You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Customer company name uniqueness issue for B2C application #1040
Due to the reuse of company for customers, customer 'names' must be unique. This is not a reasonable expectation for business selling direct to consumers as customers. The unique key for a company should be relaxed or changed. The only unique part for a 'customer' should be the email address.
That's a good point and I agree with you. It would take some thoughts to alter the email field without disrupting current databases (and maybe making it unique only for customers?) but I don't think it is a necessary measure, what do you think @SchrodingersGat ?
I can't see why email would not be unique for suppliers/manufacturers as well as customers. For reference QuickBooks requires all customers/vendors to have a unique email address (you can have the same email as a vendor and a customer however). Ideally the customers/suppliers are in separate tables and are separate objects with their own logic.
@amishHammer The current implementation does not enforce email as a required field for company instances (regardless if customer or supplier) so adding uniqueness requirement could break the migration process because companies with "blank" email value will clash (it definitely happens for us, suppliers/manufacturers don't have any email address set).
Not many people buy directly from manufacturers/suppliers, using email. For customers, it would make a bit more sense to enforce email address as point of contact is necessary for selling product. But again, adding a database constraint will break existing users setups.
My proposal is to remove uniqueness requirement on the company name field and leave the email requirement loose in first place. If you really need to have the email uniqueness feature, we may be able to add it as an InvenTree setting, but not as a strict built-in requirement.
@eeintech I would strongly disagree with the assessment that purchasing is not done via email. Lots of people buy from their supply chain using purchase orders, which these days are typically emailed rather than faxed. In most places a purchase order like this is considered a legally binding contract if it is accepted by the vendor. At some point it would be great to see a send purchase order function in the PO section that formats the PO as a PDF and emails it to the supplier. Back to the QuickBooks reference, this functionality is fairly core to the way purchase orders work in that and most other applications that issue purchase orders.
SQL92 states that a NULL value in a unique key can exist multiple times, NULLs are not considered as part of the uniqueness check. This may also be true in other dialects, SQLite and MySQL both act as SQL92 states. Based on this is should be fine to add a unique key to email without breaking the DB as long as the empty emails are NULL and not empty strings. This could be enforced with a 2 step migration, step one make empty strings NULL, step 2 add the unique key.
Sure, I don't disagree with you, I was not trying to make a case against or for one implementation or the other but rather differentiating the process for validating supplier vs customers, to refer to your original post. Anyhow, I agree and the InvenTree "company" model should stay generic for this use-case.
I have to double check for the NULL step migration you proposed, in my case it still threw migration errors. However, I'll leave it up-to @SchrodingersGat to decide if he want to enforce email as unique (InvenTree is not QuickBooks).
While I agree that this is not QB I'm just using it as an example of a product that has this feature. At the end of the day InvenTree is the most promising solution to my problem and I'd love to be able to get this hooked up to Opencart for inventory management.
In my limited customer base (~600) I have maybe a dozen customers with name conflicts, and this issue is the next hurdle in my implementation. I've been waiting for sales orders for a while so I can do this integration.
@amishHammer I succeeded to migrate my database and add uniqueness constraint to email field, empty value is still allowed and saved as Null. My only concern left is for "real" duplicates (not empty string) in the email field, the migration may fail in this case. I'll give it a shot soon and update the PR if needed. You're welcome to give it a try but make sure to backup your database beforehand (see #1043).
As I feared, when the database contains duplicate Company emails, adding the unique=True will make the migration fail...
As mentioned in this StackOverflow post, there is no non-intrusive way to do so as the constraint will apply to the complete table.
I think we would need to introduce this as a setting rather than a strict requirement. When the setting is enabled, the database will be scanned for duplicates and reported to the user, then enforce the email field is validated during company creation.
Hey @amishHammer I am happy to relax the uniqueness requirement here. However I do not fully understand the requirement. Can you please provide an example where you would be selling to multiple customers that have the same "name"?
I think this request is about people names (eg. customers) which can easily be the same.
Therefore, removing the uniqueness on name would clear this, and potentially adding validation on email address.
Not a bad idea I think, were you thinking multiple email addresses or full contact information? Any how it would require an extra DB table to store the multiple contacts but it's doable.
@SchrodingersGat@eeintech's explanation is correct in this example I'm trying to hook up an e-commerce platform that sells direct to the consumer to InvenTree, in this example I have lots of customers that have the same name.
As for multiple contacts per company that is also a useful feature however it does not negate the need to have multiple company objects for customers with the same name.
@lookme2 I just realized InvenTree already has a Contact model but it does seem to be put into action yet, something to add on our TODO list.
As for multiple contacts per company that is also a useful feature however it does not negate the need to have multiple company objects for customers with the same name.
@eeintech wish I could help out with some of that. I know some python but not enough to really contribute. Sorry.
Ha, no problem. I was only mentioning this as I stumbled upon the model, here is the commit for reference: feff4f0
Don't see more done in that direction yet... Would need to add views and template forms to link contacts to a company, shouldn't be too difficult, I can take a look soon 😄
@amishHammer what is the ecommerce platform you're trying to integrate with? If you're willing, and if your integration is useful for other users, it would be great to be able to work the integration into InvenTree!
Just tried this out and its working thanks! Last issue with customer syncing is an encoding issue but that's probably fairly simple. @SchrodingersGat I'm working on integrating OpenCart with InvenTree, I'd also like to eventually integrate QBO but that is a much longer road map.
I'm working on integrating OpenCart with InvenTree, I'd also like to eventually integrate QBO but that is a much longer road map.
I am very interested in hearing how you go with this.
Let me know if you need any help getting into the nuts and bolts of InvenTree. And if you get something working, and are willing to contribute it back to the main project, that would be very much appreciated.
Last issue with customer syncing is an encoding issue
What do you mean?
It's a problem with my script that pulls the customers from one DB and adds them to InvenTree. Probably a utf8 encoding issue or encoding header issue on my end.
I'm working on integrating OpenCart with InvenTree, I'd also like to eventually integrate QBO but that is a much longer road map.
I am very interested in hearing how you go with this.
Let me know if you need any help getting into the nuts and bolts of InvenTree. And if you get something working, and are willing to contribute it back to the main project, that would be very much appreciated.
I have the core started that will allow a pluggable architecture (calling them extensions to not conflict with the existing plugins system) with these external applications, it will allow for any kind of integration directly into InvenTree with no core code modification. (Unless new hook/data points are required to be added to the framework).
Activity
eeintech commentedon Oct 12, 2020
That's a good point and I agree with you. It would take some thoughts to alter the email field without disrupting current databases (and maybe making it unique only for customers?) but I don't think it is a necessary measure, what do you think @SchrodingersGat ?
amishHammer commentedon Oct 12, 2020
I can't see why email would not be unique for suppliers/manufacturers as well as customers. For reference QuickBooks requires all customers/vendors to have a unique email address (you can have the same email as a vendor and a customer however). Ideally the customers/suppliers are in separate tables and are separate objects with their own logic.
eeintech commentedon Oct 12, 2020
@amishHammer The current implementation does not enforce email as a required field for company instances (regardless if customer or supplier) so adding uniqueness requirement could break the migration process because companies with "blank" email value will clash (it definitely happens for us, suppliers/manufacturers don't have any email address set).
Not many people buy directly from manufacturers/suppliers, using email. For customers, it would make a bit more sense to enforce email address as point of contact is necessary for selling product. But again, adding a database constraint will break existing users setups.
My proposal is to remove uniqueness requirement on the company
namefield and leave the email requirement loose in first place. If you really need to have the email uniqueness feature, we may be able to add it as an InvenTree setting, but not as a strict built-in requirement.amishHammer commentedon Oct 12, 2020
@eeintech I would strongly disagree with the assessment that purchasing is not done via email. Lots of people buy from their supply chain using purchase orders, which these days are typically emailed rather than faxed. In most places a purchase order like this is considered a legally binding contract if it is accepted by the vendor. At some point it would be great to see a send purchase order function in the PO section that formats the PO as a PDF and emails it to the supplier. Back to the QuickBooks reference, this functionality is fairly core to the way purchase orders work in that and most other applications that issue purchase orders.
SQL92 states that a NULL value in a unique key can exist multiple times, NULLs are not considered as part of the uniqueness check. This may also be true in other dialects, SQLite and MySQL both act as SQL92 states. Based on this is should be fine to add a unique key to email without breaking the DB as long as the empty emails are NULL and not empty strings. This could be enforced with a 2 step migration, step one make empty strings NULL, step 2 add the unique key.
eeintech commentedon Oct 12, 2020
Sure, I don't disagree with you, I was not trying to make a case against or for one implementation or the other but rather differentiating the process for validating supplier vs customers, to refer to your original post. Anyhow, I agree and the InvenTree "company" model should stay generic for this use-case.
I have to double check for the NULL step migration you proposed, in my case it still threw migration errors. However, I'll leave it up-to @SchrodingersGat to decide if he want to enforce email as unique (InvenTree is not QuickBooks).
amishHammer commentedon Oct 12, 2020
While I agree that this is not QB I'm just using it as an example of a product that has this feature. At the end of the day InvenTree is the most promising solution to my problem and I'd love to be able to get this hooked up to Opencart for inventory management.
In my limited customer base (~600) I have maybe a dozen customers with name conflicts, and this issue is the next hurdle in my implementation. I've been waiting for sales orders for a while so I can do this integration.
eeintech commentedon Oct 12, 2020
@amishHammer I succeeded to migrate my database and add uniqueness constraint to
emailfield, empty value is still allowed and saved asNull. My only concern left is for "real" duplicates (not empty string) in theemailfield, the migration may fail in this case. I'll give it a shot soon and update the PR if needed. You're welcome to give it a try but make sure to backup your database beforehand (see #1043).eeintech commentedon Oct 13, 2020
As I feared, when the database contains duplicate Company emails, adding the
unique=Truewill make the migration fail...As mentioned in this StackOverflow post, there is no non-intrusive way to do so as the constraint will apply to the complete table.
I think we would need to introduce this as a setting rather than a strict requirement. When the setting is enabled, the database will be scanned for duplicates and reported to the user, then enforce the email field is validated during company creation.
SchrodingersGat commentedon Oct 18, 2020
Hey @amishHammer I am happy to relax the uniqueness requirement here. However I do not fully understand the requirement. Can you please provide an example where you would be selling to multiple customers that have the same "name"?
eeintech commentedon Oct 19, 2020
I think this request is about people names (eg. customers) which can easily be the same.
Therefore, removing the uniqueness on name would clear this, and potentially adding validation on email address.
Example:
@amishHammer Correct me if I'm wrong.
SchrodingersGat commentedon Oct 19, 2020
Yeah, that makes sense then.
lookme2 commentedon Oct 20, 2020
Would it make sense to to have a way to hold multiple contact info per company?
eeintech commentedon Oct 20, 2020
Not a bad idea I think, were you thinking multiple email addresses or full contact information? Any how it would require an extra DB table to store the multiple contacts but it's doable.
lookme2 commentedon Oct 20, 2020
I would think full contact info.
amishHammer commentedon Oct 20, 2020
@SchrodingersGat @eeintech's explanation is correct in this example I'm trying to hook up an e-commerce platform that sells direct to the consumer to InvenTree, in this example I have lots of customers that have the same name.
As for multiple contacts per company that is also a useful feature however it does not negate the need to have multiple company objects for customers with the same name.
eeintech commentedon Oct 20, 2020
@lookme2 I just realized InvenTree already has a
Contactmodel but it does seem to be put into action yet, something to add on our TODO list.@amishHammer That is covered by #1043
lookme2 commentedon Oct 20, 2020
@eeintech wish I could help out with some of that. I know some python but not enough to really contribute. Sorry.
eeintech commentedon Oct 20, 2020
Ha, no problem. I was only mentioning this as I stumbled upon the model, here is the commit for reference: feff4f0
Don't see more done in that direction yet... Would need to add views and template forms to link contacts to a company, shouldn't be too difficult, I can take a look soon 😄
amishHammer commentedon Oct 22, 2020
What's the best way to pull that PR into my WC to test it?
eeintech commentedon Oct 22, 2020
@amishHammer I would do this (assuming you have
gitinstalled):and then run the server.
SchrodingersGat commentedon Oct 23, 2020
@amishHammer what is the ecommerce platform you're trying to integrate with? If you're willing, and if your integration is useful for other users, it would be great to be able to work the integration into InvenTree!
eeintech commentedon Oct 23, 2020
And as it was just merged into master, you only need to follow those instructions: https://inventree.readthedocs.io/en/latest/start/update/
amishHammer commentedon Oct 27, 2020
Just tried this out and its working thanks! Last issue with customer syncing is an encoding issue but that's probably fairly simple. @SchrodingersGat I'm working on integrating OpenCart with InvenTree, I'd also like to eventually integrate QBO but that is a much longer road map.
eeintech commentedon Oct 27, 2020
What do you mean?
SchrodingersGat commentedon Oct 28, 2020
I am very interested in hearing how you go with this.
Let me know if you need any help getting into the nuts and bolts of InvenTree. And if you get something working, and are willing to contribute it back to the main project, that would be very much appreciated.
amishHammer commentedon Oct 28, 2020
It's a problem with my script that pulls the customers from one DB and adds them to InvenTree. Probably a utf8 encoding issue or encoding header issue on my end.
I have the core started that will allow a pluggable architecture (calling them extensions to not conflict with the existing plugins system) with these external applications, it will allow for any kind of integration directly into InvenTree with no core code modification. (Unless new hook/data points are required to be added to the framework).
WIP is here: https://github.com/amishHammer/InvenTree/tree/plugin_system