Technical

Extend Existing Selection in Odoo 10

You might have ever wondered how to add more keys to an existing selection field in Odoo, well the truth is its very easy and i will put you through that in this tutorial.

This tutorial is assumed you know how to develop a module and add the necessary dependencies in the __manifest__.py file.

So for the purpose of this tutorial, we will make changes on the product model in the sales module, and whatever is done here can be replicated in any instance, in any module, you are trying to add more selection keys.

Step 1: Get the model, where you want to add your selection key. 

This the product form and the model name is template.product , we are adding more keys to the Product Type field.

In the Product Type field, we have Consumable,  Service and Stockable Product, just as shown below…

The essence of this above illustration is to fully understand what we have on ground, so we can be able to add what we want. So i hope we are on the same page. Let’s move to the code part.

Step 2: Coding out our Wish

Now that we are ready to code what we want, make sure you have imported odoo and have defined a class, and have inherited the model, if all these are done, then you can add this line of code.

Now, load your server and install the module or refresh your browser and the changes has been done, just as you can see below;

Conclusion

You can see the process was short and easy, just with selection_add, and this usually used in odoo 10, if you search through other versions of odoo, you will barely see them, but you can also use the selection_add in version 9.

If you find this tutorial helpful, kindly comment below and share.

Leave a Reply

Your email address will not be published. Required fields are marked *