How to save and load module configuration in Odoo

Finding a Solution

Often a custom Odoo module needs some parameters to run. However, [my previous analysis of Odoo’s own implementation] ( doesn’t give me an obvious answer on how to implement a configuration function for a custom module. Nonetheless, the analysis helps me to evaluate answers I found online today.

Basically, there are three methods to implement module configuration:

  • Using a regular form view to save/read configuration data. This is suggested by [an Odoo forum thread] ( Using this method, I failed to show an Edit and Cancel button and there is no clear way to customize a form view for the purpose.
  • Using a set_xxx method and a get_default_xxx method in a model that inherits ‘res.config.settings’ to save and read a configuration parameter. I found this idea in [an Odoo forum post] ( It might be good for one or two fields because it requires a field to be defined in both a model for the configuration UI and a model to manage permanent data. The model for the configuration UI is based on a transient model and cannot be used to permanently store module settings.
  • Using default_xxx column in a model that inherits ‘res.config.settings’. I thought about this idea and was glad to know that somebody had the similar thought. This method is a simple one because the ‘res.config.settings’ implements the function to store and read any column whose name starts with default_ in the ‘ir.value’ model. To get the configuration settings, one need to read ir_value records that match the key, name, and model column values. The key has a fixed value of ‘default’. The name is the ‘xxx’ field. the model is define in the default_model attribute in the ‘default_xxx’ column.

Open Issues

Though simple, the ‘default_xxx’ method has some drawbacks that could be improved in the future:

  • It puts settings in ‘ir.value’ table but doesn’t remove those settings when a module is uninstalled. I need to find a simple way to clean the data during uninstallation.
  • By default, one needs to be the Odoo administrator or a member of ‘base.grouperpmanager’ to configure a custom module. Extra code is needed to change this requirement.
  • Configuration data is stored as clear text. This might be a security issue.

Implementation Example

The implementation turns out very simple. To follow the Odoo convention, we name our view as ‘res_config_view.xml’ and our model as ‘’.

The menu and view definitions are as the following:

<?xml version="1.0" encoding="UTF-8"?>
        <record id="view_amdeb_amazon_configuration"
            <field name="name">amdeb amazon settings</field>
            <field name="model"></field>

            <field name="arch" type="xml">
                <form string="Amazon Integration Configuration"
                            <button string="Apply"
                                    class="oe_highlight" />
                            <button string="Cancel"
                                    class="oe_link" />

                        <group string="Account Settings">
                            <field name="default_account_id" />
                            <field name="default_access_key" />
                            <field name="default_secrete_key" />

                        <group string="Integration Settings">
                            <field name="default_integration_interval" />
                            <field name="default_automatic_flag" />

        <record id="action_amdeb_amazon_configuration"
            <field name="name">Amdeb Amazon Configuration</field>
            <field name="res_model"></field>
            <field name="view_mode">form</field>
            <field name="target">inline</field>

        <menuitem id="menu_amdeb_amazon_config"
                  name="Amazon Settings"
                  action="action_amdeb_amazon_configuration" />

The model is define as the following:

# -*- coding: utf-8 -*-

from openerp import models, fields

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

    default_account_id = fields.Char(
        string='Account Id',
        help="The Amazon Merchant Identifier",

    default_access_key = fields.Char(
        string='Access Key',
        help="The Amazon Marketplace Web Service (MWS) access key",

    default_secrete_key = fields.Char(
        string='Secret Key',
        help="The Amazon Marketplace Web Service (MWS) secret key",

    default_integration_interval = fields.Integer(
        string='Integration Interval (seconds)',
        help="The minimum interval for Amazon automatic integration",

    default_automatic_flag = fields.Boolean(
        string='Automatic Integration',
        help="Enable or disable Amazon automatic integration",
Written on October 17, 2014