From 7d29f30f710cadcf477d9699708f98d23bf028ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Thu, 31 Aug 2023 13:15:33 +0200 Subject: [PATCH] [IMP] base_tier_validation: Add method to allow remove reviews. A method for deciding whether or not to remove related reviews is added. TT43351 --- .../models/tier_validation.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/base_tier_validation/models/tier_validation.py b/base_tier_validation/models/tier_validation.py index e964f28b55..e360bea354 100644 --- a/base_tier_validation/models/tier_validation.py +++ b/base_tier_validation/models/tier_validation.py @@ -247,10 +247,25 @@ def write(self, vals): and not rec._context.get("skip_validation_check") ): raise ValidationError(_("The operation is under validation.")) - if vals.get(self._state_field) in self._state_from: - self.mapped("review_ids").unlink() + if rec._allow_to_remove_reviews(vals): + rec.mapped("review_ids").unlink() return super(TierValidation, self).write(vals) + def _allow_to_remove_reviews(self, values): + """Method for deciding whether the elimination of revisions is necessary.""" + self.ensure_one() + state_to = values.get(self._state_field) + if not state_to: + return False + state_from = self[self._state_field] + # If you change to _cancel_state + if state_to in (self._cancel_state): + return True + # If it is changed to _state_from and it was not in _state_from + if state_to in self._state_from and state_from not in self._state_from: + return True + return False + def _check_state_from_condition(self): return self.env.context.get("skip_check_state_condition") or ( self._state_field in self._fields