From e57df47eddccdcabc70dd42ae563164364de8e53 Mon Sep 17 00:00:00 2001 From: Quentin Groulard Date: Thu, 2 Apr 2026 11:48:41 +0200 Subject: [PATCH 1/2] [IMP] server_environment: Preserve not env managed data 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. --- server_environment/models/server_env_mixin.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/server_environment/models/server_env_mixin.py b/server_environment/models/server_env_mixin.py index f5cfa1c8c..e45052829 100644 --- a/server_environment/models/server_env_mixin.py +++ b/server_environment/models/server_env_mixin.py @@ -425,3 +425,31 @@ def _setup_base(self): self._server_env_transform_field_to_read_from_env(field) self._server_env_add_is_editable_field(field) return + + @api.model + def _preserve_not_env_managed_data(self, field_name_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. + """ + self.env.cr.execute(f"SELECT * FROM {self._table}") + for row in self.env.cr.dictfetchall(): + record = ( + self.env[self._name] + .with_context(active_test=False) + .search([("id", "=", row["id"])]) + ) + if record: + record_values = {} + for field_name in field_name_list: + if field_name in row: + record_values[field_name] = row[field_name] + record.update(record_values) From 73641ea136589968b8dbfc9456c7a2d37206c509 Mon Sep 17 00:00:00 2001 From: Quentin Groulard Date: Thu, 2 Apr 2026 15:23:54 +0200 Subject: [PATCH 2/2] [FIX] mail_environment: Add migration script for field "smtp_authentication" 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. --- mail_environment/migrations/16.0.1.0.3/post-migration.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 mail_environment/migrations/16.0.1.0.3/post-migration.py diff --git a/mail_environment/migrations/16.0.1.0.3/post-migration.py b/mail_environment/migrations/16.0.1.0.3/post-migration.py new file mode 100644 index 000000000..523be970a --- /dev/null +++ b/mail_environment/migrations/16.0.1.0.3/post-migration.py @@ -0,0 +1,9 @@ +# Copyright 2026 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + env["ir.mail_server"]._preserve_not_env_managed_data(["smtp_authentication"])