odoo12 ResConfigSettings source code analysis two

Analyze the beginning of config_

hasattr(field, 'config_parameter'):

IrConfigParameter = self.env['ir.config_parameter'].sudo()

value = IrConfigParameter.get_param(icp, field.default(self) if field.default else False)

You can see that the value is taken through the ir.default database

Then look at the database

It is a key-value pair. And ir.config_parameter wrote a get_param to facilitate obtaining the value

    @api.model
    def get_param(self, key, default=False):
        """Retrieve the value for a given key.

        :param string key: The key of the parameter value to retrieve.
        :param string default: default value if parameter is missing.
        :return: The value of the parameter, or ``default`` if it does not exist.
        :rtype: string
        """
        return self._get_param(key) or default

    @api.model
    @ormcache('self._uid', 'key')
    def _get_param(self, key):
        params = self.search_read([('key', '=', key)], fields=['value'], limit=1)
        return params[0]['value'] if params else None

So that other places only need

# data = order.env['ir.config_parameter'].sudo().search([('key','=','zhy.name_edit')]).key
data = order.env['ir.config_parameter'].sudo().get_param('zhy.name_edit')

Both ways can be obtained

Guess you like

Origin blog.csdn.net/sr50611/article/details/100077540