SlideShare a Scribd company logo
1 of 12
Model Inheritance in
Odoo 17
Enterprise
Introduction
Enterprise
In This slide we'll explore the various aspects of model
inheritance in Odoo, including its types, implementation, and
best practices. Let's delve into the world of Odoo model
inheritance.
Enterprise
Model Inheritance
● Model inheritance is a fundamental concept in Odoo, the
popular open-source ERP system.
● With model inheritance, you can extend existing
database models without modifying their core
definitions.
● Odoo primarily provides three kinds of model inheritance
which are inheritance via Delegation, Extension, and
Classical methods.
Enterprise
Classical Inheritance
● The _inherit and _name attributes are used together. The
new model retrieves all of its base's fields, methods, and
meta-data (defaults, etc.).
Example:
class ClassicalInheritanceParent(models.Model):
_name = 'classical.inheritance.parent'
_description = 'Classical Inheritance Parent'
name = fields.Char(string="Name")
def call(self):
return self.test_check("Model ClassicalInheritanceParent")
def test_check(self, s):
return "This is a test check with {}".format(s)
Enterprise
Classical Inheritance
Now lets create a model to inherit the parent class.
class ClassicalInheritanceChild(models.Model):
_name = 'inheritance.child'
_inherit = 'classical.inheritance.parent'
_description = 'Classical Inheritance Child'
def call(self):
return self.test_check("Model
ClassicalInheritanceChild")
Enterprise
Classical Inheritance
● The attribute “_name” was the only declared in the
parent class; however, the child class defined both
“_name” and “_inherit”, allowing the child model to
access the parent class's fields and functions.
● So by using the classical inheritance we can access the
data from the parent model to the child model.
Enterprise
Extension Inheritance
● Use the _inherit attribute and not the _name attribute.
The previous model is also replaced by the new one.
● When we wish to add more fields or functionalities to the
existing model, we use this inheritance.
Example:
class SaleOrder(models.Model):
_inherit = sale.order
test_field = fields.Char(string="Test Field")
Enterprise
Extension Inheritance
● When we check in the database we can see that the
test_field is added to the model sale.order.
Enterprise
Delegation Inheritance
● We use the _inherits attribute for delegation inheritance.
● This kind of inheritance also allows you to sink another
model to your current model without changing the views.
● As a result, the database tables will have both a field for
the inherited object and the information from your model
Enterprise
Delegation Inheritance
● Let see an example.
class ProductTemplate(models.Model):
_name = "product.template"
class ProductProduct(models.Model):
_name = "product.product"
_inherits = {'product.template': 'product_tmpl_id'}
product_tmpl_id = fields.Many2one('product.template',
'Product Template', required=True, ondelete="cascade")
Enterprise
Delegation Inheritance
● In this example, we can observe that the product
template has many2one fields in the product model.
These fields are only preserved in the Product template
table, even though the Product model can access the
fields from the Product template.
For More Info.
Check our company website for related
blogs and Odoo book.
Check our YouTube channel for
functional and technical videos in Odoo.
Enterprise
www.cybrosys.com

More Related Content

Similar to What is Model Inheritance in Odoo 17 ERP

The django book - Chap10 : Advanced Models
The django book - Chap10 : Advanced ModelsThe django book - Chap10 : Advanced Models
The django book - Chap10 : Advanced Models
Spin Lai
 
Core Java Programming Language (JSE) : Chapter VI - Class Design
Core Java Programming Language (JSE) : Chapter VI - Class DesignCore Java Programming Language (JSE) : Chapter VI - Class Design
Core Java Programming Language (JSE) : Chapter VI - Class Design
WebStackAcademy
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
Gaurav Tyagi
 

Similar to What is Model Inheritance in Odoo 17 ERP (20)

03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
JAVA-PPT'S.pptx
JAVA-PPT'S.pptxJAVA-PPT'S.pptx
JAVA-PPT'S.pptx
 
JAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptxJAVA-PPT'S-complete-chrome.pptx
JAVA-PPT'S-complete-chrome.pptx
 
Tutorial: Develop an App with the Odoo Framework
Tutorial: Develop an App with the Odoo FrameworkTutorial: Develop an App with the Odoo Framework
Tutorial: Develop an App with the Odoo Framework
 
Django Models
Django ModelsDjango Models
Django Models
 
JAVA-PPT'S.pdf
JAVA-PPT'S.pdfJAVA-PPT'S.pdf
JAVA-PPT'S.pdf
 
Django Heresies
Django HeresiesDjango Heresies
Django Heresies
 
Templates
TemplatesTemplates
Templates
 
Django
DjangoDjango
Django
 
The django book - Chap10 : Advanced Models
The django book - Chap10 : Advanced ModelsThe django book - Chap10 : Advanced Models
The django book - Chap10 : Advanced Models
 
Sbi simulation
Sbi simulationSbi simulation
Sbi simulation
 
Modular ObjectLens
Modular ObjectLensModular ObjectLens
Modular ObjectLens
 
Core Java Programming Language (JSE) : Chapter VI - Class Design
Core Java Programming Language (JSE) : Chapter VI - Class DesignCore Java Programming Language (JSE) : Chapter VI - Class Design
Core Java Programming Language (JSE) : Chapter VI - Class Design
 
Object Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionObject Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) Introduction
 
Tips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptxTips On Trick Odoo Add-On.pptx
Tips On Trick Odoo Add-On.pptx
 
P Training Presentation
P Training PresentationP Training Presentation
P Training Presentation
 
Design patterns in java script, jquery, angularjs
Design patterns in java script, jquery, angularjsDesign patterns in java script, jquery, angularjs
Design patterns in java script, jquery, angularjs
 
Odoo 15 Traditional Class Inheritance
Odoo 15 Traditional Class InheritanceOdoo 15 Traditional Class Inheritance
Odoo 15 Traditional Class Inheritance
 
Unit - 3.pptx
Unit - 3.pptxUnit - 3.pptx
Unit - 3.pptx
 

More from Celine George

More from Celine George (20)

How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17How to Analyse Profit of a Sales Order in Odoo 17
How to Analyse Profit of a Sales Order in Odoo 17
 
How to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 InventoryHow to Manage Closest Location in Odoo 17 Inventory
How to Manage Closest Location in Odoo 17 Inventory
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17How to Send Pro Forma Invoice to Your Customers in Odoo 17
How to Send Pro Forma Invoice to Your Customers in Odoo 17
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
How to Make Down Payments in Odoo 17 Sales App
How to Make Down Payments in Odoo 17 Sales AppHow to Make Down Payments in Odoo 17 Sales App
How to Make Down Payments in Odoo 17 Sales App
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 

Recently uploaded

SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 

Recently uploaded (20)

SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptxMichaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
PUBLIC FINANCE AND TAXATION COURSE-1-4.pdf
PUBLIC FINANCE AND TAXATION COURSE-1-4.pdfPUBLIC FINANCE AND TAXATION COURSE-1-4.pdf
PUBLIC FINANCE AND TAXATION COURSE-1-4.pdf
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 

What is Model Inheritance in Odoo 17 ERP

  • 2. Introduction Enterprise In This slide we'll explore the various aspects of model inheritance in Odoo, including its types, implementation, and best practices. Let's delve into the world of Odoo model inheritance.
  • 3. Enterprise Model Inheritance ● Model inheritance is a fundamental concept in Odoo, the popular open-source ERP system. ● With model inheritance, you can extend existing database models without modifying their core definitions. ● Odoo primarily provides three kinds of model inheritance which are inheritance via Delegation, Extension, and Classical methods.
  • 4. Enterprise Classical Inheritance ● The _inherit and _name attributes are used together. The new model retrieves all of its base's fields, methods, and meta-data (defaults, etc.). Example: class ClassicalInheritanceParent(models.Model): _name = 'classical.inheritance.parent' _description = 'Classical Inheritance Parent' name = fields.Char(string="Name") def call(self): return self.test_check("Model ClassicalInheritanceParent") def test_check(self, s): return "This is a test check with {}".format(s)
  • 5. Enterprise Classical Inheritance Now lets create a model to inherit the parent class. class ClassicalInheritanceChild(models.Model): _name = 'inheritance.child' _inherit = 'classical.inheritance.parent' _description = 'Classical Inheritance Child' def call(self): return self.test_check("Model ClassicalInheritanceChild")
  • 6. Enterprise Classical Inheritance ● The attribute “_name” was the only declared in the parent class; however, the child class defined both “_name” and “_inherit”, allowing the child model to access the parent class's fields and functions. ● So by using the classical inheritance we can access the data from the parent model to the child model.
  • 7. Enterprise Extension Inheritance ● Use the _inherit attribute and not the _name attribute. The previous model is also replaced by the new one. ● When we wish to add more fields or functionalities to the existing model, we use this inheritance. Example: class SaleOrder(models.Model): _inherit = sale.order test_field = fields.Char(string="Test Field")
  • 8. Enterprise Extension Inheritance ● When we check in the database we can see that the test_field is added to the model sale.order.
  • 9. Enterprise Delegation Inheritance ● We use the _inherits attribute for delegation inheritance. ● This kind of inheritance also allows you to sink another model to your current model without changing the views. ● As a result, the database tables will have both a field for the inherited object and the information from your model
  • 10. Enterprise Delegation Inheritance ● Let see an example. class ProductTemplate(models.Model): _name = "product.template" class ProductProduct(models.Model): _name = "product.product" _inherits = {'product.template': 'product_tmpl_id'} product_tmpl_id = fields.Many2one('product.template', 'Product Template', required=True, ondelete="cascade")
  • 11. Enterprise Delegation Inheritance ● In this example, we can observe that the product template has many2one fields in the product model. These fields are only preserved in the Product template table, even though the Product model can access the fields from the Product template.
  • 12. For More Info. Check our company website for related blogs and Odoo book. Check our YouTube channel for functional and technical videos in Odoo. Enterprise www.cybrosys.com