Hello,
I created several fields for res.config.settings and added them to the view. For Float fields, I was able to configure the ability to enter and save new values, and also figured out how to set default values.
However, I do not know how to make sure that the Boolean field is saved when changing and clicking Save.
class ResConfigSettings(models.TransientModel):_inherit = 'res.config.settings'
field_name = fields.Float(string='Im float field')
boolean_field = fields.Boolean(string='I want the checkmark set here to be saved')
For enter and save new values in Float fields I use:
def set_values(self):res = super(ResConfigSettings, self).set_values()self.env['ir.config_parameter'].set_param('module_name.field_name', self.field_name)return res
@api.modeldef get_values(self):res = super(ResConfigSettings, self).get_values()ICPSudo = self.env['ir.config_parameter'].sudo()res.update(field_name= ICPSudo.get_param('module_name.field_name'),)return res
Do you know how you can save the state of a Boolean field?
I tried to make a new class with a Boolean field and add it from there, but this field became not clickable
class Settings_holder(models.Model):
_name = 'module_name.settings_holder'
field_name= fields.Boolean('Hello Odoo!')
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
test_field = fields.Many2one('module_name.settings_holder', string='hmmmm')
covid_tax = fields.Boolean(related='test_field.field_name')
I forgot the comma when listing in res.update() inside get_values(). Don't forget the commas :D
From Odoo 17.0 You can do like this
sale_invoice_id = fields.Many2one('sale.order', string='Sale Invoice', config_parameter='current_module_name.sale_invoice_id')
You can use this for all type field in v17.0 (Note:- Only for setting value in res.config.setting')