Join the Odoo Inner Circle to view the premium video below.
Odoo Inheritance - Build a simple warranty registration module

Odoo Inheritance - Build a simple warranty registration module

Odoo Inner Circle Only

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.

Video Length:   56 minutes
Free With Odoo Inner Circle

Learn to use different types of Inheritance in Odoo

Odoo offers you various ways to inherit from an existing model in Odoo. Depending on your requirements you can extend an existing module to add additional fields or behavior, or you can create an entire new model based on an existing model that will maintain its own records and can be extended with additional functionality of its own.

Learn to extend the Odoo CRM application

Naturally one of the main draws to Odoo is that it can be customized to fit the needs of your business. What is more important for developers and IT integrators is that Odoo allows you to extend applications and modules without changing any of the base code in Odoo. In this video we show you how to extend one of the most flexible modules for collecting information on leads, customers, affiliates, or anything related to a 'person'.

Create a simple warranty registration system in an hour

Like most of our videos on Odoo Class we always build around real world examples and solutions. For this example we create a simple way to collect product and serial # along with other important customer related information for the purpose of warranty registration. Rather than starting from scratch, we build a system up using Odoo's lead model (crm.lead) and use inheritance to create an entire new table to manage and maintain the warranty registrations.

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.

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.