From 386c5e1055a42d6e5cd7f688207fb34ac332a814 Mon Sep 17 00:00:00 2001 From: hparfr Date: Tue, 8 Jan 2019 15:45:21 +0100 Subject: [PATCH] base_exception allow to filter rules in inherited modules --- base_exception/__manifest__.py | 2 +- base_exception/models/base_exception.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/base_exception/__manifest__.py b/base_exception/__manifest__.py index ad5b430c6..c92a6c176 100644 --- a/base_exception/__manifest__.py +++ b/base_exception/__manifest__.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). {'name': 'Exception Rule', - 'version': '10.0.2.0.0', + 'version': '10.0.2.0.1', 'category': 'Generic Modules', 'summary': """This module provide an abstract model to manage customizable exceptions to be applied on different models (sale order, invoice, ...)""", diff --git a/base_exception/models/base_exception.py b/base_exception/models/base_exception.py index 10afb15e1..57c32f19b 100644 --- a/base_exception/models/base_exception.py +++ b/base_exception/models/base_exception.py @@ -187,6 +187,15 @@ class BaseException(models.AbstractModel): if hasattr(exception_obj, field.name) ] or [None])[0] + def _rule_domain(self): + """Filter exception.rules. + + By default, only the rules with the correct rule group + will be used. + """ + # TODO fix self[0] : it may not be the same on all ids in self + return [('rule_group', '=', self[0].rule_group)] + @api.multi def detect_exceptions(self): """List all exception_ids applied on self @@ -196,8 +205,7 @@ class BaseException(models.AbstractModel): return [] exception_obj = self.env['exception.rule'] all_exceptions = exception_obj.sudo().search( - [('rule_group', '=', self[0].rule_group)]) - # TODO fix self[0] : it may not be the same on all ids in self + self._rule_domain()) model_exceptions = all_exceptions.filtered( lambda ex: ex.model == self._name) sub_exceptions = all_exceptions.filtered(