diff --git a/base_exception/models/base_exception.py b/base_exception/models/base_exception.py index bc24cc9aa..fee5f5674 100644 --- a/base_exception/models/base_exception.py +++ b/base_exception/models/base_exception.py @@ -101,12 +101,12 @@ class BaseExceptionMethod(models.AbstractModel): to_remove = commons - records_with_exception to_add = records_with_exception - commons # we expect to always work on the same model type - rules_to_remove.setdefault( - rule.id, main_records.browse() - ).update(to_remove) - rules_to_add.setdefault( - rule.id, main_records.browse() - ).update(to_add) + if rule.id not in rules_to_remove: + rules_to_remove[rule.id] = main_records.browse() + rules_to_remove[rule.id] |= to_remove + if rule.id not in rules_to_add: + rules_to_add[rule.id] = main_records.browse() + rules_to_add[rule.id] |= to_add if records_with_exception: all_exception_ids.append(rule.id) # Cumulate all the records to attach to the rule diff --git a/base_exception/tests/test_base_exception.py b/base_exception/tests/test_base_exception.py index 6ab115b4f..a20e2a881 100644 --- a/base_exception/tests/test_base_exception.py +++ b/base_exception/tests/test_base_exception.py @@ -68,6 +68,8 @@ class TestBaseException(common.SavepointCase): # Block because of exception during validation with self.assertRaises(ValidationError): potest1.button_confirm() + # Test that we have linked exceptions + self.assertTrue(potest1.exception_ids) # Test ignore exeception make possible for the po to validate potest1.ignore_exception = True potest1.button_confirm()