From eae8e7cdf2656282460dcfdba22d8d1180a89255 Mon Sep 17 00:00:00 2001 From: hparfr Date: Wed, 10 Jul 2019 10:28:35 +0200 Subject: [PATCH 1/3] Remove the feature when self is empty. This recently added feature is counter intuitive, error prone and is already causing bugs in sale_workflow. --- base_exception/models/base_exception.py | 27 ++++++++----------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/base_exception/models/base_exception.py b/base_exception/models/base_exception.py index 549af1e45..42de521a8 100644 --- a/base_exception/models/base_exception.py +++ b/base_exception/models/base_exception.py @@ -99,7 +99,6 @@ class BaseExceptionMethod(models.AbstractModel): def detect_exceptions(self): """List all exception_ids applied on self Exception ids are also written on records - If self is empty, check exceptions on all active records. """ rules = self.env['exception.rule'].sudo().search( self._rule_domain()) @@ -107,18 +106,13 @@ class BaseExceptionMethod(models.AbstractModel): for rule in rules: records_with_exception = self._detect_exceptions(rule) reverse_field = self._reverse_field() - if self: - 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}) - else: - rule.write({ - reverse_field: [(6, 0, records_with_exception.ids)] - }) + 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}) if records_with_exception: all_exception_ids.append(rule.id) return all_exception_ids @@ -161,16 +155,12 @@ class BaseExceptionMethod(models.AbstractModel): @api.multi def _get_base_domain(self): - domain = [('ignore_exception', '=', False)] - if self: - domain = osv.expression.AND([domain, [('id', 'in', self.ids)]]) - return domain + return [('ignore_exception', '=', False), ('id', 'in', self.ids)] @api.multi def _detect_exceptions_by_py_code(self, rule): """ Find exceptions found on self. - If self is empty, check on all records. """ domain = self._get_base_domain() records = self.search(domain) @@ -184,7 +174,6 @@ class BaseExceptionMethod(models.AbstractModel): def _detect_exceptions_by_domain(self, rule): """ Find exceptions found on self. - If self is empty, check on all records. """ base_domain = self._get_base_domain() rule_domain = rule._get_domain() From 0f57853884b4da8d8066becdf0cbdcdbf9e0eb05 Mon Sep 17 00:00:00 2001 From: oca-travis Date: Wed, 7 Aug 2019 13:06:52 +0000 Subject: [PATCH 2/3] [UPD] Update base_exception.pot --- base_exception/i18n/base_exception.pot | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base_exception/i18n/base_exception.pot b/base_exception/i18n/base_exception.pot index f0035517c..762c0561b 100644 --- a/base_exception/i18n/base_exception.pot +++ b/base_exception/i18n/base_exception.pot @@ -75,7 +75,7 @@ msgid "Domain" msgstr "" #. module: base_exception -#: code:addons/base_exception/models/base_exception.py:151 +#: code:addons/base_exception/models/base_exception.py:145 #, python-format msgid "Error when evaluating the exception.rule rule:\n" " %s \n" From c232cdcd52b7fc5922c0c6aa22ee7f2f20da284a Mon Sep 17 00:00:00 2001 From: OCA-git-bot Date: Wed, 7 Aug 2019 13:47:10 +0000 Subject: [PATCH 3/3] base_exception 10.0.4.0.0 --- base_exception/__manifest__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base_exception/__manifest__.py b/base_exception/__manifest__.py index 346e2e27f..f620cc7b7 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.3.0.2', + 'version': '10.0.4.0.0', 'category': 'Generic Modules', 'summary': """This module provide an abstract model to manage customizable exceptions to be applied on different models (sale order, invoice, ...)""",