Skip to content

Commit 67d33a6

Browse files
committed
[FIX] base_tier_validation: ensure skip_validation_check bypasses validations
1 parent bbc54d2 commit 67d33a6

File tree

5 files changed

+115
-67
lines changed

5 files changed

+115
-67
lines changed

base_tier_validation/README.rst

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.. image:: https://odoo-community.org/readme-banner-image
2-
:target: https://odoo-community.org/get-involved?utm_source=readme
3-
:alt: Odoo Community Association
4-
51
====================
62
Base Tier Validation
73
====================
@@ -17,7 +13,7 @@ Base Tier Validation
1713
.. |badge1| image:: https://img.shields.io/badge/maturity-Mature-brightgreen.png
1814
:target: https://odoo-community.org/page/development-status
1915
:alt: Mature
20-
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
2117
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2218
:alt: License: AGPL-3
2319
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--ux-lightgray.png?logo=github
@@ -103,6 +99,29 @@ To configure Tier Validation Exceptions, you need to:
10399
- If check *Write after Validation* and *Write under Validation*,
104100
records will be able to be modified defined fields always.
105101

102+
Usage
103+
=====
104+
105+
**Bypass tier validation context key**
106+
107+
``skip_validation_check``: This flag will bypass the tier validation
108+
workflow. When this context key is set to True, aall tier validations
109+
within the write and \_write methods are bypassed.
110+
111+
This is the ideal flag to use in your unit tests.
112+
113+
.. code:: python
114+
115+
# Example: Confirming a sale order in a unit test
116+
# without triggering the tier validation workflow.
117+
sale_order.with_context(skip_validation_check=True).action_confirm()
118+
119+
**Skip initial state check**
120+
121+
``skip_check_state_condition``: This forces the initial state check to
122+
pass. This makes the system believe the record is in a valid state to
123+
behin the validation process, even if it isn't.
124+
106125
Known issues / Roadmap
107126
======================
108127

base_tier_validation/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"name": "Base Tier Validation",
55
"summary": "Implement a validation process based on tiers.",
6-
"version": "17.0.4.0.0",
6+
"version": "17.0.4.0.1",
77
"development_status": "Mature",
88
"maintainers": ["LoisRForgeFlow"],
99
"category": "Tools",

base_tier_validation/models/tier_validation.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,16 @@ def _check_tier_state_transition(self, vals):
371371
) not in (self._state_to + [self._cancel_state])
372372

373373
def write(self, vals):
374-
self._tier_validation_check_state_on_write(vals)
375-
self._tier_validation_check_write_allowed(vals)
376-
self._tier_validation_check_write_remove_reviews(vals)
374+
if not self._context.get("skip_validation_check"):
375+
self._tier_validation_check_state_on_write(vals)
376+
self._tier_validation_check_write_allowed(vals)
377+
self._tier_validation_check_write_remove_reviews(vals)
377378
return super().write(vals)
378379

379380
def _write(self, vals):
380-
if self._tier_validation_state_field_is_computed:
381+
if self._tier_validation_state_field_is_computed and not self._context.get(
382+
"skip_validation_check"
383+
):
381384
self._tier_validation_check_state_on_write(vals)
382385
self._tier_validation_check_write_remove_reviews(vals)
383386
return super()._write(vals)
@@ -437,7 +440,6 @@ def _tier_validation_check_write_allowed(self, vals):
437440
rec.review_ids
438441
and rec._check_tier_state_transition(vals)
439442
and not rec._check_allow_write_under_validation(vals)
440-
and not rec._context.get("skip_validation_check")
441443
):
442444
(
443445
allowed_fields,
@@ -464,7 +466,6 @@ def _tier_validation_check_write_allowed(self, vals):
464466
and rec._tier_validation_get_current_state_value()
465467
in (self._state_to + [self._cancel_state])
466468
and not rec._check_allow_write_after_validation(vals)
467-
and not rec._context.get("skip_validation_check")
468469
):
469470
(
470471
allowed_fields,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
**Bypass tier validation context key**
2+
3+
```skip_validation_check```: This flag will bypass the tier validation
4+
workflow. When this context key is set to True, aall tier validations within the write and _write methods are bypassed.
5+
6+
This is the ideal flag to use in your unit tests.
7+
8+
``` python
9+
# Example: Confirming a sale order in a unit test
10+
# without triggering the tier validation workflow.
11+
sale_order.with_context(skip_validation_check=True).action_confirm()
12+
```
13+
14+
**Skip initial state check**
15+
16+
```skip_check_state_condition```: This forces the initial state check to pass. This makes the system believe the record is in a valid state to behin the validation process, even if it isn't.

0 commit comments

Comments
 (0)