Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
8353 Lượt xem

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?

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 12 19
5946
1
thg 2 24
12146
5
thg 8 24
2878
0
thg 1 22
2537
1
thg 3 25
4520