Skip to content

Commit

Permalink
[IMP] base_tier_validation, approve by sequence with option to bypass…
Browse files Browse the repository at this point in the history
… for same reviewer
  • Loading branch information
kittiu authored and Saran440 committed May 11, 2023
1 parent d639f11 commit 519881f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 1 deletion.
3 changes: 3 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,9 @@ def _get_tier_validation_model_names(self):
default=False,
help="Approval order by the specified sequence number",
)
approve_sequence_bypass = fields.Boolean(
help="Bypassed (auto validated), if previous tier was validated by same reviewer",
)

@api.onchange("review_type")
def onchange_review_type(self):
Expand Down
3 changes: 3 additions & 0 deletions base_tier_validation/models/tier_review.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class TierReview(models.Model):
approve_sequence = fields.Boolean(
related="definition_id.approve_sequence", readonly=True
)
approve_sequence_bypass = fields.Boolean(
related="definition_id.approve_sequence_bypass", readonly=True
)

@api.depends("definition_id.approve_sequence")
def _compute_can_review(self):
Expand Down
4 changes: 3 additions & 1 deletion base_tier_validation/models/tier_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,9 @@ def _add_comment(self, validate_reject, reviews):
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)
reviews = self.review_ids.filtered(
lambda l: l.sequence in sequences or l.approve_sequence_bypass
)
if self.has_comment:
return self._add_comment("validate", reviews)
self._validate_tier(reviews)
Expand Down
45 changes: 45 additions & 0 deletions base_tier_validation/tests/test_tier_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,51 @@ def test_12_approve_sequence_same_user(self):
0, len(record1.review_ids.filtered(lambda l: l.status == "pending"))
)

def test_12_approve_sequence_same_user_bypassed(self):
"""Similar to test_12_approve_sequence, with all same users,
but approve_sequence_bypass is True"""
# Create new test record
test_record = self.test_model.create({"test_field": 2.5})
# 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', '>', 1.0)]",
"approve_sequence": True,
"approve_sequence_bypass": True,
"sequence": 20,
}
)
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', '>', 1.0)]",
"approve_sequence": True,
"approve_sequence_bypass": True,
"sequence": 10,
}
)
# Request validation
self.assertFalse(self.test_record.review_ids)
reviews = test_record.with_user(self.test_user_1.id).request_validation()
self.assertTrue(reviews)

record1 = test_record.with_user(self.test_user_1.id)
record1.invalidate_cache()
self.assertTrue(record1.can_review)
# When the first tier is validated, all the rest will be approved.
self.assertEqual(
3, len(record1.review_ids.filtered(lambda l: l.status == "pending"))
)
record1.validate_tier()
self.assertEqual(
0, len(record1.review_ids.filtered(lambda l: l.status == "pending"))
)

def test_13_onchange_review_type(self):
tier_def_id = self.tier_def_obj.create(
{
Expand Down
10 changes: 10 additions & 0 deletions base_tier_validation/views/tier_definition_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@
/>
<field name="sequence" />
<field name="approve_sequence" />
<label for="approve_sequence_bypass" invisible="1" />
<div
name="approve_sequence_bypass_div"
class="o_row"
attrs="{'invisible': [('approve_sequence', '=', False)]}"
>
<field name="approve_sequence_bypass" />
<span
>Bypassed, if previous tier was validated by same reviewer</span>
</div>
</group>
</group>
<notebook>
Expand Down

0 comments on commit 519881f

Please sign in to comment.