# -*- coding: utf-8 -*-
import logging
from odoo import api, fields, models, _

_logger = logging.getLogger(__name__)


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

    bfm_url = fields.Selection(
        [("https://bfm.cs.jikimo.com", "开发环境(https://bfm.cs.jikimo.com)"),
         ("https://bfm.r.jikimo.com", "测试环境(https://bfm.r.jikimo.com)"),
         # ("正式环境", "https://bfm.jikimo.com")], string='bfm环境', store=True)
         ("https://bfm.jikimo.com", "正式环境(https://bfm.jikimo.com)")], string='bfm环境', store=True)

    @api.model
    def get_values(self):
        """
        重载获取参数的方法，参数都存在系统参数中
        :return:
        """
        values = super(ResBFMConfigSettings, self).get_values()
        config = self.env['ir.config_parameter'].sudo()
        bfm_url = config.get_param('bfm_url', default='')

        values.update(
            bfm_url=bfm_url,
        )
        return values

    def set_values(self):
        super(ResBFMConfigSettings, self).set_values()
        ir_config = self.env['ir.config_parameter'].sudo()
        ir_config.set_param("bfm_url", self.bfm_url or "")

