Skip to main content

Create, Store, and Get Setting in res.config.settings in Odoo

There are many methods to store and retrieve data in Odoo. The most common is to use the ORM (Object Relational Mapping) system. However, sometimes you need to access data that is in a special model. In these cases, you can use res.config.settings.

Odoo makes it simple to create system’s settings. These settings can be found in Settings > General Settings.

Model:

class ResConfigSettings(models.TransientModel):
    _inherit = 'res.config.settings'

    custom_field = fields.Char('Custom Field', config_parameter='my_module.custom_field')    

Create an xml file for UI as views_res_config_settings.xml (remember to include this file in the manifest file):

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="res_config_settings_view_form" model="ir.ui.view">
            <field name="name">res.config.settings.view.form.inherit</field>
            <field name="model">res.config.settings</field>
            <field name="priority" eval="99"/>
            <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="My Module" string="My Module"
                         data-key="my_module">
                        <h2>My Module Settings</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">
                                    <label string="Email From" for="custom_field"/>
                                    <div class="text-muted">Store custom data</div>
                                    <field name="custom_emails" widget="text"/>
                                </div>
                            </div>

                        </div>

                    </div>
                </xpath>
            </field>
        </record>
    </data>
</odoo>

By continuing to use the site, you agree to the use of cookies.