Skip to content

Commit

Permalink
[IMP] base_tier_validation: add button for reevaluation and added test
Browse files Browse the repository at this point in the history
  • Loading branch information
JasminSForgeFlow committed Sep 3, 2024
1 parent a64e791 commit bfa3c38
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 1 deletion.
33 changes: 32 additions & 1 deletion base_tier_validation/models/tier_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

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

View check run for this annotation

Codecov / codecov/patch

base_tier_validation/models/tier_validation.py#L215-L216

Added lines #L215 - L216 were not covered by tests
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

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

View check run for this annotation

Codecov / codecov/patch

base_tier_validation/models/tier_validation.py#L231

Added line #L231 was not covered by tests

@api.model
def _calc_reviews_validated(self, reviews):
"""Override for different validation policy."""
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 7 additions & 0 deletions base_tier_validation/templates/tier_validation_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@
('#{state_field}', '#{state_operator}', #{state_value})]}"
type="object"
/>
<button
name="reevaluate_reviews"
string="Reevaluate Reviews"
t-attf-attrs="{'invisible': ['|',('is_reevaluation_required', '!=', True),('#{state_field}', '#{state_operator}', #{state_value})]}"
type="object"
/>
</div>
</template>
<template id="tier_validation_label">
<div>
<field name="need_validation" invisible="1" />
<field name="is_reevaluation_required" invisible="1" />
<field name="validated" invisible="1" />
<field name="rejected" invisible="1" />
<div
Expand Down
82 changes: 82 additions & 0 deletions base_tier_validation/tests/test_tier_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,88 @@ def test_25_change_field_exception_validation(self):
)
self.assertEqual(self.test_record.test_validation_field, 4)

def test_27_reevaluate_validation(self):
# Create new test record
test_record = self.test_model.create(
{"test_field": 100, "test_validation_field": 15}
)
# Create tier definitions
self.tier_def_obj.create(
{
"model_id": self.tester_model.id,
"review_type": "individual",
"reviewer_id": self.test_user_1.id,
"definition_domain": "[('test_field', '>', 100)]",
}
)
# Request validation
reviews = test_record.with_user(self.test_user_2.id).request_validation()
# Check need validation
self.assertTrue(test_record.need_validation)
self.assertEqual(len(reviews), 1)

# Now record is not validated yet and new definition create,
# and then we reevaluate object then it will add new definition validation
# also in current object
self.tier_def_obj.create(
{
"model_id": self.tester_model.id,
"review_type": "individual",
"reviewer_id": self.test_user_1.id,
"definition_domain": "[('test_validation_field', '>', 10)]",
}
)

# Reevaluate Validation
reviews = test_record.with_user(self.test_user_2.id).reevaluate_reviews()
# Check need validation
self.assertTrue(test_record.need_validation)
self.assertEqual(len(reviews), 2)

def test_28_reevaluate_validation(self):
# Create new test record
test_record = self.test_model.create(
{"test_field": 100, "test_validation_field": 15}
)
# Create tier definitions
# 1st defination to check test_field
self.tier_def_obj.create(
{
"model_id": self.tester_model.id,
"review_type": "individual",
"reviewer_id": self.test_user_1.id,
"definition_domain": "[('test_field', '>', 100)]",
}
)
# 2nd definition will be trigger only when there is
# new message with body "This record need extra validation"
test_message = "This record need extra validation"
self.tier_def_obj.create(
{
"model_id": self.tester_model.id,
"review_type": "individual",
"reviewer_id": self.test_user_1.id,
"definition_domain": "[('message_ids.body', 'ilike', '%s')]"
% (test_message),
}
)

# Request validation
reviews = test_record.with_user(self.test_user_2.id).request_validation()
# Check need validation
self.assertTrue(test_record.need_validation)
self.assertEqual(len(reviews), 1)

# now post new message "This record need extra validation",
# it will need to reevaluate record and will add new tier validation
test_record.with_user(self.test_user_2.id).message_post(body=test_message)

# Reevaluate Validation
reviews = test_record.with_user(self.test_user_2.id).reevaluate_reviews()
# Check need validation
self.assertTrue(test_record.need_validation)
self.assertEqual(len(reviews), 2)


@tagged("at_install")
class TierTierValidationView(CommonTierValidation):
Expand Down

0 comments on commit bfa3c38

Please sign in to comment.