Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
1 Antworten
8344 Ansichten

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
Verwerfen
Autor Beste Antwort

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
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
1
Dez. 19
5941
1
Feb. 24
12139
5
Aug. 24
2869
0
Jan. 22
2533
1
März 25
4512