Skip to content

Commit

Permalink
[IMP] base_tier_validation: Add method to allow remove reviews.
Browse files Browse the repository at this point in the history
A method for deciding whether or not to remove related reviews is added.

TT43351
  • Loading branch information
victoralmau committed Sep 1, 2023
1 parent f496279 commit 5a83837
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion base_tier_validation/models/tier_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,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._cancel_state]):
if rec._allow_to_remove_reviews(vals):
self.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

Check warning on line 286 in base_tier_validation/models/tier_validation.py

View check run for this annotation

Codecov / codecov/patch

base_tier_validation/models/tier_validation.py#L286

Added line #L286 was not covered by tests
# 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

Check warning on line 289 in base_tier_validation/models/tier_validation.py

View check run for this annotation

Codecov / codecov/patch

base_tier_validation/models/tier_validation.py#L289

Added line #L289 was not covered by tests
return False

def _check_state_from_condition(self):
return self.env.context.get("skip_check_state_condition") or (
self._state_field in self._fields
Expand Down

0 comments on commit 5a83837

Please sign in to comment.