Skip to content

[Company] Allow duplicate names - Unique name/email pair - #1043

Merged
SchrodingersGat merged 5 commits into
inventree:masterfrom
eeintech:unique_email_company
Oct 23, 2020
Merged

SchrodingersGat merged 5 commits into
inventree:masterfrom
eeintech:unique_email_company

Conversation

@eeintech

@eeintech eeintech commented Oct 12, 2020 •

Copy link
Copy Markdown
Contributor

Fixes #1040.

  • Company name field unique constraint was removed
  • Company email field null constraint was set to True (convert empty string to Null value)
  • Company email field unique constraint was set to True (check for uniqueness)
  • Added custom method to migration file to convert email field empty string value to Null value
  • Added UniqueConstraint on name/email pair (instead of unique constraint on email only)

image

@SchrodingersGat

Copy link
Copy Markdown
Member

Now that the "name" field does not have to be unique, but the email does, there still could be a situation where multiple company objects exist with the same name and a blank email.

So, I would suggest that we add a requirement that if the email is empty, then the name must be unique.

It may be as simple as adding:

class Meta:
    unique_together = [
        ('name', 'email'),
    ]

(but this requires testing)

@eeintech

Copy link
Copy Markdown
Contributor Author

Thanks @SchrodingersGat I'll take another shot with this in mind. Seems like the better way is to create a UniqueConstraint as unique_together could be deprecated in the future.

@eeintech eeintech changed the title [Company] Duplicate names - Unique email field [Company] Allow duplicate names - Unique name/email pair Oct 20, 2020
@eeintech
eeintech marked this pull request as ready for review October 20, 2020 12:48
@eeintech

Copy link
Copy Markdown
Contributor Author

@SchrodingersGat This PR is ready for review, I did testing with the migration on my database and validation on the modal form, everything looks good on my side.

@SchrodingersGat

Copy link
Copy Markdown
Member

@eeintech I'm pretty happy with this on my side, I don't see any issues with this as it stands. Thanks for addressing the issue 👍

@SchrodingersGat
SchrodingersGat merged commit 5e63ccc into inventree:master Oct 23, 2020
@eeintech
eeintech deleted the unique_email_company branch July 14, 2021 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Customer company name uniqueness issue for B2C application

2 participants