Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
6134 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Autore

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):

Post correlati Risposte Visualizzazioni Attività
4
mar 24
2911
1
ott 23
4920
4
giu 21
15431
2
ago 17
12413
0
apr 16
2956