Wednesday, January 27, 2021

edit odoo setting

 


In this blog we will explain how to edit setting object and view in odoo to add new setting so let us give an example

let us say that we want to add three fields to odoo setting (res.config.settings) object so we have to know some important things

  • res.config.settings is Transient Model , so it will not save data
  • we have specific way to save all fields one the model
  • relational fields have different way to make them savable at setting 
Eg : 
we want to add name field which is char field , age which is integer field and account_id with is many2one field so 

first define the fields in the class as bellow

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

    name = fields.Char(string="Name")
    age = fields.Integer(string="Age")
    account_id = fields.Many2one('account.account', string="Account")

second make the non relational fields savable by adding the methods bellow 
 
@api.model
    def get_values(self):
        res = super(ResConfigSettings, self).get_values()
        ICPSudo = self.env['ir.config_parameter'].sudo()
        name = ICPSudo.get_param('module_name.name')
        res.update(name=name)
        age = ICPSudo.get_param('module_name.age')
        res.update(age=age) 
 
 
def set_values(self):
        super(ResConfigSettings, self).set_values()
        for rec in self:
            ICPSudo = rec.env['ir.config_parameter'].sudo()
            ICPSudo.set_param('module_name.name',str(rec.name))
            ICPSudo.set_param('
module_name.age',rec.age) 
 
Third make relational fields savable through 2 steps 
 
1/ inherit res.company object and add same relational fields inside it just as

class Company(models.Model):
    _inherit = "res.company"
 
    account_id = fields.Many2one('account.account', string="Account")
 
2/ edit the relational fields that you had defined in the setting object by makeing them related fields just as 
 
account_id = fields.Many2one('account.account', string="Account", related="company_id.account_id") 

No comments:

Post a Comment

Odoo Invoice Qr code issues

There are two main issues must of us facing with the QR code in Odoo invoice & these issues are 1/ QR code displayed as broken image w...