You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.7 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2017 Therp BV <http://therp.nl>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. import sys
  5. import inspect
  6. from openerp.models import MetaModel
  7. def post_load_hook():
  8. """
  9. We try to be smart here: If the crm module is to be loaded too
  10. (or is already loaded), we remove our own models again in order not to
  11. clash with the CRM ones: https://github.com/OCA/partner-contact/issues/283
  12. """
  13. for frame, filename, lineno, funcname, line, index in inspect.stack():
  14. # walk up the stack until we're in load_module_graph
  15. if 'graph' in frame.f_locals:
  16. graph = frame.f_locals['graph']
  17. package = frame.f_locals['package']
  18. if any(p.name == 'crm' for p in graph):
  19. # so crm is installed, then we need to remove your model
  20. # from the list of models to be registered
  21. # TODO: this could be smarter and only ditch models that need
  22. # to be ditched (if crm is in their mro)
  23. our_version = 'openerp.addons.base_partner_merge.' \
  24. 'models.base_partner_merge'
  25. classes_to_ditch = [_class for _name, _class in
  26. inspect.getmembers(sys.modules[our_version],
  27. lambda member: inspect.isclass(member)
  28. and member.__module__ == our_version)]
  29. for _class in classes_to_ditch:
  30. MetaModel.module_to_models['base_partner_merge'] \
  31. .remove(_class)
  32. # and in this case, we also don't want to load our xml file
  33. package.data['data'].remove('views/base_partner_merge.xml')
  34. break