[18.0][IMP] server_environment: Preserve not env managed data - #264
Conversation
65f05d6 to
f772104
Compare
| return | ||
|
|
||
| @api.model | ||
| def preserve_not_env_managed_data(self): |
There was a problem hiding this comment.
| def preserve_not_env_managed_data(self): | |
| def _preserve_not_env_managed_data(self): |
If this is to be used in migration scripts, maybe it's safer to pass the list of fields/columns to handle explicitly?
f772104 to
51885bd
Compare
Helper function typically used for hooks and migration scripts. Restores database values for fields transitioning to 'server env managed'. When a field is defined as managed by the server environment, Odoo ignores the value stored in the database, prioritizing the environment configuration instead. If no environment configuration exists, the field may effectively lose its previous value. This method forces to 'persist' these values if they are not explicitly overridden by the current environment configuration.
51885bd to
7bec03f
Compare
…cation" To preserve the value of field "smtp_authentication" if we don't set it from the environment. Which may happen to anyone updating the sources of mail_environment for its project.
|
/ocabot merge patch |
|
This PR looks fantastic, let's merge it! |
|
Congratulations, your PR was merged at 45c5c39. Thanks a lot for contributing to OCA. ❤️ |
| record_values = {} | ||
| for field_name in field_name_list: | ||
| if field_name in row: | ||
| record_values[field_name] = row[field_name] |
There was a problem hiding this comment.
To be complete, this may need conversion based on the field type. But this is good enough for practical use cases of server env fields.
|
I'm working on the issue: Therefore, I've opened several PR's to remove For example: Only on that v18 split PR the current PR issue was raised in the tests and the logical fix was to add a Why do we need this hook there: Before this split (
When the environment module is installed on an existing database, the old value is still present in the original SQL column, but it is not automatically copied into The question which now comes to me:
From what I see it impacts all the versions. As for now we've decided to cover
@lmignon @sbidoul @etobella @rousseldenis @ivantodorovich WDYT? |
Heavily inspired from #219, thank you @rven for your contribution.
I wanted to make @rven script more generic because this problem potentially happens every time we add the
server.env.mixinto a model or when we add fields to the_server_env_fields()list.Helper function typically used for hooks and migration scripts.
Restores database values for fields transitioning to 'server env managed'.
When a field is defined as managed by the server environment, Odoo ignores the value stored in the database, prioritizing the environment configuration instead. If no environment configuration exists, the field may effectively lose its previous value.
This method forces to 'persist' these values if they are not explicitly overridden by the current environment configuration.