Help

0

How to easily inherit onchange, contrains and compute methods using _inherits delegation?

The ORM documentation states the following

Warning

when using delegation inheritance, methods are not inherited, only fields

I am using delegation inheritance, but I need the children models to keep the behavior of the parent on every field. This means that @onchange, @constrains, @depends and every other method should exist in the children models.

The only way I can think of for this to work is to copy every method signature and call the parent's method from within. Is there an easier and more maintainable/scalable way?

Avatar
Discard
1 Answer
0
Best Answer

So I didn't find a simlpe and quick way to do this, but after a lot of research this is the best I could do. This is an example of what I wrote on the child models.

@api.onchange('location_id')
def _onchange_location(self):
    for r in self:
        r.parent_id.update({
            'location_id': r.location_id,
            'product_id': r.product_id,
            })
        r.parent_id._onchange_location()

I had to manually update the values of the used variables in the parent model, since they weren't registering with the new values when the onchange function was called. I had to use `update` instead of `write` because the latter was causing double calls to the database and double chatter messages on tracked variables.

Avatar
Discard