diff --git a/base_tier_validation/models/tier_definition.py b/base_tier_validation/models/tier_definition.py
index 7ef4404058..48738442a2 100644
--- a/base_tier_validation/models/tier_definition.py
+++ b/base_tier_validation/models/tier_definition.py
@@ -68,6 +68,12 @@ def _get_tier_validation_model_names(self):
"this definition is triggered.",
)
has_comment = fields.Boolean(string="Comment", default=False)
+ comment_required_validate = fields.Boolean(
+ string="Comment required for validation", default=True
+ )
+ comment_required_reject = fields.Boolean(
+ string="Comment required for rejection", default=True
+ )
approve_sequence = fields.Boolean(
string="Approve by sequence",
default=False,
diff --git a/base_tier_validation/models/tier_review.py b/base_tier_validation/models/tier_review.py
index fa56d86bb6..e89c30ef8e 100644
--- a/base_tier_validation/models/tier_review.py
+++ b/base_tier_validation/models/tier_review.py
@@ -50,6 +50,12 @@ class TierReview(models.Model):
string="Validation Formated Date", compute="_compute_reviewed_formated_date"
)
has_comment = fields.Boolean(related="definition_id.has_comment", readonly=True)
+ comment_required_validate = fields.Boolean(
+ related="definition_id.comment_required_validate", readonly=True
+ )
+ comment_required_reject = fields.Boolean(
+ related="definition_id.comment_required_reject", readonly=True
+ )
comment = fields.Char(string="Comments")
can_review = fields.Boolean(
compute="_compute_can_review",
diff --git a/base_tier_validation/models/tier_validation.py b/base_tier_validation/models/tier_validation.py
index ffcb6db6bb..cfd4a7d7e9 100644
--- a/base_tier_validation/models/tier_validation.py
+++ b/base_tier_validation/models/tier_validation.py
@@ -64,14 +64,20 @@ class TierValidation(models.AbstractModel):
compute="_compute_can_review", search="_search_can_review"
)
has_comment = fields.Boolean(compute="_compute_has_comment")
+ comment_required_validate = fields.Boolean(compute="_compute_has_comment")
+ comment_required_reject = fields.Boolean(compute="_compute_has_comment")
next_review = fields.Char(compute="_compute_next_review")
def _compute_has_comment(self):
for rec in self:
- has_comment = rec.review_ids.filtered(
+ reviews = rec.review_ids.filtered(
lambda r: r.status == "pending" and (self.env.user in r.reviewer_ids)
- ).mapped("has_comment")
- rec.has_comment = True in has_comment
+ )
+ rec.has_comment = any(reviews.mapped("has_comment"))
+ rec.comment_required_validate = any(
+ reviews.mapped("comment_required_validate")
+ )
+ rec.comment_required_reject = any(reviews.mapped("comment_required_reject"))
def _get_sequences_to_approve(self, user):
all_reviews = self.review_ids.filtered(lambda r: r.status == "pending")
@@ -383,7 +389,7 @@ def validate_tier(self):
reviews = self.review_ids.filtered(
lambda l: l.sequence in sequences or l.approve_sequence_bypass
)
- if self.has_comment:
+ if self.has_comment and self.comment_required_validate:
user_reviews = reviews.filtered(
lambda r: r.status == "pending" and (self.env.user in r.reviewer_ids)
)
@@ -395,7 +401,7 @@ def reject_tier(self):
self.ensure_one()
sequences = self._get_sequences_to_approve(self.env.user)
reviews = self.review_ids.filtered(lambda l: l.sequence in sequences)
- if self.has_comment:
+ if self.has_comment and self.comment_required_reject:
return self._add_comment("reject", reviews)
self._rejected_tier(reviews)
self._update_counter({"review_deleted": True})
diff --git a/base_tier_validation/tests/test_tier_validation.py b/base_tier_validation/tests/test_tier_validation.py
index 4cbd96132a..b79852cec9 100644
--- a/base_tier_validation/tests/test_tier_validation.py
+++ b/base_tier_validation/tests/test_tier_validation.py
@@ -160,6 +160,7 @@ def test_11_add_comment(self):
wizard = Form(self.env["comment.wizard"].with_context(**ctx))
wizard.comment = "Test Comment"
wiz = wizard.save()
+ self.assertTrue(wiz.comment_required)
wiz.add_comment()
self.assertTrue(test_record.review_ids.mapped("comment"))
# Check notify
@@ -183,6 +184,7 @@ def test_11_add_comment_rejection(self):
"reviewer_id": self.test_user_1.id,
"definition_domain": "[('test_field', '>', 1.0)]",
"has_comment": True,
+ "comment_required_reject": False,
}
)
# Request validation
@@ -195,6 +197,7 @@ def test_11_add_comment_rejection(self):
wizard = Form(self.env["comment.wizard"].with_context(**ctx))
wizard.comment = "Test Comment"
wiz = wizard.save()
+ self.assertFalse(wiz.comment_required)
wiz.add_comment()
self.assertTrue(test_record.review_ids.mapped("comment"))
# Check notify
diff --git a/base_tier_validation/views/tier_definition_view.xml b/base_tier_validation/views/tier_definition_view.xml
index 64e0227aa8..8598d7bbeb 100644
--- a/base_tier_validation/views/tier_definition_view.xml
+++ b/base_tier_validation/views/tier_definition_view.xml
@@ -100,6 +100,14 @@
+
+
diff --git a/base_tier_validation/wizard/comment_wizard.py b/base_tier_validation/wizard/comment_wizard.py
index 5c5a6c933d..209b6f55f6 100644
--- a/base_tier_validation/wizard/comment_wizard.py
+++ b/base_tier_validation/wizard/comment_wizard.py
@@ -12,12 +12,22 @@ class CommentWizard(models.TransientModel):
res_model = fields.Char()
res_id = fields.Integer()
review_ids = fields.Many2many(comodel_name="tier.review")
- comment = fields.Char(required=True)
+ comment = fields.Char()
+ comment_required = fields.Boolean(compute="_compute_comment_required")
+
+ def _compute_comment_required(self):
+ for this in self:
+ this.comment_required = all(
+ this.review_ids.mapped(
+ "definition_id.comment_required_%s" % this.validate_reject
+ )
+ )
def add_comment(self):
self.ensure_one()
rec = self.env[self.res_model].browse(self.res_id)
- self.review_ids.write({"comment": self.comment})
+ if self.comment:
+ self.review_ids.write({"comment": self.comment})
if self.validate_reject == "validate":
rec._validate_tier(self.review_ids)
if self.validate_reject == "reject":
diff --git a/base_tier_validation/wizard/comment_wizard_view.xml b/base_tier_validation/wizard/comment_wizard_view.xml
index 70c1a9285a..a1369d0280 100644
--- a/base_tier_validation/wizard/comment_wizard_view.xml
+++ b/base_tier_validation/wizard/comment_wizard_view.xml
@@ -9,7 +9,13 @@