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})