From 1c1e751f983537775f248840ff3517a30d8295d2 Mon Sep 17 00:00:00 2001 From: Quentin Groulard Date: Thu, 2 Apr 2026 11:48:41 +0200 Subject: [PATCH 1/3] [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 2bf47b0c7..dcb28ab45 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 55fcfaf89ec02e05e2955ece18069dae8198582a Mon Sep 17 00:00:00 2001 From: Quentin Groulard Date: Thu, 2 Apr 2026 15:23:54 +0200 Subject: [PATCH 2/3] [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/__manifest__.py | 2 +- mail_environment/migrations/17.0.1.0.2/post-migration.py | 9 +++++++++ mail_environment/static/description/index.html | 2 +- server_environment/__manifest__.py | 2 +- server_environment/static/description/index.html | 2 +- 5 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 mail_environment/migrations/17.0.1.0.2/post-migration.py diff --git a/mail_environment/__manifest__.py b/mail_environment/__manifest__.py index b20d02d35..7f3f8c3ec 100644 --- a/mail_environment/__manifest__.py +++ b/mail_environment/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Mail configuration with server_environment", - "version": "17.0.1.0.1", + "version": "17.0.1.0.2", "category": "Tools", "summary": "Configure mail servers with server_environment_files", "author": "Camptocamp, Odoo Community Association (OCA)", diff --git a/mail_environment/migrations/17.0.1.0.2/post-migration.py b/mail_environment/migrations/17.0.1.0.2/post-migration.py new file mode 100644 index 000000000..523be970a --- /dev/null +++ b/mail_environment/migrations/17.0.1.0.2/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"]) diff --git a/mail_environment/static/description/index.html b/mail_environment/static/description/index.html index 0f434f77e..52b90a641 100644 --- a/mail_environment/static/description/index.html +++ b/mail_environment/static/description/index.html @@ -3,7 +3,7 @@ -README.rst +Mail configuration with server_environment