Skip to Content
Menu
This question has been flagged
3 Replies
19704 Views

Hi,

I have stored some value for many2one field in res.config.settings,how can i access that value from a different model.

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

  partner_id = fields.Many2one('res.partner',string='Partner')

Thanks in advance

Avatar
Discard
Best Answer

Hi,

Use following code for accessing a field value which is stored in settings

settings_partner = self.env['ir.config_parameter'].sudo().get_param('partner_id') or False

Regards

Avatar
Discard

this method always returning False.

This is not right. res.config.settings is not ir.config_parameter. That is why we always get null values.

Best Answer

do you used set and get values to store values ? 

if not 

you should do it like that 

def set_values(self):
res =
super(ResConfigSettingsdurar, self).set_values()
self.env['ir.config_parameter'].set_param('yourmodelname.partner_id', self.partner_id)
return res

@api.model
def get_values(self):
res = super(ResConfigSettingsdurar, self).get_values()
ICPSudo = self.env['ir.config_parameter'].sudo()
   partner_parameter = ICPSudo.get_param('yourmodelname.partner_id')
res.update(
        
partner_id=partner_parameter,
)
return res

then

you should get it in yourmodel bu this way

def get_partner(self):
partner_from_seeting =
self.env['ir.config_parameter'].sudo().get_param('yourmodelname.partner_id') or False
return partner_form_setting
Avatar
Discard

how I can hide button that i have created in sales quotation based on boolean field value from ir.config.settings. I have added new boolean field in settings

Related Posts Replies Views Activity
3
Jan 23
4895
2
Jan 23
951
0
Aug 22
970
3
Nov 20
3182
1
Jul 20
2438