Skip to content

Customer company name uniqueness issue for B2C application #1040

Closed

Description

@amishHammer

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.

Activity

  1. eeintech commented on Oct 12, 2020

    @eeintech
    Contributor

    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 ?

  2. amishHammer commented on Oct 12, 2020

    @amishHammer
    Author

    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.

  3. eeintech commented on Oct 12, 2020

    @eeintech
    Contributor

    @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.

  4. amishHammer commented on Oct 12, 2020

    @amishHammer
    Author

    @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.

  5. eeintech commented on Oct 12, 2020

    @eeintech
    Contributor

    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).

  6. amishHammer commented on Oct 12, 2020

    @amishHammer
    Author

    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.

  7. eeintech commented on Oct 12, 2020

    @eeintech
    Contributor

    @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).

  8. eeintech commented on Oct 13, 2020

    @eeintech
    Contributor

    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.

  9. SchrodingersGat commented on Oct 18, 2020

    @SchrodingersGat
    Member

    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"?

  10. eeintech commented on Oct 19, 2020

    @eeintech
    Contributor

    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.

  11. SchrodingersGat commented on Oct 19, 2020

    @SchrodingersGat
    Member

    Yeah, that makes sense then.

  12. lookme2 commented on Oct 20, 2020

    @lookme2

    Would it make sense to to have a way to hold multiple contact info per company?

  13. eeintech commented on Oct 20, 2020

    @eeintech
    Contributor

    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.

  14. lookme2 commented on Oct 20, 2020

    @lookme2

    I would think full contact info.

  15. amishHammer commented on Oct 20, 2020

    @amishHammer
    Author

    @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.

  16. eeintech commented on Oct 20, 2020

    @eeintech
    Contributor

    @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.

    @amishHammer That is covered by #1043

  17. lookme2 commented on Oct 20, 2020

    @lookme2

    @eeintech wish I could help out with some of that. I know some python but not enough to really contribute. Sorry.

  18. eeintech commented on Oct 20, 2020

    @eeintech
    Contributor

    @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 😄

  19. amishHammer commented on Oct 22, 2020

    @amishHammer
    Author

    What's the best way to pull that PR into my WC to test it?

  20. eeintech commented on Oct 22, 2020

    @eeintech
    Contributor

    @amishHammer I would do this (assuming you have git installed):

    $ git remote add eeintech https://github.com/eeintech/InvenTree.git
    $ git fetch eeintech
    $ git checkout -b unique_email_company
    $ git pull eeintech unique_email_company
    

    and then run the server.

  21. SchrodingersGat commented on Oct 23, 2020

    @SchrodingersGat
    Member

    @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!

  22. eeintech commented on Oct 23, 2020

    @eeintech
    Contributor

    And as it was just merged into master, you only need to follow those instructions: https://inventree.readthedocs.io/en/latest/start/update/

  23. amishHammer commented on Oct 27, 2020

    @amishHammer
    Author

    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.

  24. eeintech commented on Oct 27, 2020

    @eeintech
    Contributor

    Last issue with customer syncing is an encoding issue

    What do you mean?

  25. SchrodingersGat commented on Oct 28, 2020

    @SchrodingersGat
    Member

    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.

  26. amishHammer commented on Oct 28, 2020

    @amishHammer
    Author

    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).

    WIP is here: https://github.com/amishHammer/InvenTree/tree/plugin_system

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions