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.