Develop a Custom Settings Page in Odoo
Odoo's framework provides the ability to create settings pages for modules and applications.
Odoo's framework provides the ability to create settings pages for modules and applications. In this video learn how to use this framework to create your own custom settings page.
Building a custom settings page using Odoo's framework
Often times when building a module or application you will need to create or modify a settings page to provide an administrator the ability to configure the application for a specific business requirement. If you have built your own settings page you already know there are a few things you must understand about the Odoo framework... If you are new to developing settings pages, this video is for you.
Taking a step-by-step approach to developing Odoo modules
Once again this video takes a step-by-step approach in teaching you exactly how to customize the Odoo framework and solve business requirements. Learn how to customize settings pages in Odoo and provide your users with specific configuration options for your module or application. In this video we use a real-world development example that adds real functionality to the application.
What do I need to know to develop settings pages in Odoo?
Step 1 - Finding the view for the settings form
In our real world example we take an application that provides Slack integration into Odoo and wish to make the application easier to configure by providing a settings page.
As this application will integrate with the sales/crm application we want to customize the sale settings to include new options for our slack application. We can easily find out which view we need to customize by turning on developer mode and navigating to the settings page and choosing Edit FormView from the developer settings.
Step 2 - Understand the view inheritence
Next you must determine which view you wish to inherit from and find it's extrenal_id. You can see here that for the sale.settings view that we have the Inherited Views tab selected. Under there we can the options that the CRM application has added to the sale.settings menu. We wish to inherit from the CRM view crm.view_sale_config_settings because this application is a CRM application that manages customer relationships. This also means that the CRM application must be installed in order for our custom Slack integration application to function properly.
Code from the standard Odoo sales configuration settings
<record id="view_sale_config_settings" model="ir.ui.view">
<field name="name">sale settings</field>
<field name="model">sale.config.settings</field>
<field name="arch" type="xml">
<form string="Configure Sales" class="oe_form_configuration" name="sale_config_form">
<header>
<button string="Apply" type="object" name="execute" class="oe_highlight"/>
<button string="Cancel" type="object" name="cancel" class="oe_link"/>
</header>
<div id="main"/>
</form>
</field>
</record>
Step 3 - Determine the external id from the parent view you wish to inherit from
If your are new to Odoo Development this can be a little confusing at first. That is largely why the video dedicates time in showing you how to navigate the various views in Odoo so you can completely understand how everything fits together.
Step 4 - Add fields to the model
This should be very simple for even beginning Odoo developers. Simply add the custom fields you wish to use for storing your custom settings. Details for this step are provided in the video.
Step 5 - Create your custom view
Now that you know exactly how you need to integrate your view with Odoo's CRM application and associated settings we can begin writing our view.
As you will see in the code example we create a record in XML that inherits from sales_team.view_sale_config_settings. This demonstrates a typical aspect of Odoo development. Much of the work is examining existing Odoo source code. In fact if you are not spending a lot of time looking at the base Odoo application code when building your own custom modules, you are probably doing something wrong... or at the very least you are not being productive.
Code Example for a Custom Settings View in Odoo
<record id="view_slack_config_settings" model="ir.ui.view">
<field name="name">slack settings</field>
<field name="model">sale.config.settings</field>
<field name="inherit_id" ref="sales_team.view_sale_config_settings"/>
<field name="arch" type="xml">
<div id="main" position="inside">
<group string="Slack" name="config_slack">
<label for="module_crm_slack" string="Slack integration"/>
<div>
<field name="module_crm_slack" class="oe_inline"/>
<label for="module_crm_slack" invisible="1"/>
</div>
</group>
</div>
</field>
</record>
TOPICS INCLUDE:
Your Instructor
Diogo Duarte has a degree in Electrical Engineering and Computer Science with 20 years of experience in several industries, both functional and technical. He is an Odoo developer and Project Manager across the EU, the USA, and AU and the Head of Technical Consulting for OdooClass since 2014.
Diogo is an expert in all things Odoo and has been consulted on hundreds of Odoo projects in nearly every industry sector. If you need a problem solved with Odoo, Diogo can find you a solution.