Contributors mailing list archives
contributors@odoo-community.org
Browse archives
Re: How to write hook addon properly.
by
Holger Brunn
some nitpickings > All of the python code is "loaded and available" and the classes are > instantiated Odoo loads (as in `import ...`) all code that's in the addon path. It does not instantiate the classes defined in non installed modules as in `my_class()` > whether the module is installed or not - Odoo will control, > by knowledge of the modules installed, which methods are to be called and > in which order. actually, the framework won't control anything for non-installed modules. And it can't and it shouldn't. If a module needs monkey patching I'd suggest to do this in _register_hook of some model, then you know your module is actually installed. For models, Odoo will create python classes on the fly mimicking the inheritance chain of the modules installed, so if you have modules A and B both having a model inheriting from res.partner, and A depends on B, Odoo will carve classes that in python inheritance look somewhat like base#res.partner B#res.partner (inherits from base#res.partner) A#res.partner (inherits from B#res.partner) If you need to do fancy stuff with inheritance, inspect self.__mro__ - this is more or less where python stores the chain of functions to call when you say super(...). You can also manipulate this programmatically, or call just the version of the function you need. So what the example code should be doing is class MrpProductProduce(models.TransientModel): _inherit = "mrp.product.produce" def _register_hook(self): # do the patching, and detect if it happend before # (models are registered with every registry reload, that can happen # on run time too) # cf https://github.com/OCA/OCB/blob/9.0/openerp/models.py#L5329 return super()._register_hook() #
Reference
-
How to write hook addon properly.
byEcosoft Co. Ltd., Kitti Upariphutthiphong-
Re: How to write hook addon properly.
by Richard deMeester <richard.demeester@willdooit.com> - 11/03/2019 23:48:36 - 0 -
Re: How to write hook addon properly.
byEcosoft Co. Ltd., Kitti Upariphutthiphong -
Re: How to write hook addon properly.
byEcosoft Co. Ltd., Kitti Upariphutthiphong -
Re: How to write hook addon properly.
by Richard deMeester <richard.demeester@willdooit.com> - 07/03/2019 23:44:59 - 2 -
Re: How to write hook addon properly.
byEcosoft Co. Ltd., Kitti Upariphutthiphong -
Re: How to write hook addon properly.
byForgeFlow, S.L., Jordi Ballester Alomar
-