Enable Dark Mode!
how-to-install-or-uninstall-a-module-by-enabling-boolean-field-in-the-settings.jpg
By: Aswathi C

How to Install or Uninstall a Module by Enabling Boolean Field in the Settings

Technical

 To install a module in Odoo, you normally go to the app's menu on Odoo and install it from there. There is also another option to install or uninstall modules directly from the settings via a boolean field. In some cases, you want to use some features only if needed.  In such cases, we can use the feature of installing and uninstalling modules from settings. You add those features on a separate module and use them when needed. 

This blog explains how a module is installed or uninstalled by enabling or disabling a boolean field in settings.

Step1:

Create a new python file res_config_settings.py to add a boolean field on res.config.settings. This boolean field is used to install and uninstall a particular module. The basic syntax for the boolean field must be in the format module_module_name .

Here module name will be the technical name of the module to be installed when enabling this boolean field. We can find many examples from the Odoo addons themselves.

For example, here, we can install the sales module when enabling a boolean field on settings. Below is the code for this.

class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
module_sale_management = fields.Boolean(string="Install sales module")

In this example, the module name is sale_management . So here, we are going to install and uninstall the sales module by enabling and disabling the boolean field, respectively.

Step 2:

Create an XML view res_config_settings_view.xml to add the field on settings. We can add the module_sale_management field on settings by using the following code on the created XML view.

<record id="sale_module_install_res_config_settings_view_form" model="ir.ui.view">
<field name="name">settings.install.sale.module</field>
<field name="model">res.config.settings</field>
<field name="priority" eval="91"/>
<field name="inherit_id" ref="base.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[hasclass('settings')]" position="inside">
<div class="app_settings_block" data-string="Install sale module" id="sale_module_install_settings"
string="Install module"
>
<h2>Sale Module Install</h2>
<div class="row mt16 o_settings_container">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane"/>
<div class="o_setting_right_pane">
<div class="text-muted content-group mt16">
<label string="Install sale" for="module_sale_management" class="col-lg-3 o_light_label"/>
<field name="module_sale_management" class="text-center oe_inline"/>
</div>
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>

The below image shows the result of adding a boolean field in settings.

how-to-install-or-uninstall-a-module-by-enabling-boolean-field-in-the-settings-cybrosys

Here you can see that before enabling the boolean field the app sales are not installed. You can see it in the image below.

how-to-install-or-uninstall-a-module-by-enabling-boolean-field-in-the-settings-cybrosys

After enabling the boolean field,  the app sales will be installed on Odoo. The below image shows the result of this.

how-to-install-or-uninstall-a-module-by-enabling-boolean-field-in-the-settings-cybrosys

Also if you don’t want the feature inside this module (sales) you can just uninstall the module by disabling the boolean field. Then the features inside that module will be removed. On disabling the boolean field you will get a message like “uninstalling these modules will uninstall the following modules”.If you want to uninstall those modules you can click on the ‘OK’ button.

Similarly, you can also install custom modules like the above. For example, if you want to install a custom module named ‘budget_limit’ from settings, you can create a boolean field as module_budget_limit on res.config.settings model. And then, you can add the field module_budget_limit to the XML view of res.config.settings model. Now you can install or uninstall the custom module ’budget_limit’ by enabling or disabling the above field.

Hope you all got the basic idea of installing and uninstalling modules from settings by using a boolean field. You can refer to the following link for the demonstration video 


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment

 


whatsapp_icon
location

Calicut

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

location

Kochi

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

location

Bangalore

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

Send Us A Message