Skip to Content
Menu
This question has been flagged
2 Replies
4412 Views

Hi,

I'm having trouble while saving my field [margin_control]. I don't know where is the error, because it's running as if its going to save the value.

Here my functions

@api.model
def get_default_margin_control(self, fields):
res = super(MarginControlSettings, self).get_values()
ICPSudo = self.env['ir.config_parameter'].sudo()
sale_margin_control = ICPSudo.get_param('sale.margin_control')
res.update(
margin_control=float(sale_margin_control),
)
return res
@api.one
def set_margin_control(self):
super(MarginControlSettings, self).set_values()
self.env['ir.config_parameter'].set_param('sale.margin_control', float(self.margin_control)) 

This does not give any error but also does not run. The 'margin_control' field placed at Sale->Configuration->Settings page, under Pricing section, next to Margins field. How can I save the value(created by me.)?


Avatar
Discard
Best Answer

 Hi,

   you can use get_values(),set_values() functions for this.just try this

  

@api.model
def get_values(self):
res = super(ResConfigSettings, self).get_values()
params = self.env['ir.config_parameter'].sudo()
sale_margin_control = params.get_param('sale_margin_control', default=False)
res.update(
sale_margin_control=int(sale_margin_control)

)
return res

@api.multi
def set_values(self):
super(ResConfigSettings, self).set_values()
self.env['ir.config_parameter'].sudo().set_param("sale_margin_control",
self.sale_margin_control)

      

                   you need to make sufficient change according to your requirement

Avatar
Discard

I have the same issue but this functions do not work with Many2one field ?? Gives this error : Database fetch misses ids (('35',)) and has extra ids ((35,)), may be caused by a type incoherence in a previous request ...

Author Best Answer

Thanks that worked perfectly.

Avatar
Discard