Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
1 Vastaa
8340 Näkymät

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
Hylkää
Tekijä Paras vastaus

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
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
jouluk. 19
5936
1
helmik. 24
12135
5
elok. 24
2862
0
tammik. 22
2531
1
maalisk. 25
4510