Skip to Content
Menu
This question has been flagged
1 Odpoveď
6148 Zobrazenia

I'm learning about Odoo , when i read about inheritance of Odoo that make me very confused special is _inherit (no _name property) and _inherit (_name property value same as _inherit) . they look  same., i found the their defined at 

\https://www.odoo.com/forum/help-1/question/the-different-openerp-model-inheritance-mechanisms-what-s-the-difference-between-them-and-when-should-they-be-used-46#answer-190

  • If the _name as the same value as the inherited class it will do a basic inheritance.
  • If you forget to add the _inherit you will redefine the model

Could anyone explain for me what is  difference between their? ( a real situation, example )


Thank for all.

Avatar
Zrušiť
Best Answer

When using the _inherit and _name attributes together, Odoo creates a new model using the existing one (provided via _inherit) as a base. The new model gets all the fields, methods and meta-information (defaults & al) from its base.

When using _inherit but leaving out _name, the new model replaces the existing one, essentially extending it in-place. This is useful to add new fields or methods to existing models (created in other modules), or to customize or reconfigure them (e.g. to change their default sort order)

see examples in Odoo ORM:

Odoo ORM API

Avatar
Zrušiť
Autor

Thank you !!! But i'm not clearly about case _inherit and _name have same value. Is it like _inherit and not _name ?

When using the _inherit and _name attributes together, Odoo creates a new model using the existing one (provided via _inherit) as a base. The new model gets all the fields, methods and meta-information (defaults & al) from its base.

When using _inherit but leaving out _name, the new model replaces the existing one, essentially extending it in-place. This is useful to add new fields or methods to existing models (created in other modules), or to customize or reconfigure them (e.g. to change their default sort order):

Related Posts Replies Zobrazenia Aktivita
4
mar 24
2946
1
okt 23
4945
4
jún 21
15452
2
aug 17
12422
0
apr 16
2959