activate-settings-from-code-odoo.png
Blogger_636831848164755309.jpg
By: Tintuk Tomin

How to Activate Settings From Code in Odoo

Technical

We are very much familiar with activating different options in odoo by enabling some options in the settings page. For example activate the product variants, asset management,  etc. To enable the product variants we need to go to the inventory settings and put the tick in the product variants. For asset management, we need to go to the invoice settings and put the tick in the asset management. There are some situations where we need to activate these settings for some purpose using the code. This blog will help you to manage this.

Let's have a look at the settings.

In settings, there will be a heading and under that heading, there will be different options. Mostly all these options will be a boolean field. To enable the settings we are putting a tick in these options, saying in technical language we are making these boolean fields true.

So make these boolean fields true. For that first, we need to know the field name and the model.

The model of the settings is "res.config.settings"

We are creating a boolean field in the above model to manage the settings.

class SettingsBoolean(models.Model):
   _inherit = "res.config.settings"
   enable_settings = fields.Many2one("Enable Settings")

Now let's take an example of an asset. To enable the asset management in odoo you need to enable it in the settings.
Accounting -> Configuration -> Settings -> Asset Management

In settings, under automated entries, you will see the option for asset management.

So to enable this feature(asset management) you need to tick this option.

What we are going to do is to enable this feature using code.

First, we need to identify the field name. For that enable the debugging mode. And keep the mouse pointer just above the option. Then you will be able to see a popup just like in the above screenshot. Here you will get to know the field name of that particular field.

Now in our case, the field name is “module_account_asset

Now we need to write an XML code to make the value of this boolean field to 1.

<record model="res.config.settings" id="res_config_settings_asset">
<field name="module_account_asset" eval="1"/>
</record>

In the above code model is the name of the model. Ie “res.config.settings"
Then we need to give an id for the record. Here,  id="res_config_settings_asset
After that, we are setting the value of that particular boolean field as 1.

Now we need to write a function to run this record.

<function model="res.config.settings" name="execute">
<value eval="[ref('res_config_settings_asset')]"/>
<value eval="{}"/>
</function>

So by the above code in the XML and updating the module you can enable the settings.
Hope this blog finds helpful.



cybrosys youtube

Comments

0


Leave a comment

 
Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

London

Cybrosys Limited
Alpha House,
100 Borough High Street, London,
SE1 1LB, United Kingdom

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message