Skip to content

Commit

Permalink
Merge cf3234d into 639bb47
Browse files Browse the repository at this point in the history
  • Loading branch information
guewen committed Aug 14, 2019
2 parents 639bb47 + cf3234d commit eca543c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions base_exception/models/base_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,28 @@ def detect_exceptions(self):
rules = self.env['exception.rule'].sudo().search(
self._rule_domain())
all_exception_ids = []
rules_to_remove = {}
rules_to_add = {}
for rule in rules:
records_with_exception = self._detect_exceptions(rule)
reverse_field = self._reverse_field()
main_records = self._get_main_records()
commons = main_records & rule[reverse_field]
to_remove = commons - records_with_exception
to_add = records_with_exception - commons
to_remove_list = [(3, x.id, _) for x in to_remove]
to_add_list = [(4, x.id, _) for x in to_add]
rule.write({reverse_field: to_remove_list + to_add_list})
# 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 records_with_exception:
all_exception_ids.append(rule.id)
for rule_id, records in rules_to_remove.iteritems():
records.write({'exception_ids': [(3, rule_id,)]})
for rule_id, records in rules_to_add.iteritems():
records.write(({'exception_ids': [(4, rule_id,)]}))
return all_exception_ids

@api.model
Expand Down

0 comments on commit eca543c

Please sign in to comment.