Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mail_environment/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Mail configuration with server_environment",
"version": "19.0.1.1.0",
"version": "19.0.1.1.1",

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pre-commit argues if manifest version is not changed

"category": "Tools",
"summary": "Configure mail servers with server_environment_files",
"author": "Camptocamp, Odoo Community Association (OCA)",
Expand Down
9 changes: 9 additions & 0 deletions mail_environment/migrations/19.0.1.1.1/post-migration.py
Original file line number Diff line number Diff line change
@@ -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"])
Comment on lines +7 to +9

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set 19.0.1.1.1 as next patch one release ahead of current.

2 changes: 1 addition & 1 deletion mail_environment/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
<title>README.rst</title>
<title>Mail configuration with server_environment</title>
<style type="text/css">

/*
Expand Down
28 changes: 28 additions & 0 deletions server_environment/models/server_env_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading