Skip to Content
Menu
This question has been flagged
1 Reply
3326 Views

Hi,


I've placed a field.Selection called Behavior on Odoo Settings and I want the user to be able to select between three different speeds.


The field is working fine, but the speed values don't get stored or loaded properly.


I really don't know how to make the functions get_values and set_values work when using field.Selection


Can anyone help me?


With the code that I came up with the values get "stored" only until I refresh the page:

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

behavior = fields.Selection(string="Select the behavior",
selection=[('fast', 'As fast as possible'),
('normal', 'Normal speed'),
('slow', 'The slowest')],
required=False, default='fast')

def set_values(self):
super(ResConfigSettings, self).set_values()
self.env['ir.config_parameter'].sudo().set_param('my_app.behavior', self.behavior)
return

@api.model
def get_values(self):
res = super(ResConfigSettings, self).get_values()
res.update(
behavior = self.env['ir.config_parameter'].sudo().set_param('my_app.behavior', self.behavior) or "normal"
)
return res



Avatar
Discard
Best Answer

Hi,

No Need to set get and set values. Just add a config parameter for the field
here is an example

product_volume_volume_in_cubic_feet = fields.Selection([
('0', 'Cubic Meters'),
('1', 'Cubic Feet'),], 'Volume unit of measure', config_parameter='product.volume_in_cubic_feet', default='0')

Like this change your field definition to

behavior = fields.Selection(string="Select the behavior",
selection=[('fast', 'As fast as possible'),
('normal', 'Normal speed'),
('slow', 'The slowest')], required=False, default='fast', config_parameter='your_custom_module_name.behaviour')

And to access that field value use this

self.env['ir.config_parameter'].sudo().get_param('your_custom_module_name.behaviour')

Regards

Avatar
Discard