Odoo Inheritance - Build a simple warranty registration module
This basic development video demonstrates how Odoo's inheritance model can be used to create a simple warranty registration module with very little code and with absolutely no change at all to the base Odoo source code. In this video we cover a practical application of prototype inheritance in which we can create an entirely new model in Odoo based on the definition of another Odoo model.
Learn to use different types of Inheritance in Odoo
Learn to extend the Odoo CRM application
Create a simple warranty registration system in an hour
Understanding Odoo Inheritence
One of the most powerful aspects of developing applications in Odoo is that is quite easy to extend Odoo's funcationality without changing anything inside of the base Odoo source code itself. This functionality is provided through a process known has inheritence. Models such as res.partner, the customer/supplier model used in Odoo can be extended to include new fields, rules and processes without disturbing Odoo's core applications. This allows for more easy updates and maintenance of your changes.
New models based on existing models
In this video we explore a special type of inheritence, prototype inheritence, that allows you to create an entirely new model inside Odoo based on an exsisting model. For our real world example we use a model that is often extended in this manner, the crm.lead model that is used to manage leads in Odoo.
Things to know about Odoo Inheritence
Do I need to use inheritence, wouldn't be easier to just modify the Odoo source code?
Yes, you really do need to use inheritence as modifying the Odoo source code directly is a very bad practice. By leaving the Odoo source code untouched it makes it much easier to pull down updates and patches. Odoo is one of the fastest developing business application frameworks out there. While most ERP systems seem to take forever to add even the most simple features, Odoo's functionality is expanding rapidly.
Modify base code only for prototyping and proof of concept
There are times when modifying Odoo base code can make sense. If you have not figured the problem out at all and have no idea how you would implement a particular feature, that is an example of a scenerio where you take sandbox version of Odoo to work through the problem. Once you have it figured out and have a working prototype then inherit from Odoo's base classes and create a standalone module that can provide you the functionality you need.
Use Class Inheritence when you want new fields in Odoo added to your existing records
With class inheritence you don't create a new model but instead extend the model that you are inheriting from. This could mean adding fields but also adding additonal python methods as well. Often the new fields you add can be fields that relate to other tables. This gives you a lot of power within in Odoo to associate information that works best for your company. For example, if you were a tatoo shop and wanted to attach the artist that did the design to the product you can simply add an artist_id field and reference it to res.partner. The product list is still exactliy the same, but now you have the option to attach an artist to any product without having to create a dozen or more fields to describe that artist.
Use Prototype Inheritence when you want a new Odoo model with its own records
Prototype inheritence in Odoo allows you to inherit and extend from an existing model, but also creates an entirely new model. That model then has its own set of records that is entirely seperate from the parent class. Using our previous tatoo artist example, let's say that they have a list of these artists but for some reason they don't want them cluttering up their customers or supplier records. Sure you could add another field like 'is_artist' to res.partner but this could have disadvantages as it could complicate filters in other parts of the system. Instead you could choose to use protype inheritence to inherit from res.partner but instead put them into an entire other collection. But because these artists are inherited from the res.partner class they have a name, address, email, a picture and pretty much everything you need to describe an artist. Even better you can now extend that further with perhaps a portfolio or other content that would be applicable to artists.
Odoo Model and View inheritence are similar in principal but drastically different in implementation
As you begin learning about Odoo inheritence an important tip for beginners is that model inheritence and view inheritence are often both required to get a desired result in your application. While they are similar view inheritence uses XML syntax to describe what external_id is the view you wish to inherit from. As you will see in many of our videos we can often use the developer mode in Odoo to quickly find which external_id we need to inherit from.