-
-
Notifications
You must be signed in to change notification settings - Fork 618
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 hbrunn
- Loading branch information
Showing
13 changed files
with
244 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"pull_requests": { | ||
"792": "(auto) Nothing to port from PR #792", | ||
"1244": "(auto) Nothing to port from PR #1244" | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ResCompany(models.Model): | ||
_inherit = "res.company" | ||
|
||
mail_tracking_show_aliases = fields.Boolean( | ||
string="Show Aliases in Mail Tracking", | ||
default=False, | ||
) |
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,16 @@ | ||
from odoo import fields, models | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = "res.config.settings" | ||
|
||
mail_tracking_show_aliases = fields.Boolean( | ||
related="company_id.mail_tracking_show_aliases", | ||
readonly=False, | ||
) | ||
mail_tracking_email_max_age_days = fields.Integer( | ||
"Max age in days of mail tracking email records", | ||
config_parameter="mail_tracking.mail_tracking_email_max_age_days", | ||
help="If set as positive integer enables the deletion of " | ||
"old mail tracking records to reduce the database size.", | ||
) |
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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Copyright 2024 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) | ||
|
||
from odoo import fields | ||
|
||
from odoo.addons.base.tests.common import SavepointCaseWithUserDemo | ||
|
||
|
||
class TestMailTrackingEmailCleanUp(SavepointCaseWithUserDemo): | ||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) | ||
cls.settings = cls.env["res.config.settings"].create( | ||
{"mail_tracking_email_max_age_days": 365} | ||
) | ||
cls.settings.set_values() | ||
cls.partner = cls.env.ref("base.res_partner_address_28") | ||
cls.message = cls.env["mail.message"].create( | ||
{ | ||
"model": "res.partner", | ||
"res_id": cls.partner.id, | ||
"body": "TEST", | ||
"message_type": "email", | ||
"subtype_id": cls.env.ref("mail.mt_comment").id, | ||
"author_id": cls.partner.id, | ||
"date": "2024-03-26", | ||
} | ||
) | ||
cls.recent_mail_tracking_email = cls.env["mail.tracking.email"].create( | ||
{"mail_message_id": cls.message.id} | ||
) | ||
# Can't set the write_date directly as it gets overwritten by the ORM | ||
cls.old_mail_tracking_email = cls.env["mail.tracking.email"].create( | ||
{"mail_message_id": cls.message.id} | ||
) | ||
cls.total_count = 2 | ||
cls.recent_count = 1 | ||
cls.domain = [ | ||
("mail_message_id", "=", cls.message.id), | ||
] | ||
|
||
def _set_write_date(self): | ||
# Set the write_date of the old record to be older than the max_age_days | ||
# Update DB directly to avoid ORM overwriting the write_date | ||
old_write_date = fields.Datetime.subtract(fields.Datetime.now(), days=400) | ||
self.env.cr.execute( | ||
"UPDATE mail_tracking_email SET write_date = %s WHERE id = %s", | ||
(old_write_date, self.old_mail_tracking_email.id), | ||
) | ||
|
||
def test_deletion_of_mail_tracking_email(self): | ||
self._set_write_date() | ||
self.assertEqual( | ||
len(self.env["mail.tracking.email"].search(self.domain)), self.total_count | ||
) | ||
self.env["mail.tracking.email"]._gc_mail_tracking_email() | ||
self.assertEqual( | ||
len(self.env["mail.tracking.email"].search(self.domain)), self.recent_count | ||
) | ||
self.assertTrue(self.recent_mail_tracking_email.exists()) | ||
|
||
def test_deletion_follows_configuration_variable(self): | ||
self._set_write_date() | ||
self.assertEqual( | ||
len(self.env["mail.tracking.email"].search(self.domain)), self.total_count | ||
) | ||
# when disabled, no deletions should happen | ||
self.settings.mail_tracking_email_max_age_days = 0 | ||
self.settings.set_values() | ||
self.env["mail.tracking.email"]._gc_mail_tracking_email() | ||
self.assertEqual( | ||
len(self.env["mail.tracking.email"].search(self.domain)), self.total_count | ||
) | ||
# when disabled, no deletions should happen | ||
self.settings.mail_tracking_email_max_age_days = -1 | ||
self.settings.set_values() | ||
self.env["mail.tracking.email"]._gc_mail_tracking_email() | ||
self.assertEqual( | ||
len(self.env["mail.tracking.email"].search(self.domain)), self.total_count | ||
) | ||
# when enabled, deletions should happen | ||
self.settings.mail_tracking_email_max_age_days = 365 | ||
self.settings.set_values() | ||
self.env["mail.tracking.email"]._gc_mail_tracking_email() | ||
self.assertEqual( | ||
len(self.env["mail.tracking.email"].search(self.domain)), self.recent_count | ||
) |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<record id="res_config_settings_view_form" model="ir.ui.view"> | ||
<field name="name">res.config.settings.view.form.inherit.mail.tracking</field> | ||
<field name="model">res.config.settings</field> | ||
<field name="inherit_id" ref="mail.res_config_settings_view_form" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//block[@id='emails']" position="inside"> | ||
<setting> | ||
<field name="mail_tracking_show_aliases" /> | ||
<div class="content-group"> | ||
<label for="mail_tracking_show_aliases" /> | ||
<div | ||
class="text-muted" | ||
id="mail_tracking_show_aliases" | ||
>Show Aliases in Mail Tracking</div> | ||
</div> | ||
</setting> | ||
<setting> | ||
<field name="mail_tracking_email_max_age_days" /> | ||
<div class="content-group"> | ||
<label | ||
for="mail_tracking_email_max_age_days" | ||
string="Max age in days of mail tracking email records" | ||
/> | ||
<div | ||
class="text-muted" | ||
id="mail_tracking_email_max_age_days" | ||
>If set as positive integer enables the deletion of old mail tracking records to reduce the database size.</div> | ||
</div> | ||
</setting> | ||
</xpath> | ||
</field> | ||
</record> | ||
</odoo> |