Skip to content

Commit

Permalink
fixup! [ADD] base_tier_validation: allow comments being optional
Browse files Browse the repository at this point in the history
  • Loading branch information
hbrunn committed Sep 15, 2023
1 parent a3e6543 commit 717ac6d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
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 @@ -51,14 +51,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 @@ -333,7 +339,7 @@ def validate_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_validate:
return self._add_comment("validate", reviews)
self._validate_tier(reviews)
self._update_counter({"review_deleted": True})
Expand All @@ -342,7 +348,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

0 comments on commit 717ac6d

Please sign in to comment.