Skip to content

Commit

Permalink
[IMP] mail_environment: Keep existing settings at install of module
Browse files Browse the repository at this point in the history
  • Loading branch information
rven committed Jan 2, 2025
1 parent 3a6f9fe commit e08ecbd
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions mail_environment/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import models
from .hooks import post_init_hook
1 change: 1 addition & 0 deletions mail_environment/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
"license": "AGPL-3",
"website": "https://github.com/OCA/server-env",
"depends": ["mail", "server_environment"],
"post_init_hook": "post_init_hook",
}
20 changes: 20 additions & 0 deletions mail_environment/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
def post_init_hook(env):
# Migrate Outgoing Mail Server data
env.cr.execute("SELECT * FROM ir_mail_server")
for row in env.cr.dictfetchall():
mail_server = env["ir.mail_server"].search([("name", "=", row["name"])])

Check warning on line 5 in mail_environment/hooks.py

View check run for this annotation

Codecov / codecov/patch

mail_environment/hooks.py#L5

Added line #L5 was not covered by tests
if not mail_server:
continue

Check warning on line 7 in mail_environment/hooks.py

View check run for this annotation

Codecov / codecov/patch

mail_environment/hooks.py#L7

Added line #L7 was not covered by tests
for field_name, _options in env["ir.mail_server"]._server_env_fields.items():
if field_name in row:
mail_server[field_name] = row[field_name]

Check warning on line 10 in mail_environment/hooks.py

View check run for this annotation

Codecov / codecov/patch

mail_environment/hooks.py#L10

Added line #L10 was not covered by tests

# Migrate Incoming Mail Server data
env.cr.execute("SELECT * FROM fetchmail_server")
for row in env.cr.dictfetchall():
mail_server = env["fetchmail.server"].search([("name", "=", row["name"])])

Check warning on line 15 in mail_environment/hooks.py

View check run for this annotation

Codecov / codecov/patch

mail_environment/hooks.py#L15

Added line #L15 was not covered by tests
if not mail_server:
continue

Check warning on line 17 in mail_environment/hooks.py

View check run for this annotation

Codecov / codecov/patch

mail_environment/hooks.py#L17

Added line #L17 was not covered by tests
for field_name, _options in env["fetchmail.server"]._server_env_fields.items():
if field_name in row:
mail_server[field_name] = row[field_name]

Check warning on line 20 in mail_environment/hooks.py

View check run for this annotation

Codecov / codecov/patch

mail_environment/hooks.py#L20

Added line #L20 was not covered by tests

0 comments on commit e08ecbd

Please sign in to comment.