diff --git a/base_tier_validation/models/tier_validation.py b/base_tier_validation/models/tier_validation.py index d00e1df6b2..0caeb8c0d7 100644 --- a/base_tier_validation/models/tier_validation.py +++ b/base_tier_validation/models/tier_validation.py @@ -12,7 +12,7 @@ from odoo.osv.expression import OR from odoo.tools.misc import frozendict -BASE_EXCEPTION_FIELDS = ["message_follower_ids", "access_token"] +BASE_EXCEPTION_FIELDS = ["message_follower_ids", "access_token", "need_validation"] class TierValidation(models.AbstractModel): @@ -70,6 +70,9 @@ class TierValidation(models.AbstractModel): ) has_comment = fields.Boolean(compute="_compute_has_comment") next_review = fields.Char(compute="_compute_next_review") + is_reevaluation_required = fields.Boolean( + compute="_compute_is_reevaluation_required" + ) def _compute_has_comment(self): for rec in self: @@ -206,6 +209,27 @@ def _compute_next_review(self): )[:1] rec.next_review = review and _("Next: %s") % review.name or "" + def _compute_is_reevaluation_required(self): + for rec in self: + if isinstance(rec.id, models.NewId): + rec.is_reevaluation_required = False + continue + tiers = ( + self.env["tier.definition"] + .with_context(active_test=True) + .search( + [ + ("model", "=", self._name), + ("company_id", "in", [False] + self.env.company.ids), + ] + ) + ) + rec.is_reevaluation_required = False + valid_tiers = tiers.filtered(lambda x: rec.evaluate_tier(x)) + if valid_tiers and rec.review_ids.definition_id: + if len(valid_tiers) != len(rec.review_ids.definition_id): + rec.is_reevaluation_required = True + @api.model def _calc_reviews_validated(self, reviews): """Override for different validation policy.""" @@ -677,6 +701,13 @@ def restart_validation(self): getattr(self, subscribe)(partner_ids=partners_to_notify_ids) rec._notify_restarted_review() + def reevaluate_reviews(self): + reviews = self.env["tier.review"] + for rec in self: + rec._compute_need_validation() + reviews += rec.request_validation() + return reviews + @api.model def _update_counter(self, review_counter): self.review_ids._compute_can_review() diff --git a/base_tier_validation/templates/tier_validation_templates.xml b/base_tier_validation/templates/tier_validation_templates.xml index 9629b2de62..e5f2110f05 100644 --- a/base_tier_validation/templates/tier_validation_templates.xml +++ b/base_tier_validation/templates/tier_validation_templates.xml @@ -18,11 +18,18 @@ ('#{state_field}', '#{state_operator}', #{state_value})]}" type="object" /> +