openerp-expert-framework team mailing list archive
-
openerp-expert-framework team
-
Mailing list archive
-
Message #00788
Re: Multiple inheritance problem with MRO
On 20-04-12 20:01, Ovnicraft wrote:
Hello we are working with hr_payroll module, so we implement another
module inherit from it.
Here is our case:
A hr_payroll (core openerp)
B hr_payroll_b (custom module) here we redefine compute_sheet method
C hr_payroll_c (another custom module) here we redefine compute_sheet
again but we need run compute_sheet redefined in B module but sytem
calls method from A.
Reading about MRO[1] in Python , i need to know how to solve this
issue in OpenERP and if system support this.
Hi Christian,
are you sure your module dependencies are set up correctly? If B depends
on A and C depends on B then you should not need to rearrange the
__mro__. In fact, if C calls A directly then B may not even be
accessible through the __mro__ from C.
I only know how to use the __mro__ to *skip* to a higher level method,
not inject another module's method. But depending on your configuration,
you may be able to use elements from this example to retrieve the method
you want to apply.
Cheers,
Stefan.
class project_work(osv.osv):
_inherit = "project.task.work"
def create(self, cr, uid, vals, *args, **kwargs):
#
# (custom code to manipulate 'vals' left out for this example)
#
# Finally, run super on 'vals'
for x in self.__class__.__mro__:
# bypassing project_timesheet's create()
if x.__module__.split('.')[0] == 'project':
return x.create(self, cr, uid, vals, *args, **kwargs)
--
Therp - Maatwerk in open ontwikkeling
Stefan Rijnhart - Ontwerp en implementatie
mail: stefan@xxxxxxxx
tel: +31 (0) 614478606
web: http://therp.nl
References