strike_noir
strike_noir

Reputation: 4174

Set Odoo's config settings on module installation

I have made my custom config settings in Odoo using models.TransientModel with implementing the get_default and the set function. The way I do it is the same like is shown in the answer for this question

Set and get store data Odoo with TransientModel

When the module installed, the settings is empty. How to have a default value of that config settings on install?

I've tried using the init function.

def init(self, cr):
    config = self.pool.get("ir.config.parameter")
    config_value = {
        "value": "[email protected]",
        "key": "myapplication.email_address"
    }
    config.create(cr, uid, config_value, context=None)

It didn't work.

Upvotes: 2

Views: 1302

Answers (1)

Heroic
Heroic

Reputation: 980

You can do it by getter and setter method as below :

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

    key = fields.Char()
    value = fields.Char()

    @api.model
    def get_default_key_values(self, fields):
        return {
            'key': "myapplication.email_address",
            'value': "[email protected]",
        }

    @api.multi
    def set_key_values(self):
       self.ensure_one()
       ICP = self.env['ir.config_parameter']
       ICP.set_param('key', self.key)
       ICP.set_param('value', self.value)

Upvotes: 2

Related Questions