From 005918efd7302a7723c3e4753ed9de3e1edcdb6f Mon Sep 17 00:00:00 2001 From: len Date: Thu, 5 Dec 2024 20:04:57 +0100 Subject: [PATCH] [FIX] partner_company_type: make unique constraint dependent on country --- .../models/res_partner_company_type.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/partner_company_type/models/res_partner_company_type.py b/partner_company_type/models/res_partner_company_type.py index 652bb4a492d..2785562292a 100644 --- a/partner_company_type/models/res_partner_company_type.py +++ b/partner_company_type/models/res_partner_company_type.py @@ -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!" + ), + ( + "unique_name_null_country_id", + "EXCLUDE (name WITH =) WHERE (country_id IS NULL)", + "Shared Partner Company Type already exists!" + ), + ]