diff --git a/mail_notification_clean_status_error/README.rst b/mail_notification_clean_status_error/README.rst new file mode 100644 index 000000000..9ffe3185b --- /dev/null +++ b/mail_notification_clean_status_error/README.rst @@ -0,0 +1,117 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +=================================================== +Mail Notification - Clean up notifications in error +=================================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:bd9f5cb206148163f804bac6b092c415e864e167ac477e80fb6150e8c827d201 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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/19.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-19-0/mail-19-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=19.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) + +- CIT-Services <> + +- Prayag + +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 000000000..0650744f6 --- /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 000000000..bfa7650e7 --- /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": "19.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/it.po b/mail_notification_clean_status_error/i18n/it.po new file mode 100644 index 000000000..0b942122a --- /dev/null +++ b/mail_notification_clean_status_error/i18n/it.po @@ -0,0 +1,22 @@ +# 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 19.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-11-19 11:52+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.6.2\n" + +#. module: mail_notification_clean_status_error +#: model:ir.model,name:mail_notification_clean_status_error.model_mail_notification +msgid "Message Notifications" +msgstr "Notifiche messaggio" 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 000000000..62b71afbc --- /dev/null +++ b/mail_notification_clean_status_error/i18n/mail_notification_clean_status_error.pot @@ -0,0 +1,19 @@ +# 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 19.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,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 000000000..f7ba6ce41 --- /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 000000000..1547d0c02 --- /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 000000000..4231d0ccc --- /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 000000000..5a0fd2ea2 --- /dev/null +++ b/mail_notification_clean_status_error/readme/CONTRIBUTORS.md @@ -0,0 +1,7 @@ +- [Camptocamp](https://www.camptocamp.com): + - Sébastien Alix \<\> + +- [Trobz](https://trobz.com): + - Khoi (Kien Kim) \<\> +- CIT-Services \<\> +- Prayag \<\> 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 000000000..80354b7d2 --- /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 000000000..bc93e6da7 --- /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/index.html b/mail_notification_clean_status_error/static/description/index.html new file mode 100644 index 000000000..967be5e31 --- /dev/null +++ b/mail_notification_clean_status_error/static/description/index.html @@ -0,0 +1,457 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

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 000000000..eb90d9fb3 --- /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 000000000..c8b627a00 --- /dev/null +++ b/mail_notification_clean_status_error/tests/test_gc_notifications.py @@ -0,0 +1,79 @@ +# 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.user.partner_id + 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()) + + def test_notification_exception_status(self): + msg = self.env["mail.message"].create( + { + "model": "res.partner", + "res_id": self.partner.id, + "body": "TEST EXC", + "message_type": "email", + "subtype_id": self.env.ref("mail.mt_comment").id, + "author_id": self.partner.id, + "date": "2024-03-26", + } + ) + notification_exc = self.env["mail.notification"].create( + { + "mail_message_id": msg.id, + "res_partner_id": self.partner.id, + "notification_type": "email", + "notification_status": "exception", + } + ) + read_date = fields.Datetime.subtract(fields.Datetime.now(), days=2) + notification_exc.is_read = True + notification_exc.read_date = read_date + self.env["mail.notification"]._gc_notifications(max_age_days=1) + self.assertFalse(notification_exc.exists()) + + def test_notification_in_error_recent_read(self): + # Read recently (read_date > max_age_days threshold), should not be deleted + read_date = fields.Datetime.now() + self.notification.is_read = True + self.notification.read_date = read_date + self.env["mail.notification"]._gc_notifications(max_age_days=1) + self.assertTrue(self.notification.exists())