From 754320486c4639487217cb6234793e63ef07be27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Mon, 11 Oct 2021 08:55:57 +0200 Subject: [PATCH] [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 --- partner_tier_validation/__init__.py | 1 + partner_tier_validation/__manifest__.py | 1 + .../data/tier_definition.xml | 1 + partner_tier_validation/hooks.py | 18 ++++++++++++++++++ 4 files changed, 21 insertions(+) create mode 100644 partner_tier_validation/hooks.py diff --git a/partner_tier_validation/__init__.py b/partner_tier_validation/__init__.py index 31660d6a9..c0d9f3d12 100644 --- a/partner_tier_validation/__init__.py +++ b/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 diff --git a/partner_tier_validation/__manifest__.py b/partner_tier_validation/__manifest__.py index 8321c7d0a..7b2ca7f1f 100644 --- a/partner_tier_validation/__manifest__.py +++ b/partner_tier_validation/__manifest__.py @@ -14,4 +14,5 @@ "data/tier_definition.xml", "views/res_partner_view.xml", ], + "post_init_hook": "post_init_hook", } diff --git a/partner_tier_validation/data/tier_definition.xml b/partner_tier_validation/data/tier_definition.xml index 4a5436fa0..528842bca 100644 --- a/partner_tier_validation/data/tier_definition.xml +++ b/partner_tier_validation/data/tier_definition.xml @@ -5,6 +5,7 @@ group domain + ["&",["is_company","=",True],"|",["active","=",True],["active","=",False]] diff --git a/partner_tier_validation/hooks.py b/partner_tier_validation/hooks.py new file mode 100644 index 000000000..0bfebf185 --- /dev/null +++ b/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})