Skip to content

Commit

Permalink
[FIX] product_abc_classification: Adapt write() for a multi recordset
Browse files Browse the repository at this point in the history
  • Loading branch information
rousseldenis committed Nov 22, 2022
1 parent 2bc9ee1 commit 1a0ea49
Showing 1 changed file with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 1a0ea49

Please sign in to comment.