Search code examples
odooodoo-9

Set and get default in config file odoo


In custom module I'm inherit purchase.config.settings and add two field. How add below field set_dafault_value and get_default_value after open config file need load data in my field from database.

class PurchaseConfigSettings(models.TransientModel):
_name = 'purchase.config.settings'
_inherit = 'purchase.config.settings'

purchase_reminder = fields.Selection([
                ('one_day', 'One day'),
                ('two_day', 'Two day'),
                ],default='one_day',string='Day')
purchase_email = fields.Char(string='Email')

@api.model
def get_default_purchase_reminder(self, fields):
    #???

@api.multi
def set_default_purchase_reminder(self):
    #???

Solution

  • The answer is:

    @api.model
    def get_default_purchase_reminder(self, fields):
        # load your value and return it in a dict, you can load it from params (see below) or from another non Transient model
        return {'purchase_reminder': 'value1', 'purchase_email' : 'value2'}
    
    @api.multi
    def set_default_purchase_reminder(self):
        # save your value either in a non transsient model or on params like this:
        for rec in self:
            ir_config_parameter = self.env['ir.config_parameter']
            ir_config_parameter.set_param('purchase_reminder', rec.purchase_reminder)
            ir_config_parameter.set_param('purchase_email', rec.purchase_email)