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
22 changes: 9 additions & 13 deletions mail_environment/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

==========================================
Mail configuration with server_environment
==========================================
Expand All @@ -17,7 +13,7 @@ Mail configuration with server_environment
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--env-lightgray.png?logo=github
Expand Down Expand Up @@ -103,8 +99,8 @@ file.
Known issues / Roadmap
======================

- Due to the special nature of this addon, you cannot test it on the OCA
runbot.
- Due to the special nature of this addon, you cannot test it on the
OCA runbot.

Bug Tracker
===========
Expand All @@ -127,12 +123,12 @@ Authors
Contributors
------------

- Nicolas Bessi <nicolas.bessi@camptocamp.com>
- Yannick Vaucher <yannick.vaucher@camptocamp.com>
- Guewen Baconnier <guewen.baconnier@camptocamp.com>
- Joël Grand-Guillaume <joel.grandguillaume@camptocamp.com>
- Holger Brunn <hbrunn@therp.nl>
- Alexandre Fayolle <alexandre.fayolle@camptocamp.com>
- Nicolas Bessi <nicolas.bessi@camptocamp.com>
- Yannick Vaucher <yannick.vaucher@camptocamp.com>
- Guewen Baconnier <guewen.baconnier@camptocamp.com>
- Joël Grand-Guillaume <joel.grandguillaume@camptocamp.com>
- Holger Brunn <hbrunn@therp.nl>
- Alexandre Fayolle <alexandre.fayolle@camptocamp.com>

Maintainers
-----------
Expand Down
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, pre_init_hook
2 changes: 2 additions & 0 deletions mail_environment/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@
"license": "AGPL-3",
"website": "https://github.com/OCA/server-env",
"depends": ["mail", "server_environment"],
"pre_init_hook": "pre_init_hook",
"post_init_hook": "post_init_hook",
}
79 changes: 79 additions & 0 deletions mail_environment/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from odoo.tools import config


def pre_init_hook(env):
if config["test_enable"]:
env["ir.mail_server"].create(
{
"name": "Test Outgoing Mail Server",
"smtp_host": "localhost",
"smtp_port": 25,
"smtp_user": "test",
"smtp_pass": "test123",
"active": False,
}
)
env.cr.execute(
"SELECT * FROM ir_mail_server where name = 'Test Outgoing Mail Server'"
)
mail_server = env.cr.dictfetchone()
assert mail_server
assert mail_server["smtp_host"] == "localhost"
assert mail_server["smtp_port"] == 25
assert mail_server["smtp_user"] == "test"
assert mail_server["smtp_pass"] == "test123"
env["fetchmail.server"].create(
{
"name": "Test Incoming Mail Server",
"server": "localhost",
"port": 143,
"user": "test",
"password": "test123",
"active": False,
}
)
env.cr.execute(
"SELECT * FROM fetchmail_server where name = 'Test Incoming Mail Server'"
)
mail_server = env.cr.dictfetchone()
assert mail_server
assert mail_server["server"] == "localhost"
assert mail_server["port"] == 143
assert mail_server["user"] == "test"
assert mail_server["password"] == "test123"


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"]
.with_context(active_test=False)
.search([("name", "=", row["name"])])
)
if mail_server:
mail_server_values = {}
for field_name, _options in env[
"ir.mail_server"
]._server_env_fields.items():
if field_name in row:
mail_server_values[field_name] = row[field_name]
mail_server.update(mail_server_values)

# Migrate Incoming Mail Server data
env.cr.execute("SELECT * FROM fetchmail_server")
for row in env.cr.dictfetchall():
mail_server = (
env["fetchmail.server"]
.with_context(active_test=False)
.search([("name", "=", row["name"])])
)
if mail_server:
mail_server_values = {}
for field_name, _options in env[
"fetchmail.server"
]._server_env_fields.items():
if field_name in row:
mail_server_values[field_name] = row[field_name]
mail_server.update(mail_server_values)
36 changes: 15 additions & 21 deletions 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 Expand Up @@ -360,21 +360,16 @@
</style>
</head>
<body>
<div class="document">
<div class="document" id="mail-configuration-with-server-environment">
<h1 class="title">Mail configuration with server_environment</h1>


<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
</a>
<div class="section" id="mail-configuration-with-server-environment">
<h1>Mail configuration with server_environment</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:b27d3ac30fd7cb59d6eed6d0f910db100f70a145e028b2096015bcd7022a33b3
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-env/tree/18.0/mail_environment"><img alt="OCA/server-env" src="https://img.shields.io/badge/github-OCA%2Fserver--env-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-env-18-0/server-env-18-0-mail_environment"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-env&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-env/tree/18.0/mail_environment"><img alt="OCA/server-env" src="https://img.shields.io/badge/github-OCA%2Fserver--env-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-env-18-0/server-env-18-0-mail_environment"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-env&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows to configure the incoming and outgoing mail servers
using the server_environment mechanism: you can then have different mail
servers for the production and the test environment.</p>
Expand All @@ -395,12 +390,12 @@ <h1>Mail configuration with server_environment</h1>
</ul>
</div>
<div class="section" id="installation">
<h2><a class="toc-backref" href="#toc-entry-1">Installation</a></h2>
<h1><a class="toc-backref" href="#toc-entry-1">Installation</a></h1>
<p>To install this module, you need to have the server_environment module
installed and properly configured.</p>
</div>
<div class="section" id="configuration">
<h2><a class="toc-backref" href="#toc-entry-2">Configuration</a></h2>
<h1><a class="toc-backref" href="#toc-entry-2">Configuration</a></h1>
<p>With this module installed, the incoming and outgoing mail servers are
configured in the server_environment_files module (which is a module you
should provide, see the documentation of server_environment for more
Expand Down Expand Up @@ -440,36 +435,36 @@ <h2><a class="toc-backref" href="#toc-entry-2">Configuration</a></h2>
mail server with the field name set to “odoo_pop_mail1”.</p>
</div>
<div class="section" id="usage">
<h2><a class="toc-backref" href="#toc-entry-3">Usage</a></h2>
<h1><a class="toc-backref" href="#toc-entry-3">Usage</a></h1>
<p>Once configured, Odoo will read the mail servers values from the
configuration file related to each environment defined in the main Odoo
file.</p>
</div>
<div class="section" id="known-issues-roadmap">
<h2><a class="toc-backref" href="#toc-entry-4">Known issues / Roadmap</a></h2>
<h1><a class="toc-backref" href="#toc-entry-4">Known issues / Roadmap</a></h1>
<ul class="simple">
<li>Due to the special nature of this addon, you cannot test it on the OCA
runbot.</li>
<li>Due to the special nature of this addon, you cannot test it on the
OCA runbot.</li>
</ul>
</div>
<div class="section" id="bug-tracker">
<h2><a class="toc-backref" href="#toc-entry-5">Bug Tracker</a></h2>
<h1><a class="toc-backref" href="#toc-entry-5">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-env/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/server-env/issues/new?body=module:%20mail_environment%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
<h2><a class="toc-backref" href="#toc-entry-6">Credits</a></h2>
<h1><a class="toc-backref" href="#toc-entry-6">Credits</a></h1>
<div class="section" id="authors">
<h3><a class="toc-backref" href="#toc-entry-7">Authors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-7">Authors</a></h2>
<ul class="simple">
<li>Camptocamp</li>
</ul>
</div>
<div class="section" id="contributors">
<h3><a class="toc-backref" href="#toc-entry-8">Contributors</a></h3>
<h2><a class="toc-backref" href="#toc-entry-8">Contributors</a></h2>
<ul class="simple">
<li>Nicolas Bessi &lt;<a class="reference external" href="mailto:nicolas.bessi&#64;camptocamp.com">nicolas.bessi&#64;camptocamp.com</a>&gt;</li>
<li>Yannick Vaucher &lt;<a class="reference external" href="mailto:yannick.vaucher&#64;camptocamp.com">yannick.vaucher&#64;camptocamp.com</a>&gt;</li>
Expand All @@ -480,7 +475,7 @@ <h3><a class="toc-backref" href="#toc-entry-8">Contributors</a></h3>
</ul>
</div>
<div class="section" id="maintainers">
<h3><a class="toc-backref" href="#toc-entry-9">Maintainers</a></h3>
<h2><a class="toc-backref" href="#toc-entry-9">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
Expand All @@ -493,6 +488,5 @@ <h3><a class="toc-backref" href="#toc-entry-9">Maintainers</a></h3>
</div>
</div>
</div>
</div>
</body>
</html>
1 change: 1 addition & 0 deletions mail_environment/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import test_existing_mail_server_config
from . import test_mail_environment
30 changes: 30 additions & 0 deletions mail_environment/tests/test_existing_mail_server_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from odoo.tests import tagged

from odoo.addons.server_environment.tests.common import ServerEnvironmentCase


@tagged("post_install", "-at_install")
class TestMailEnvironment(ServerEnvironmentCase):
def test_outgoing_mail_server(self):
mail_server = (
self.env["ir.mail_server"]
.with_context(active_test=False)
.search([("name", "=", "Test Outgoing Mail Server")])
)
self.assertTrue(mail_server)
self.assertEqual(mail_server.smtp_host, "localhost")
self.assertEqual(mail_server.smtp_port, 25)
self.assertEqual(mail_server.smtp_user, "test")
self.assertEqual(mail_server.smtp_pass, "test123")

def test_incoming_mail_server(self):
mail_server = (
self.env["fetchmail.server"]
.with_context(active_test=False)
.search([("name", "=", "Test Incoming Mail Server")])
)
self.assertTrue(mail_server)
self.assertEqual(mail_server.server, "localhost")
self.assertEqual(mail_server.port, 143)
self.assertEqual(mail_server.user, "test")
self.assertEqual(mail_server.password, "test123")