From b58b663fd70f8745800765e27d67d9895b07881e Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Tue, 25 Apr 2017 19:37:21 +0200 Subject: [PATCH] [IMP] coexist with crm fixes #283 --- base_partner_merge/__init__.py | 1 + base_partner_merge/__openerp__.py | 1 + base_partner_merge/hooks.py | 26 ++++++++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 base_partner_merge/hooks.py diff --git a/base_partner_merge/__init__.py b/base_partner_merge/__init__.py index 63a531f4d..488930a4b 100644 --- a/base_partner_merge/__init__.py +++ b/base_partner_merge/__init__.py @@ -1,2 +1,3 @@ from . import base_partner_merge from . import validate_email +from .hooks import post_load_hook diff --git a/base_partner_merge/__openerp__.py b/base_partner_merge/__openerp__.py index c6cfc9519..4ce75ef9f 100644 --- a/base_partner_merge/__openerp__.py +++ b/base_partner_merge/__openerp__.py @@ -17,4 +17,5 @@ 'views/base_partner_merge.xml', ], 'installable': True, + 'post_load': 'post_load_hook', } diff --git a/base_partner_merge/hooks.py b/base_partner_merge/hooks.py new file mode 100644 index 000000000..7e3dbd9c0 --- /dev/null +++ b/base_partner_merge/hooks.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# © 2017 Therp BV +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +import inspect +from openerp.models import MetaModel + + +def post_load_hook(): + """We try to be smart here: If the crm module is to be loaded too + (or is already loaded), we remove our own models again in order not to + clash with the CRM ones: https://github.com/OCA/partner-contact/issues/283 + """ + for frame, filename, lineno, funcname, line, index in inspect.stack(): + # walk up the stack until we're in load_module_graph + if 'graph' in frame.f_locals: + graph = frame.f_locals['graph'] + package = frame.f_locals['package'] + if any(p.name == 'crm' for p in graph): + # so crm is installed, then we need to remove your model + # from the list of models to be registered + # TODO: this could be smarter and only ditch models that need + # to be ditched (if crm is in their mro) + MetaModel.module_to_models['base_partner_merge'] = [] + # and in this case, we also don't want to load our xml files + package.data['data'].remove('views/base_partner_merge.xml') + break