[IMP] mail_tracking: Ignore catchall

This commit is contained in:
Alexandre Díaz 2020-04-16 19:36:32 +02:00 committed by Jasmin Solanki
parent 9449f77510
commit 7e271bb5ca
4 changed files with 40 additions and 5 deletions

View File

@ -10,3 +10,4 @@ from . import res_partner
from . import mail_thread
from . import mail_resend_message
from . import mail_alias
from . import ir_config_parameter

View File

@ -0,0 +1,24 @@
# Copyright 2020 Tecnativa - Alexandre Díaz
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, models
class IrConfigParameter(models.Model):
_inherit = "ir.config_parameter"
@api.model_create_multi
def create(self, vals_list):
res = super().create(vals_list)
self.env["mail.alias"].clear_caches()
return res
def write(self, vals):
res = super().write(vals)
self.env["mail.alias"].clear_caches()
return res
def unlink(self):
res = super().unlink()
self.env["mail.alias"].clear_caches()
return res

View File

@ -10,10 +10,17 @@ class MailAlias(models.Model):
@api.model
@tools.ormcache()
def get_aliases(self):
return {
aliases = {
x["display_name"]
for x in self.search_read([("alias_name", "!=", False)], ["display_name"])
}
IrConfigParamObj = self.env["ir.config_parameter"].sudo()
catchall = "{}@{}".format(
IrConfigParamObj.get_param("mail.catchall.alias"),
IrConfigParamObj.get_param("mail.catchall.domain"),
)
aliases.add(catchall)
return aliases
@api.model_create_multi
def create(self, vals_list):

View File

@ -211,7 +211,7 @@ class TestMailTracking(TransactionCase):
def _check_partner_trackings_to(self, message):
message_dict = message.message_format()[0]
self.assertEqual(len(message_dict["partner_trackings"]), 3)
self.assertEqual(len(message_dict["partner_trackings"]), 4)
# mail cc
foundPartner = False
foundNoPartner = False
@ -253,16 +253,19 @@ class TestMailTracking(TransactionCase):
"res_id": self.recipient.id,
"partner_ids": [(4, self.recipient.id)],
"email_to": "Dominique Pinon <support+unnamed@test.com>"
", sender@example.com, recipient@example.com",
", sender@example.com, recipient@example.com"
", TheCatchall@test.com",
"body": "<p>This is another test message</p>",
}
)
message._moderate_accept()
recipients = self.recipient._message_get_suggested_recipients()
self.assertEqual(len(recipients[self.recipient.id]), 3)
self.assertEqual(len(recipients[self.recipient.id]), 4)
self._check_partner_trackings_to(message)
# Catchall + Alias
self.env["ir.config_parameter"].set_param("mail.catchall.domain", "test.com")
IrConfigParamObj = self.env["ir.config_parameter"].sudo()
IrConfigParamObj.set_param("mail.catchall.alias", "TheCatchall")
IrConfigParamObj.set_param("mail.catchall.domain", "test.com")
self.env["mail.alias"].create(
{
"alias_model_id": self.env["ir.model"]._get("res.partner").id,