hello,
Can I inherit multi model in one class and add same field to each model
like this:
class Multi():
_inherit=["model1","model2", "model3"]
new_field=fields.integer()
SO new_field thiis field add to these inherited models !!!!!!
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
hello,
Can I inherit multi model in one class and add same field to each model
like this:
class Multi():
_inherit=["model1","model2", "model3"]
new_field=fields.integer()
SO new_field thiis field add to these inherited models !!!!!!
Hi nohaAhmad,
Yes in order to inherit multiple model you can define it just like your question, however you need to define a new _name for your inherited models like so :
class Multi(models.Model):
_name = 'sale.order'
_inherit = ['sale.order', 'mail.thread']
new_field = fields.Char("test")
The code above will re-define sale.order by inheriting sale.order model and adding a new mail.thread model. it is actually not recommended doing that way, since code above will redefine the sale.order with your custom module. as odoo suggest, we should rather inherit the existing code (extending it) rather than redefine it.
To properly inherit modeol, you need to define different class and define the different inherit. You need to inherit model1 and model 2 in different class like this :
class InheritModel1(models.Model):
_inherit = ['model1']
new_field = fields.Integer()
class InheritModel2(models.Model):
_inherit = ['model2']
new_field = fields.Integer()
The code above will create a new_field in model1 and model2. The new_field is independently created to each module you are inherited.
Hope this helpful, best regards,
Altela (altelasoftware.com)
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up
1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.
Hi,
Refer to this forum it shows multiple models inherited in a class
https://www.odoo.com/forum/help-1/multiple-models-inherited-in-a-class-156901
Hope it helps you