1919#
2020##############################################################################
2121
22- import inspect
2322import logging
2423from contextlib import contextmanager
25- from openerp import models
26-
2724from .deprecate import log_deprecate , DeprecatedClass
2825
2926_logger = logging .getLogger (__name__ )
@@ -49,42 +46,32 @@ def _get_openerp_module_name(module_path):
4946
5047
5148def install_in_connector ():
52- """ Installs an OpenERP module in the ``Connector`` framework.
49+ log_deprecate ("This call to 'install_in_connector()' has no effect and is "
50+ "not required." )
51+
52+
53+ def is_module_installed (env , module_name ):
54+ """ Check if an Odoo addon is installed.
5355
54- It has to be called once per OpenERP module to plug.
56+ The function might be called before `connector` is even installed;
57+ in such case, `ir_module_module.is_module_installed()` is not available yet
58+ and this is why we first check the installation of `connector` by looking
59+ up for a model in the registry.
5560
56- Under the cover, it creates a ``openerp.models.AbstractModel`` whose
57- name is the name of the module with a ``.intalled`` suffix:
58- ``{name_of_the_openerp_module_to_install}.installed``.
61+ :param module_name: name of the addon to check being 'connector' or
62+ an addon depending on it
5963
60- The connector then uses this model to know when the OpenERP module
61- is installed or not and whether it should use the ConnectorUnit
62- classes of this module or not and whether it should fire the
63- consumers of events or not.
6464 """
65- # Get the module of the caller
66- module = inspect .getmodule (inspect .currentframe ().f_back )
67- openerp_module_name = _get_openerp_module_name (module .__name__ )
68- # Build a new AbstractModel with the name of the module and the suffix
69- name = "%s.installed" % openerp_module_name
70- class_name = name .replace ('.' , '_' )
71- # we need to call __new__ and __init__ in 2 phases because
72- # __init__ needs to have the right __module__ and _module attributes
73- model = models .MetaModel .__new__ (models .MetaModel , class_name ,
74- (models .AbstractModel ,), {'_name' : name })
75- # Update the module of the model, it should be the caller's one
76- model ._module = openerp_module_name
77- model .__module__ = module .__name__
78- models .MetaModel .__init__ (model , class_name ,
79- (models .AbstractModel ,), {'_name' : name })
80-
81-
82- # install the connector itself
83- install_in_connector ()
84-
85-
86- def is_module_installed (pool , module_name ):
87- return bool (pool .get ('%s.installed' % module_name ))
65+ if env .registry .get ('connector.backend' ):
66+ if module_name == 'connector' :
67+ # fast-path: connector is necessarily installed because
68+ # the model is in the registry
69+ return True
70+ # for another addon, check in ir.module.module
71+ return env ['ir.module.module' ].is_module_installed (module_name )
72+
73+ # connector module is not installed neither any sub-addons
74+ return False
8875
8976
9077def get_openerp_module (cls_or_func ):
0 commit comments