11# 2025 Camptocamp SA (https://www.camptocamp.com).
2- # License LGPL -3.0 or later (https://www.gnu.org/licenses/lgpl .html).
2+ # License AGPL -3.0 or later (https://www.gnu.org/licenses/agpl .html).
33from odoo import _ , api , models
44from odoo .exceptions import ValidationError
55
@@ -11,11 +11,13 @@ class ResPartner(models.Model):
1111 def _compute_product_pricelist (self ):
1212 return super ()._compute_product_pricelist ()
1313
14+ @api .constrains ("operating_unit_ids" , "property_product_pricelist" )
1415 def _check_pricelist_operating_unit (self ):
1516 for partner in self :
1617 pricelist = partner .property_product_pricelist
1718 if (
1819 pricelist
20+ and pricelist .operating_unit_id
1921 and pricelist .operating_unit_id not in partner .operating_unit_ids
2022 ):
2123 raise ValidationError (
@@ -28,18 +30,7 @@ def _check_pricelist_operating_unit(self):
2830 )
2931 )
3032
31- def write (self , vals ):
32- res = super ().write (vals )
33- # We check that both `operating_unit_ids` and `property_product_pricelist`
34- # are in `vals` to avoid wrongly raised ValidationError
35- if "operating_unit_ids" in vals and "property_product_pricelist" in vals :
36- self ._check_pricelist_operating_unit ()
37- return res
38-
39- @api .model_create_multi
40- def create (self , vals_list ):
41- partners = super ().create (vals_list )
42- for partner , vals in zip (partners , vals_list , strict = True ):
43- if "operating_unit_ids" in vals and "property_product_pricelist" in vals :
44- partner ._check_pricelist_operating_unit ()
45- return partners
33+ def _commercial_fields (self ):
34+ # list of fields that are managed by the commercial entity
35+ # to which a partner belongs.
36+ return super ()._commercial_fields () + ["operating_unit_ids" ]
0 commit comments