From 5f4a582ccd9c3a934b9d669ac083eeae7d590e53 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 fa83ae642..9e38ae098 100644 --- a/server_environment/models/server_env_mixin.py +++ b/server_environment/models/server_env_mixin.py @@ -423,3 +423,31 @@ def _post_model_setup__(self): self._server_env_transform_field_to_read_from_env(field) self._server_env_add_is_editable_field(field) return super()._post_model_setup__() + + @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 c025687dbc8d6ee17f4ff95812ec5074d6ca6b74 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/__manifest__.py | 2 +- mail_environment/migrations/19.0.1.1.1/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/19.0.1.1.1/post-migration.py diff --git a/mail_environment/__manifest__.py b/mail_environment/__manifest__.py index 33e466634..7abedb803 100644 --- a/mail_environment/__manifest__.py +++ b/mail_environment/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Mail configuration with server_environment", - "version": "19.0.1.1.0", + "version": "19.0.1.1.1", "category": "Tools", "summary": "Configure mail servers with server_environment_files", "author": "Camptocamp, Odoo Community Association (OCA)", diff --git a/mail_environment/migrations/19.0.1.1.1/post-migration.py b/mail_environment/migrations/19.0.1.1.1/post-migration.py new file mode 100644 index 000000000..523be970a --- /dev/null +++ b/mail_environment/migrations/19.0.1.1.1/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 5951ba425..3350c03d1 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