From 1a0ea4929c180096854ccb559cedc870bad76541 Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Tue, 22 Nov 2022 10:47:00 +0100 Subject: [PATCH] [FIX] product_abc_classification: Adapt write() for a multi recordset --- .../abc_classification_product_level.py | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/product_abc_classification/models/abc_classification_product_level.py b/product_abc_classification/models/abc_classification_product_level.py index 1ad9cf6c1843..c317a9d47b7f 100644 --- a/product_abc_classification/models/abc_classification_product_level.py +++ b/product_abc_classification/models/abc_classification_product_level.py @@ -146,14 +146,27 @@ def create(self, vals_list): return super().create(vals_list) def write(self, vals): + """ + We apply the manual level to the product level if + computed level is modified and only for profiles with + auto_apply_computed_value = =True + """ values = vals.copy() - if "profile_id" in values: - profile = self.env["abc.classification.profile"].browse( - values["profile_id"] + new_self = self + if "computed_level_id" in values: + profile_ids = ( + [values["profile_id"]] + if "profile_id" in values + else self.mapped("profile_id").ids ) - else: - profile = self.mapped("profile_id") - - if profile.auto_apply_computed_value and "computed_level_id" in values: - values["manual_level_id"] = values["computed_level_id"] - return super().write(values) + auto_applied_profiles_levels = self.filtered( + lambda l: l.profile_id.id in profile_ids + and l.profile_id.auto_apply_computed_value + ) + if auto_applied_profiles_levels: + values["manual_level_id"] = values["computed_level_id"] + new_self = self - auto_applied_profiles_levels + super( + AbcClassificationProductLevel, auto_applied_profiles_levels + ).write(values) + return super(AbcClassificationProductLevel, new_self).write(vals)