summaryrefslogtreecommitdiff
path: root/odoo/models.py
diff options
context:
space:
mode:
authorRaphael Collet <rco@odoo.com>2021-01-12 09:45:11 +0000
committerRaphael Collet <rco@odoo.com>2021-01-12 14:03:27 +0000
commit25760348859f594abb796b5bc7b28f63e298cd53 (patch)
tree19b44da9232340d56edc8ef29be5bd03b600bd0b /odoo/models.py
parent9dd7e037239ff7b124d36f176fe4c66091e2cc4e (diff)
[FIX] core: invoke constraint methods once per write
Consider a constraint method with two fields: a normal field, and a field with an inverse method. When calling write() with both fields, the constraint method should be invoked once. closes odoo/odoo#64411 X-original-commit: 3b39d7efa94484b3bbf04fce756394a7e424f625 Signed-off-by: Raphael Collet (rco) <rco@openerp.com> Co-authored-by: Thibault Delavallée <tde@odoo.com>
Diffstat (limited to 'odoo/models.py')
-rw-r--r--odoo/models.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/odoo/models.py b/odoo/models.py
index be36edcdc79..d9adffc1bbe 100644
--- a/odoo/models.py
+++ b/odoo/models.py
@@ -1244,10 +1244,15 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
yield dbid, xid, converted, dict(extras, record=stream.index)
- def _validate_fields(self, field_names):
+ def _validate_fields(self, field_names, excluded_names=()):
+ """ Invoke the constraint methods for which at least one field name is
+ in ``field_names`` and none is in ``excluded_names``.
+ """
field_names = set(field_names)
+ excluded_names = set(excluded_names)
for check in self._constraint_methods:
- if not field_names.isdisjoint(check._constrains):
+ if (not field_names.isdisjoint(check._constrains)
+ and excluded_names.isdisjoint(check._constrains)):
check(self)
@api.model
@@ -3680,7 +3685,7 @@ Fields:
# validate non-inversed fields first
inverse_fields = [f.name for fs in determine_inverses.values() for f in fs]
- real_recs._validate_fields(set(vals) - set(inverse_fields))
+ real_recs._validate_fields(vals, inverse_fields)
for fields in determine_inverses.values():
# inverse records that are not being computed
@@ -3895,7 +3900,7 @@ Fields:
# check Python constraints for non-stored inversed fields
for data in data_list:
- data['record']._validate_fields(set(data['inversed']) - set(data['stored']))
+ data['record']._validate_fields(data['inversed'], data['stored'])
if self._check_company_auto:
records._check_company()