From ad39e0668505c6be14cf16e236305f67cd1d066e Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Wed, 12 Jun 2019 15:03:05 +0200 Subject: [PATCH] Fix union between recordset and parent recordset in base_exception --- base_exception/__manifest__.py | 2 +- base_exception/models/base_exception.py | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/base_exception/__manifest__.py b/base_exception/__manifest__.py index 4e93835c7..579801eef 100644 --- a/base_exception/__manifest__.py +++ b/base_exception/__manifest__.py @@ -4,7 +4,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { 'name': 'Exception Rule', - 'version': '12.0.2.0.2', + 'version': '12.0.2.0.3', 'category': 'Generic Modules', 'summary': """ This module provide an abstract model to manage customizable diff --git a/base_exception/models/base_exception.py b/base_exception/models/base_exception.py index 79224d126..26c4b57c4 100644 --- a/base_exception/models/base_exception.py +++ b/base_exception/models/base_exception.py @@ -61,6 +61,16 @@ class BaseExceptionMethod(models.AbstractModel): _name = 'base.exception.method' _description = 'Exception Rule Methods' + @api.multi + def _get_main_records(self): + """ + Used in case we check exceptions on a record but write these + exceptions on a parent record. Typical example is with + sale.order.line. We check exceptions on some sale order lines but + write these exceptions on the sale order, so they are visible. + """ + return self + @api.multi def _reverse_field(self): raise NotImplementedError() @@ -85,7 +95,8 @@ class BaseExceptionMethod(models.AbstractModel): records_with_exception = self._detect_exceptions(rule) reverse_field = self._reverse_field() if self: - commons = self & rule[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]