-
-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by pedrobaeza
- Loading branch information
Showing
12 changed files
with
158 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
|
||
from . import ir_mail_server | ||
from . import mail_message | ||
from . import fetchmail | ||
from . import mail_thread |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import fields, models | ||
|
||
|
||
class FetchmailServer(models.Model): | ||
|
||
_inherit = "fetchmail.server" | ||
|
||
company_id = fields.Many2one("res.company", "Company") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
|
||
import logging | ||
|
||
from odoo import api, models | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class MailThread(models.AbstractModel): | ||
_inherit = "mail.thread" | ||
|
||
@api.model | ||
def message_process( | ||
self, | ||
model, | ||
message, | ||
custom_values=None, | ||
save_original=False, | ||
strip_attachments=False, | ||
thread_id=None, | ||
): | ||
context_company = self.env.company | ||
server_id = self.env.context.get("default_fetchmail_server_id") | ||
server = self.env["fetchmail.server"].browse(server_id) | ||
server_company = server.company_id | ||
if server_company and server_company != context_company: | ||
context_company = server_company | ||
return super(MailThread, self.with_company(context_company)).message_process( | ||
model, message, custom_values, save_original, strip_attachments, thread_id | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
* Go to 'Settings / Technical / Outgoing Mail Servers', and add the company. | ||
* Go to 'Settings / Technical / Incoming Mail Servers', and add the company. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
This module adds company_id to the models ir.mail_server and mail.message. Also inherits mail.message create function to set the company mail_server. | ||
This module adds company_id to the models ir.mail_server, mail.message and fetchmail.server. Also inherits mail.message create function to set the company mail_server | ||
and the mail.thread message_process function to set the correct self.env.company when fetching from the incoming mail servers through a scheduled action. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
To use this module, you need to: | ||
|
||
* Send some email or message that comes out of Odoo. | ||
* Fetch emails from your mail server into Odoo. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,13 @@ def setUpClass(cls): | |
) | ||
cls.server1 = server_obj.create({"name": "server 1", "smtp_host": "teset.smtp"}) | ||
cls.server2 = server_obj.create({"name": "server 1", "smtp_host": "test.smtp"}) | ||
cls.mail_thread = cls.env["mail.thread"] | ||
cls.fetchmail_server = cls.env["fetchmail.server"].create( | ||
{ | ||
"name": "Test Server", | ||
"company_id": cls.company2.id, | ||
} | ||
) | ||
|
||
def _create_message(self): | ||
return ( | ||
|
@@ -86,3 +93,54 @@ def test_02_mail_message_company_restriction(self): | |
msg = self._create_message() | ||
self.assertEqual(msg.mail_server_id.id, self.server1.id) | ||
self.assertEqual(msg.email_from, "[email protected]") | ||
|
||
def test_message_process(self): | ||
fetchmail_server = self.fetchmail_server | ||
self.server2.write({"company_id": self.company2.id}) | ||
|
||
# Create a mail alias and a message that can be processed | ||
# to see that the company context is correctly set | ||
res_partner_model = self.env["ir.model"].search([("model", "=", "res.partner")]) | ||
customer = self.env["res.partner"].create({"name": "Test Partner"}) | ||
|
||
self.env["mail.alias"].create( | ||
{ | ||
"alias_name": "test_alias", | ||
"alias_model_id": res_partner_model.id, | ||
"alias_parent_model_id": res_partner_model.id, | ||
"alias_parent_thread_id": customer.id, | ||
} | ||
) | ||
self.env["ir.config_parameter"].sudo().set_param( | ||
"mail.catchall.domain", "my_domain.com" | ||
) | ||
model = "res.partner" | ||
message = """MIME-Version: 1.0 | ||
Date: Thu, 27 Dec 2018 16:27:45 +0100 | ||
Message-ID: <thisisanid1> | ||
Subject: test message on test partner | ||
From: Test Partner <[email protected]> | ||
To: test_alias@my_domain.com | ||
Content-Type: multipart/alternative; boundary="000000000000a47519057e029630" | ||
--000000000000a47519057e029630 | ||
Content-Type: text/plain; charset="UTF-8" | ||
--000000000000a47519057e029630 | ||
Content-Type: text/html; charset="UTF-8" | ||
Content-Transfer-Encoding: quoted-printable | ||
<div>Message content</div> | ||
--000000000000a47519057e029630-- | ||
""" | ||
context = {"default_fetchmail_server_id": fetchmail_server.id} | ||
|
||
# Call the message_process method | ||
result_id = self.mail_thread.with_context(**context).message_process( | ||
model, message | ||
) | ||
result = self.env["res.partner"].browse(result_id) | ||
# Add your assertions here to validate the result | ||
self.assertEqual(result.message_ids[0].mail_server_id, self.server2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" ?> | ||
<odoo> | ||
<record id="view_email_server_tree_add_company" model="ir.ui.view"> | ||
<field name="name">fetchmail.server.list.add.company</field> | ||
<field name="model">fetchmail.server</field> | ||
<field name="inherit_id" ref="mail.view_email_server_tree" /> | ||
<field name="arch" type="xml"> | ||
<field name="state" position="after"> | ||
<field name="company_id" groups="base.group_multi_company" /> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
<record id="view_email_server_form_add_company" model="ir.ui.view"> | ||
<field name="name">fetchmail.server.form.add.company</field> | ||
<field name="model">fetchmail.server</field> | ||
<field name="inherit_id" ref="mail.view_email_server_form" /> | ||
<field name="arch" type="xml"> | ||
<field name="date" position="after"> | ||
<field | ||
name="company_id" | ||
groups="base.group_multi_company" | ||
options="{'no_create': True}" | ||
/> | ||
</field> | ||
</field> | ||
</record> | ||
</odoo> |