[FIX] base: add ir_config_parameter with default value - #105991
Conversation
8fd15c3 to
11ab6c8
Compare
adwid
left a comment
There was a problem hiding this comment.
lgtm
It may worth adding a test ?
As explained by the description, since [1], we only apply the settings that have changed. To do so, we compare the old and new res.config.settings. Moreover, in the code, we use the settings classified as config through the model ir.config.parameter, we don't read such settings field directly. For instance:
odoo/addons/sale/models/res_config_settings.py
Lines 58 to 64 in 2daa9a1
Therefore, to know if a config setting has changed, we should not use the field on res.config.settings because its value could come from its default attribute and because, as shown above, this is not how a config setting is read/used. We should rather read the associated ir.config.parameter
[1] 76982c0
There was a problem hiding this comment.
seems to make sense
side note, there is several cases where this would not be an issue:
-
if when we did get_param in the code using the ir.config_parameter for real, we used the same default value
-
if we set the ir.config_parameter to the same default value at module installation in data.
it's possible that this is the current intention of how things are done.
But with the difference between 15.0 (where we would write the ir.config_parameter in any case) and saas-15.2 this change make sense to me for the continuity of the behavior.
11ab6c8 to
cba0350
Compare
Feyensv
left a comment
There was a problem hiding this comment.
It seems that we are losing part of my performance improvement with this change, but this seems to be the right fix considering the problem 👍.
As Adrien suggested, a test would indeed be nice to make sure the behavior is still supported in the future ;).
side note, there is several cases where this would not be an issue:
- if when we did get_param in the code using the ir.config_parameter for real, we used the same default value
- if we set the ir.config_parameter to the same default value at module installation in data.
it's possible that this is the current intention of how things are done.
More like we didn't think of those cases that are wrongly implemented :D.
Those default values in the settings (but not in the code) are strange, as it means you could open the settings, save without modifying anything, and some parameters would have been modified (when you thought you didn't change anything).
0f8f493 to
7479b96
Compare
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
7479b96 to
a804076
Compare
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 #105991
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>

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