Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][ADD] base_tier_validation: allow comments being optional #712

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions base_tier_validation/models/tier_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions base_tier_validation/models/tier_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 11 additions & 5 deletions base_tier_validation/models/tier_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
)
Expand All @@ -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})
Expand Down
3 changes: 3 additions & 0 deletions base_tier_validation/tests/test_tier_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions base_tier_validation/views/tier_definition_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,14 @@
<group name="notify">
<field name="notify_on_create" />
<field name="has_comment" />
<field
name="comment_required_validate"
attrs="{'invisible': [('has_comment', '=', False)]}"
/>
<field
name="comment_required_reject"
attrs="{'invisible': [('has_comment', '=', False)]}"
/>
</group>
</group>
</page>
Expand Down
14 changes: 12 additions & 2 deletions base_tier_validation/wizard/comment_wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
8 changes: 7 additions & 1 deletion base_tier_validation/wizard/comment_wizard_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@
<field name="arch" type="xml">
<form string="Comment">
<group>
<field colspan="2" name="comment" nolabel="1" />
<field name="comment_required" invisible="True" />
<field
colspan="2"
name="comment"
nolabel="1"
attrs="{'required': [('comment_required', '=', True)]}"
/>
</group>
<footer>
<button
Expand Down
Loading