[FIX] base: add ir_config_parameter with default value
Steps to reproduce:
- install sale_management module;
- go to settings of sale_management and check "Automatic invoice" parameter;
- in debug mode, we can see the template selected (do not change it);
- save the settings;
(This is just one example)
Issue:
The parameter is not added to the "ir_config_parameter" table.
Cause:
The improvement which consists in comparing the settings which one wishes to record with those which already exist in order to set the parameters which are different creates a problem.
Indeed, the current settings are retrieved directly from the model with their default value if there is one.
These are the values that will be used for the comparison.
Because of this, when we want to save a parameter which is set to its default value (on first save), the logic will not notice a difference.
Therefore, the parameter will not be saved in the "ir_config_parameter" table.
Consequence:
In the code, when we wanted to look up the value of a parameter, if it is not saved, we use its default value instead of saving it with its default value.
Example:
```
field_example = fields.Integer(string='Example', default=1000, config_parameter='model.field_example')
value_field_example = params.get_param('model.field_example', default=1000)
```
The default value is repeated.
Solution:
To know whether or not we add a new parameter in the "ir_config_parameter" table, we must look at what already exists in the table and not in the settings defined in the model.
opw-3057306
closes odoo/odoo#106188
X-original-commit: d881dfaaa163b409a94494e35afa2cbda7cf2aa2
Related: odoo/enterprise#34258
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
committed by
Victor Feyens
parent
2415338d46
commit
a64bd4ba52
@@ -559,12 +559,8 @@ class ResConfigSettings(models.TransientModel, ResConfigModuleInstallationMixin)
|
||||
for name, icp in classified['config']:
|
||||
field = self._fields[name]
|
||||
value = self[name]
|
||||
current_value = current_settings[name]
|
||||
if not field.relational and value == current_value:
|
||||
# pre-check before the value is formatted
|
||||
# because the values in current_settings are
|
||||
# in field format, not in str/False parameter format
|
||||
continue
|
||||
current_value = IrConfigParameter.get_param(icp)
|
||||
|
||||
if field.type == 'char':
|
||||
# storing developer keys as ir.config_parameter may lead to nasty
|
||||
# bugs when users leave spaces around them
|
||||
@@ -575,7 +571,7 @@ class ResConfigSettings(models.TransientModel, ResConfigModuleInstallationMixin)
|
||||
# value is a (possibly empty) recordset
|
||||
value = value.id
|
||||
|
||||
if current_value == value:
|
||||
if current_value == str(value) or current_value == value:
|
||||
continue
|
||||
IrConfigParameter.set_param(icp, value)
|
||||
|
||||
|
||||
@@ -27,3 +27,4 @@ access_ttu_product,access_ttu_product,model_ttu_product,base.group_user,1,0,0,0
|
||||
access_ttu_root,access_ttu_root,model_ttu_root,base.group_user,1,0,0,0
|
||||
access_ttu_child,access_ttu_child,model_ttu_child,base.group_user,1,0,0,0
|
||||
access_ttu_grandchild,access_ttu_grandchild,model_ttu_grandchild,base.group_user,1,0,0,0
|
||||
access_res_config_test,access_res_config_test,test_testing_utilities.model_res_config_test,base.group_user,1,0,0,0
|
||||
|
||||
|
@@ -314,3 +314,18 @@ class O2MChangesChildrenLines(models.Model):
|
||||
parent_id = fields.Many2one('o2m_changes_children')
|
||||
v = fields.Integer()
|
||||
vv = fields.Integer()
|
||||
|
||||
class ResConfigTest(models.Model):
|
||||
_inherit = 'res.config.settings'
|
||||
|
||||
_name = 'res.config.test'
|
||||
_description = 'Config test'
|
||||
|
||||
param1 = fields.Integer(
|
||||
string='Test parameter 1',
|
||||
config_parameter='resConfigTest.parameter1',
|
||||
default=1000)
|
||||
|
||||
param2 = fields.Many2one(
|
||||
'res.config',
|
||||
config_parameter="resConfigTest.parameter2")
|
||||
|
||||
@@ -3,3 +3,4 @@ from . import test_methods
|
||||
from . import test_lxml
|
||||
from . import test_form_impl
|
||||
from . import test_xml_tools
|
||||
from . import test_res_config
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
from unittest.mock import patch
|
||||
from odoo.tests.common import TransactionCase
|
||||
|
||||
class TestResConfig(TransactionCase):
|
||||
|
||||
def test_00_add_parameter_with_default_value(self):
|
||||
""" Check if parameters with a default value are saved in the ir_config_parameter table """
|
||||
|
||||
self.env['res.config.test'].create({}).execute()
|
||||
self.assertEqual(self.env['ir.config_parameter'].sudo().get_param('resConfigTest.parameter1'), str(1000),
|
||||
"The parameter is not saved with its default value")
|
||||
|
||||
with patch('odoo.addons.base.models.ir_config_parameter.IrConfigParameter.set_param') as set_param_mock:
|
||||
self.env['res.config.test'].create({}).execute()
|
||||
|
||||
set_param_mock.assert_not_called()
|
||||
Reference in New Issue
Block a user