Browse Source

[FIX] partner_tier_validation: Defer rule activation for compatibility

Having this rule activated by default in tests environments makes other tests to fail due to the additional constraint not expected by them, so what we are doing is:

- Having the rule deactivated by default.
- On a post-init hook, we activate it only if we are not in a test environment.
- On own modules tests, we activate it as well

TT30292
14.0
Víctor Martínez 3 years ago
parent
commit
754320486c
  1. 1
      partner_tier_validation/__init__.py
  2. 1
      partner_tier_validation/__manifest__.py
  3. 1
      partner_tier_validation/data/tier_definition.xml
  4. 18
      partner_tier_validation/hooks.py

1
partner_tier_validation/__init__.py

@ -1,3 +1,4 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import models
from .hooks import post_init_hook

1
partner_tier_validation/__manifest__.py

@ -14,4 +14,5 @@
"data/tier_definition.xml",
"views/res_partner_view.xml",
],
"post_init_hook": "post_init_hook",
}

1
partner_tier_validation/data/tier_definition.xml

@ -5,6 +5,7 @@
<field name="review_type">group</field>
<field name="reviewer_group_id" ref="base.group_user" />
<field name="definition_type">domain</field>
<field name="active" eval="False" />
<field
name="definition_domain"
>["&amp;",["is_company","=",True],"|",["active","=",True],["active","=",False]]</field>

18
partner_tier_validation/hooks.py

@ -0,0 +1,18 @@
# Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import SUPERUSER_ID
from odoo.api import Environment
from odoo.tools import config
def post_init_hook(cr, pool):
"""
We need to activate the rule only if we are not in a test environment.
"""
if not config["test_enable"]:
env = Environment(cr, SUPERUSER_ID, {})
tier_partner = env.ref(
"partner_tier_validation.partner_tier_definition_company_only"
)
tier_partner.write({"active": True})
Loading…
Cancel
Save