diff --git a/mail_notification_clean_status_error/README.rst b/mail_notification_clean_status_error/README.rst new file mode 100644 index 00000000..32488cbf --- /dev/null +++ b/mail_notification_clean_status_error/README.rst @@ -0,0 +1,109 @@ +=================================================== +Mail Notification - Clean up notifications in error +=================================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:9a004084c3440966fc0ecdfebe40e185c6fc5e59542d7b6a1b3985edbfa5c708 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png + :target: https://odoo-community.org/page/development-status + :alt: Production/Stable +.. |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%2Fmail-lightgray.png?logo=github + :target: https://github.com/OCA/mail/tree/18.0/mail_notification_clean_status_error + :alt: OCA/mail +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/mail-18-0/mail-18-0-mail_notification_clean_status_error + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/mail&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Delete email notifications in error. + +The scheduled action *Notification: Delete Notifications older than 6 +Month* provided by Odoo is responsible to delete notifications that have +been sent successfully. + +However, it doesn't delete the notifications that could not be sent, and +their number could keep growing over time, impacting the performance of +some queries related to the chatter. + +This module extends the scheduled action of Odoo to also delete such +notifications. + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +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 +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Camptocamp + +Contributors +------------ + +- `Camptocamp `__: + + - Sébastien Alix + +- `Trobz `__: + + - Khoi (Kien Kim) + +Other credits +------------- + +The migration of this module from 17.0 to 18.0 was financially supported +by: + +- Camptocamp. + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-sebalix| image:: https://github.com/sebalix.png?size=40px + :target: https://github.com/sebalix + :alt: sebalix + +Current `maintainer `__: + +|maintainer-sebalix| + +This module is part of the `OCA/mail `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_notification_clean_status_error/__init__.py b/mail_notification_clean_status_error/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/mail_notification_clean_status_error/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mail_notification_clean_status_error/__manifest__.py b/mail_notification_clean_status_error/__manifest__.py new file mode 100644 index 00000000..72e3707b --- /dev/null +++ b/mail_notification_clean_status_error/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) +{ + "name": "Mail Notification - Clean up notifications in error", + "summary": "Extend Odoo scheduled action to also delete notifications in error.", + "version": "18.0.1.0.0", + "category": "Mail", + "website": "https://github.com/OCA/mail", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "depends": ["mail"], + "development_status": "Production/Stable", + "maintainers": ["sebalix"], +} diff --git a/mail_notification_clean_status_error/i18n/mail_notification_clean_status_error.pot b/mail_notification_clean_status_error/i18n/mail_notification_clean_status_error.pot new file mode 100644 index 00000000..158fa43f --- /dev/null +++ b/mail_notification_clean_status_error/i18n/mail_notification_clean_status_error.pot @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_notification_clean_status_error +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mail_notification_clean_status_error +#: model:ir.model.fields,field_description:mail_notification_clean_status_error.field_mail_notification__display_name +msgid "Display Name" +msgstr "" + +#. module: mail_notification_clean_status_error +#: model:ir.model.fields,field_description:mail_notification_clean_status_error.field_mail_notification__id +msgid "ID" +msgstr "" + +#. module: mail_notification_clean_status_error +#: model:ir.model.fields,field_description:mail_notification_clean_status_error.field_mail_notification____last_update +msgid "Last Modified on" +msgstr "" + +#. module: mail_notification_clean_status_error +#: model:ir.model,name:mail_notification_clean_status_error.model_mail_notification +msgid "Message Notifications" +msgstr "" diff --git a/mail_notification_clean_status_error/models/__init__.py b/mail_notification_clean_status_error/models/__init__.py new file mode 100644 index 00000000..f7ba6ce4 --- /dev/null +++ b/mail_notification_clean_status_error/models/__init__.py @@ -0,0 +1 @@ +from . import mail_notification diff --git a/mail_notification_clean_status_error/models/mail_notification.py b/mail_notification_clean_status_error/models/mail_notification.py new file mode 100644 index 00000000..1547d0c0 --- /dev/null +++ b/mail_notification_clean_status_error/models/mail_notification.py @@ -0,0 +1,21 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from odoo import api, fields, models + + +class MailNotification(models.Model): + _inherit = "mail.notification" + + @api.model + def _gc_notifications(self, max_age_days=180): + res = super()._gc_notifications(max_age_days=max_age_days) + # Extend GC to also delete notifications in error + read_date = fields.Datetime.subtract(fields.Datetime.now(), days=max_age_days) + domain = [ + ("is_read", "=", True), + ("read_date", "<", read_date), + ("notification_status", "in", ("bounce", "exception")), + ] + self.search(domain).unlink() + return res diff --git a/mail_notification_clean_status_error/pyproject.toml b/mail_notification_clean_status_error/pyproject.toml new file mode 100644 index 00000000..4231d0cc --- /dev/null +++ b/mail_notification_clean_status_error/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mail_notification_clean_status_error/readme/CONTRIBUTORS.md b/mail_notification_clean_status_error/readme/CONTRIBUTORS.md new file mode 100644 index 00000000..1ba95526 --- /dev/null +++ b/mail_notification_clean_status_error/readme/CONTRIBUTORS.md @@ -0,0 +1,5 @@ +- [Camptocamp](https://www.camptocamp.com): + - Sébastien Alix \<\> + +- [Trobz](https://trobz.com): + - Khoi (Kien Kim) \<\> diff --git a/mail_notification_clean_status_error/readme/CREDITS.md b/mail_notification_clean_status_error/readme/CREDITS.md new file mode 100644 index 00000000..80354b7d --- /dev/null +++ b/mail_notification_clean_status_error/readme/CREDITS.md @@ -0,0 +1,3 @@ +The migration of this module from 17.0 to 18.0 was financially supported by: + +- Camptocamp. diff --git a/mail_notification_clean_status_error/readme/DESCRIPTION.md b/mail_notification_clean_status_error/readme/DESCRIPTION.md new file mode 100644 index 00000000..bc93e6da --- /dev/null +++ b/mail_notification_clean_status_error/readme/DESCRIPTION.md @@ -0,0 +1,12 @@ +Delete email notifications in error. + +The scheduled action *Notification: Delete Notifications older than 6 +Month* provided by Odoo is responsible to delete notifications that have +been sent successfully. + +However, it doesn't delete the notifications that could not be sent, and +their number could keep growing over time, impacting the performance of +some queries related to the chatter. + +This module extends the scheduled action of Odoo to also delete such +notifications. diff --git a/mail_notification_clean_status_error/static/description/icon.png b/mail_notification_clean_status_error/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/mail_notification_clean_status_error/static/description/icon.png differ diff --git a/mail_notification_clean_status_error/static/description/index.html b/mail_notification_clean_status_error/static/description/index.html new file mode 100644 index 00000000..f687e7b4 --- /dev/null +++ b/mail_notification_clean_status_error/static/description/index.html @@ -0,0 +1,449 @@ + + + + + +Mail Notification - Clean up notifications in error + + + +
+

Mail Notification - Clean up notifications in error

+ + +

Production/Stable License: AGPL-3 OCA/mail Translate me on Weblate Try me on Runboat

+

Delete email notifications in error.

+

The scheduled action Notification: Delete Notifications older than 6 +Month provided by Odoo is responsible to delete notifications that have +been sent successfully.

+

However, it doesn’t delete the notifications that could not be sent, and +their number could keep growing over time, impacting the performance of +some queries related to the chatter.

+

This module extends the scheduled action of Odoo to also delete such +notifications.

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +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 +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+

The migration of this module from 17.0 to 18.0 was financially supported +by:

+
    +
  • Camptocamp.
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

sebalix

+

This module is part of the OCA/mail project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/mail_notification_clean_status_error/tests/__init__.py b/mail_notification_clean_status_error/tests/__init__.py new file mode 100644 index 00000000..eb90d9fb --- /dev/null +++ b/mail_notification_clean_status_error/tests/__init__.py @@ -0,0 +1 @@ +from . import test_gc_notifications diff --git a/mail_notification_clean_status_error/tests/test_gc_notifications.py b/mail_notification_clean_status_error/tests/test_gc_notifications.py new file mode 100644 index 00000000..35050bda --- /dev/null +++ b/mail_notification_clean_status_error/tests/test_gc_notifications.py @@ -0,0 +1,45 @@ +# Copyright 2024 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl) + +from odoo import fields +from odoo.tests.common import TransactionCase + + +class TestNotificationErrorCleanUp(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + 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.notification = cls.env["mail.notification"].create( + { + "mail_message_id": cls.message.id, + "res_partner_id": cls.partner.id, + "notification_type": "email", + "notification_status": "bounce", + } + ) + + def test_notification_in_error_not_read(self): + # While the notification is not read, it is not deleted + self.env["mail.notification"]._gc_notifications(max_age_days=1) + self.assertTrue(self.notification.exists()) + # Once the notification is read, the GC will delete it + # NOTE: update the read data in two steps as 'read_date' is overwritten + # when 'is_read' is set. + read_date = fields.Datetime.subtract(fields.Datetime.now(), days=2) + self.notification.is_read = True + self.notification.read_date = read_date + self.env["mail.notification"]._gc_notifications(max_age_days=1) + self.assertFalse(self.notification.exists())