Hi!
I seem to be in a struggle to find the way to achieve one simple task. So far, reading the sources of stock modules, I have created a module for res_config_settings:
# -*- coding: utf-8 -*-
from odoo import fields, models
from decimal import Decimal
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
exchange_rate = fields.Float('USD/RUB', digits=(2, 2), default=69.0)
tid_en = fields.Char('Tracking ID for EN', default='UA-XXXXXXXX-1')
tid_ru = fields.Char('Tracking ID for RU', default='UA-XXXXXXXX-3')
def get_values(self):
res = super(ResConfigSettings, self).get_values()
res.update(
exchange_rate=self.env['ir.config_parameter'].sudo().get_param('crm_patch.exchange_rate'),
tid_en=self.env['ir.config_parameter'].sudo().get_param('crm_patch.tid_en'),
tid_ru=self.env['ir.config_parameter'].sudo().get_param('crm_patch.tid_ru')
)
return res
def set_values(self):
super(ResConfigSettings, self).set_values()
self.env['ir.config_parameter'].sudo().set_param('crm_patch.exchange_rate',
Decimal(self.exchange_rate))
self.env['ir.config_parameter'].sudo().set_param('crm_patch.tid_en', self.tid_en)
self.env['ir.config_parameter'].sudo().set_param('crm_patch.tid_ru', self.tid_ru)
What am I trying to achieve is to have these defaults in another module:
def _get_tid(self, x_site_lang):
if x_site_lang == 'ru':
return self.env['ir.config_parameter'].sudo().get_param('crm_patch.tid_ru')
else:
return self.env['ir.config_parameter'].sudo().get_param('crm_patch.tid_en')
So I guess I have to make some way to set ir.config_parameters on module installation once, if they are not present already?
Could you please help me with the task?