Skip to content

Commit ebe778f

Browse files
committed
Merge PR #1475 into 17.0
Signed-off-by hbrunn
2 parents 6488367 + 82e6646 commit ebe778f

File tree

13 files changed

+244
-9
lines changed

13 files changed

+244
-9
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"pull_requests": {
3+
"792": "(auto) Nothing to port from PR #792",
4+
"1244": "(auto) Nothing to port from PR #1244"
5+
}
6+
}

mail_tracking/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"views/mail_tracking_event_view.xml",
2424
"views/mail_message_view.xml",
2525
"views/res_partner_view.xml",
26+
"views/res_config_settings.xml",
2627
],
2728
"assets": {
2829
"web.assets_backend": [

mail_tracking/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
22

3+
from . import res_company
4+
from . import res_config_settings
35
from . import ir_mail_server
46
from . import mail_bounced_mixin
57
from . import mail_guest

mail_tracking/models/mail_message.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ def tracking_status(self):
226226
@api.model
227227
def _drop_aliases(self, mail_list):
228228
aliases = self.env["mail.alias"].get_aliases()
229+
if self.env.company.mail_tracking_show_aliases:
230+
IrConfigParamObj = self.env["ir.config_parameter"].sudo()
231+
aliases = "{}@{}".format(
232+
IrConfigParamObj.get_param("mail.catchall.alias"),
233+
IrConfigParamObj.get_param("mail.catchall.domain"),
234+
)
229235

230236
def _filter_alias(email):
231237
email_wn = getaddresses([email])[0][1]

mail_tracking/models/mail_thread.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ def _add_extra_recipients_suggestions(self, suggestions, field_mail, reason):
9494
)
9595
else:
9696
partner = ResPartnerObj.browse(partner_id)
97-
self._message_add_suggested_recipient(
98-
suggestions, partner=partner, reason=reason
99-
)
97+
if partner.email not in aliases:
98+
self._message_add_suggested_recipient(
99+
suggestions, partner=partner, reason=reason
100+
)
100101

101102
@api.model
102103
def get_view(self, view_id=None, view_type="form", **options):

mail_tracking/models/mail_tracking_email.py

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,7 @@ class MailTrackingEmail(models.Model):
118118
@api.depends("mail_message_id")
119119
def _compute_message_id(self):
120120
"""This helper field will allow us to map the message_id from either the linked
121-
mail.message or a mass.mailing mail.trace.
122-
"""
121+
mail.message or a mass.mailing mail.trace."""
123122
self.message_id = False
124123
for tracking in self.filtered("mail_message_id"):
125124
tracking.message_id = tracking.mail_message_id.message_id
@@ -462,3 +461,40 @@ def event_process(self, request, post, metadata, event_type=None):
462461
# - return 'NONE' if this request is not for you
463462
# - return 'ERROR' if any error
464463
return "NONE" # pragma: no cover
464+
465+
def _get_old_mail_tracking_email_domain(self, max_age_days):
466+
target_write_date = fields.Datetime.subtract(
467+
fields.Datetime.now(), days=max_age_days
468+
)
469+
return [("write_date", "<", target_write_date)]
470+
471+
@api.autovacuum
472+
def _gc_mail_tracking_email(self, limit=5000):
473+
config_max_age_days = (
474+
self.env["ir.config_parameter"]
475+
.sudo()
476+
.get_param("mail_tracking.mail_tracking_email_max_age_days")
477+
)
478+
try:
479+
max_age_days = int(config_max_age_days)
480+
except ValueError:
481+
max_age_days = 0
482+
483+
if not max_age_days > 0:
484+
return False
485+
486+
domain = self._get_old_mail_tracking_email_domain(max_age_days)
487+
records_to_delete = self.search(domain, limit=limit).exists()
488+
if records_to_delete:
489+
_logger.info(
490+
"Deleting %s mail.tracking.email records", len(records_to_delete)
491+
)
492+
records_to_delete.flush_recordset()
493+
# Using a direct query to avoid ORM as it causes an issue with
494+
# a related field mass_mailing_id in customer DB when deleting
495+
# the records. This might be 14.0 specific, so changing to
496+
# .unlink() should be tested when forward porting.
497+
query = "DELETE FROM mail_tracking_email WHERE id IN %s"
498+
args = (tuple(records_to_delete.ids),)
499+
self.env.cr.execute(query, args)
500+
self.invalidate_model()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from odoo import fields, models
2+
3+
4+
class ResCompany(models.Model):
5+
_inherit = "res.company"
6+
7+
mail_tracking_show_aliases = fields.Boolean(
8+
string="Show Aliases in Mail Tracking",
9+
default=False,
10+
)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from odoo import fields, models
2+
3+
4+
class ResConfigSettings(models.TransientModel):
5+
_inherit = "res.config.settings"
6+
7+
mail_tracking_show_aliases = fields.Boolean(
8+
related="company_id.mail_tracking_show_aliases",
9+
readonly=False,
10+
)
11+
mail_tracking_email_max_age_days = fields.Integer(
12+
"Max age in days of mail tracking email records",
13+
config_parameter="mail_tracking.mail_tracking_email_max_age_days",
14+
help="If set as positive integer enables the deletion of "
15+
"old mail tracking records to reduce the database size.",
16+
)

mail_tracking/static/description/index.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
/*
1010
:Author: David Goodger ([email protected])
11-
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
11+
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
1212
:Copyright: This stylesheet has been placed in the public domain.
1313
1414
Default cascading style sheet for the HTML output of Docutils.
15+
Despite the name, some widely supported CSS2 features are used.
1516
1617
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1718
customize this style sheet.
@@ -274,7 +275,7 @@
274275
margin-left: 2em ;
275276
margin-right: 2em }
276277

277-
pre.code .ln { color: grey; } /* line numbers */
278+
pre.code .ln { color: gray; } /* line numbers */
278279
pre.code, code { background-color: #eeeeee }
279280
pre.code .comment, code .comment { color: #5C6576 }
280281
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -300,7 +301,7 @@
300301
span.pre {
301302
white-space: pre }
302303

303-
span.problematic {
304+
span.problematic, pre.problematic {
304305
color: red }
305306

306307
span.section-subtitle {
@@ -495,7 +496,9 @@ <h2><a class="toc-backref" href="#toc-entry-8">Contributors</a></h2>
495496
<div class="section" id="maintainers">
496497
<h2><a class="toc-backref" href="#toc-entry-9">Maintainers</a></h2>
497498
<p>This module is maintained by the OCA.</p>
498-
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
499+
<a class="reference external image-reference" href="https://odoo-community.org">
500+
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
501+
</a>
499502
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
500503
mission is to support the collaborative development of Odoo features and
501504
promote its widespread use.</p>

mail_tracking/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
33

44
from . import test_mail_tracking
5+
from . import test_gc_mail_tracking_email

0 commit comments

Comments
 (0)