Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
5634 Представления

Odoo 11


For an extension module I have same fields and logic for sale.order and account invoice. I would like to have them in a mixin, however, I did not find a solution:

* if I use a plain python class and plain python multiple inheritance (class SaleOrder(MyMixin, models.Model)) it first works, but overriding decorated methods does not. E.g. @api.depends is just executed in MyMixin, overriding a helper method in the subclasses has no effect. I can, however, leave those methods undefined in MyMixin and just define them in the subclasses (what I do now with a bit of duplication). There is also another small issue with this solution: customizing the create method leads to a wrong JSON return: instead of the ID, sale.order(ID,) is returned, leading to a Postgres error on read.

* if i inherit from models.AbstractModel, related and computed fields in MyMixin do not work, because they rely on fields (e.g. partner_id) in sale.order and account.invoice. It throws the error KeyError: 'partner_id'

I tried more approaches (multiple inheritance with inherit = [] etc.) without luck, but I wonder how if there is an intended way to solve this. Also, I want to ask if using the plain python class MyMixin could have other undesired side effects.


Аватар
Отменить
Related Posts Ответы Просмотры Активность
0
мая 25
1102
0
нояб. 24
690
2
июл. 20
5096
2
янв. 25
3308
0
нояб. 24
2657