How to inherit only few fields in odoo 12 model

Viewed 55

I can't figure out how I inherit only one or few selective fields for eg: my.model.main ---> my.model.test if model my.model.main has columns [a,b,c,d,e,f,g] , I want only to inherit columns [a,d,g] in the new model my.model.test Please share a sample code for odoo 12 Thank you :)

1 Answers

You shouldn't inherit if you can only make use of a few columns of the base model. A cleaner approach in this is case is to separate the columns [a, d, g] into a separate model my.model.mixin and then let my.model.test and my.model.main both inherit from my.model.mixin.

If you still want to only inherit a few columns, you'd need to look into the functions init_models, _auto_init, and init. The init method can be overridden to implement your own custom database scheme for your model. This is usually only recommended for adding some indices or defining a view though and will probably lead to more problems if you remove columns in there.

Related