Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] partner_company_type: make unique constraint dependent on country #1917

Open
wants to merge 1 commit into
base: 12.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions partner_company_type/models/res_partner_company_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,15 @@ class ResPartnerCompanyType(models.Model):
"Leave it blank if you want it to appear on any partner.",
)

_sql_constraints = [('name_uniq', 'unique (name)',
"Partner Company Type already exists!")]
_sql_constraints = [
(
"name_country_uniq",
"unique (name, country_id)",
"Partner Company Type already exists for this country!"
),
(
Copy link
Contributor

@rousseldenis rousseldenis Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@len-foss And why not using the EXCLUDE with all the conditions (and removing unique constraint) ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally prefer 2 simple and stupid statements to having only 1 but complicated. Unless there is a simple form to combine these?

"unique_name_null_country_id",
"EXCLUDE (name WITH =) WHERE (country_id IS NULL)",
"Shared Partner Company Type already exists!"
),
]
Loading