Skip to content

Commit

Permalink
[15.0][ENH] base_tier_validation, add Notify Reviewers by Sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
kittiu committed Apr 11, 2024
1 parent 3f73626 commit 02ecdad
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
7 changes: 7 additions & 0 deletions base_tier_validation/models/tier_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ def _get_tier_validation_model_names(self):
default=False,
help="Approval order by the specified sequence number",
)
notify_by_sequence = fields.Boolean(
string="Notify Approver by Sequence",
help="Use with 'Approve by sequence' to ensure that, the next approver "
"will be notified only when he/she is the next approver in sequence.\n"
"Note: this works independently from 'Notify reviewers on creaton', "
"so it shouldn't be used together",
)
approve_sequence_bypass = fields.Boolean(
help="Bypassed (auto validated), if previous tier was validated by same reviewer",
)
Expand Down
35 changes: 35 additions & 0 deletions base_tier_validation/models/tier_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ def _validate_tier(self, tiers=False):
rec = self.env[review.model].browse(review.res_id)
rec._notify_accepted_reviews()

# Notify by sequence
self._notify_by_sequence()

def _get_requested_notification_subtype(self):
return "base_tier_validation.mt_tier_validation_requested"

Expand Down Expand Up @@ -389,6 +392,7 @@ def validate_tier(self):
return self._add_comment("validate", user_reviews)
self._validate_tier(reviews)
self._update_counter()
self._notify_by_sequence()

def reject_tier(self):
self.ensure_one()
Expand Down Expand Up @@ -457,6 +461,36 @@ def _notify_review_requested(self, tier_reviews):
body=rec._notify_requested_review_body(),
)

def _notify_by_sequence_body(self):
return _("A review is requested from %(requester)s (sent by %(sender)s)") % {
"requester": self.review_ids[0].requested_by.name,
"sender": self.env.user.name,
}

def _notify_by_sequence(self):
self.refresh() # ensure new tier reviews is loaded
self = self.with_context(mail_post_autofollow=False).sudo()
post = "message_post"
if hasattr(self, post):
for rec in self:
users = rec.review_ids.mapped("reviewer_ids")
# tier reviews for notify_by_sequence
sequences = []
for user in users:
sequences += rec._get_sequences_to_approve(user)
reviews_to_notify = rec.review_ids.filtered(
lambda r: r.definition_id.notify_by_sequence
and r.definition_id.approve_sequence
and r.sequence in sequences
and r.res_id == rec.id
)
users_to_notify = reviews_to_notify.mapped("reviewer_ids")
if len(users_to_notify) > 0:
getattr(rec, post)(
body=rec._notify_by_sequence_body(),
partner_ids=users_to_notify.mapped("partner_id").ids,
)

def _prepare_tier_review_vals(self, definition, sequence):
return {
"model": self._name,
Expand Down Expand Up @@ -487,6 +521,7 @@ def request_validation(self):
created_trs += tr_obj.create(vals)
self._update_counter()
self._notify_review_requested(created_trs)
self._notify_by_sequence()
return created_trs

def _notify_restarted_review_body(self):
Expand Down
6 changes: 6 additions & 0 deletions base_tier_validation/static/src/xml/tier_review_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<th name="th_done_by" class="text-right">Done by</th>
<th name="th_reviewed_date" class="text-right">Validation Date</th>
<th name="th_comment" class="text-right">Comment</th>
<th name="th_notified" class="text-right">Notified</th>
</tr>
</thead>
<tbody class="sale_tbody">
Expand Down Expand Up @@ -81,6 +82,11 @@
<span t-esc="review.comment" />
</t>
</td>
<td name="td_notified" class="text-right">
<t t-if="review.notified">
<span t-esc="review.notified and 'Yes' or 'No'" />
</t>
</td>
</tr>
</t>
</tbody>
Expand Down
4 changes: 4 additions & 0 deletions base_tier_validation/views/tier_definition_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
<group name="more_option">
<group name="notify">
<field name="notify_on_create" />
<field
name="notify_by_sequence"
attrs="{'invisible': [('approve_sequence', '=', False)]}"
/>
<field name="has_comment" />
</group>
</group>
Expand Down

0 comments on commit 02ecdad

Please sign in to comment.