From 519881f997de62461c054a0be287564361dbb020 Mon Sep 17 00:00:00 2001 From: Kitti U Date: Fri, 5 Nov 2021 17:01:57 +0700 Subject: [PATCH] [IMP] base_tier_validation, approve by sequence with option to bypass for same reviewer --- .../models/tier_definition.py | 3 ++ base_tier_validation/models/tier_review.py | 3 ++ .../models/tier_validation.py | 4 +- .../tests/test_tier_validation.py | 45 +++++++++++++++++++ .../views/tier_definition_view.xml | 10 +++++ 5 files changed, 64 insertions(+), 1 deletion(-) diff --git a/base_tier_validation/models/tier_definition.py b/base_tier_validation/models/tier_definition.py index e3700e5b73..7ef4404058 100644 --- a/base_tier_validation/models/tier_definition.py +++ b/base_tier_validation/models/tier_definition.py @@ -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): diff --git a/base_tier_validation/models/tier_review.py b/base_tier_validation/models/tier_review.py index 95e4f757c8..375c2fefef 100644 --- a/base_tier_validation/models/tier_review.py +++ b/base_tier_validation/models/tier_review.py @@ -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): diff --git a/base_tier_validation/models/tier_validation.py b/base_tier_validation/models/tier_validation.py index 2a0d199df8..980490f735 100644 --- a/base_tier_validation/models/tier_validation.py +++ b/base_tier_validation/models/tier_validation.py @@ -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) diff --git a/base_tier_validation/tests/test_tier_validation.py b/base_tier_validation/tests/test_tier_validation.py index 67760900a5..0c8354ece1 100644 --- a/base_tier_validation/tests/test_tier_validation.py +++ b/base_tier_validation/tests/test_tier_validation.py @@ -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( { diff --git a/base_tier_validation/views/tier_definition_view.xml b/base_tier_validation/views/tier_definition_view.xml index 6e68a06a60..64e0227aa8 100644 --- a/base_tier_validation/views/tier_definition_view.xml +++ b/base_tier_validation/views/tier_definition_view.xml @@ -71,6 +71,16 @@ /> +