From 60f170a168a1b820f50d245f4cabcfab0b36a2b2 Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Sat, 22 Apr 2023 10:11:20 +0200 Subject: [PATCH] [IMP] mail_activity_reminder: Group sendings per user and activity type --- mail_activity_reminder/README.rst | 6 --- mail_activity_reminder/__manifest__.py | 6 ++- .../data/mail_activity_template.xml | 43 +++++++++++++++++++ .../models/mail_activity.py | 31 ++++++------- mail_activity_reminder/readme/ROADMAP.rst | 2 - .../static/description/index.html | 30 +++++-------- 6 files changed, 74 insertions(+), 44 deletions(-) create mode 100644 mail_activity_reminder/data/mail_activity_template.xml delete mode 100644 mail_activity_reminder/readme/ROADMAP.rst diff --git a/mail_activity_reminder/README.rst b/mail_activity_reminder/README.rst index abddfcd26..21dde1cc1 100644 --- a/mail_activity_reminder/README.rst +++ b/mail_activity_reminder/README.rst @@ -43,12 +43,6 @@ To configure reminders for specific Activity Type: when reminders should be fired: e.g. 0 means "on the deadline day" while 5 means "5 calendar days before the deadline". -Known issues / Roadmap -====================== - - * Maybe, group reminders by receiver and send multiple scheduled remiders - in one message. - Bug Tracker =========== diff --git a/mail_activity_reminder/__manifest__.py b/mail_activity_reminder/__manifest__.py index 882ef3f07..f686193b3 100644 --- a/mail_activity_reminder/__manifest__.py +++ b/mail_activity_reminder/__manifest__.py @@ -11,5 +11,9 @@ "license": "AGPL-3", "summary": "Reminder notifications about planned activities", "depends": ["mail"], - "data": ["data/mail_activity_reminder_cron.xml", "views/mail_activity_type.xml"], + "data": [ + "data/mail_activity_reminder_cron.xml", + "views/mail_activity_type.xml", + "data/mail_activity_template.xml", + ], } diff --git a/mail_activity_reminder/data/mail_activity_template.xml b/mail_activity_reminder/data/mail_activity_template.xml new file mode 100644 index 000000000..21e3c6ac2 --- /dev/null +++ b/mail_activity_reminder/data/mail_activity_template.xml @@ -0,0 +1,43 @@ + + + + + + + diff --git a/mail_activity_reminder/models/mail_activity.py b/mail_activity_reminder/models/mail_activity.py index e1898ef8f..6d5825612 100644 --- a/mail_activity_reminder/models/mail_activity.py +++ b/mail_activity_reminder/models/mail_activity.py @@ -98,30 +98,31 @@ class MailActivity(models.Model): activity.last_reminder_local = utc_now.astimezone(tz).replace(tzinfo=None) def action_remind(self): - IrModel = self.env["ir.model"] + """ + Group reminders by user and type and send them together + """ MailThread = self.env["mail.thread"] - message_activity_assigned = self.env.ref("mail.message_activity_assigned") + message_activity_assigned = self.env.ref( + "mail_activity_reminder.message_activity_assigned" + ) utc_now = fields.Datetime.now().replace(tzinfo=UTC) - for activity in self: - tz = timezone(activity.user_id.sudo().tz or "UTC") + for user in self.mapped("user_id"): + activities = self.filtered(lambda activity: activity.user_id == user) + tz = timezone(user.sudo().tz or "UTC") local_now = utc_now.astimezone(tz) - model_description = IrModel._get(activity.res_model).display_name - subject = _("%s: %s assigned to you, %d day(s) remaining") % ( - activity.res_name, - activity.summary or activity.activity_type_id.name, - (activity.date_deadline - local_now.date()).days, - ) + + subject = _("Some activities you are assigned too expire soon.") + body = message_activity_assigned.render( - dict(activity=activity, model_description=model_description), + dict(activities=activities, model_description="Activities"), engine="ir.qweb", minimal_qcontext=True, ) MailThread.message_notify( - partner_ids=activity.user_id.partner_id.ids, + partner_ids=user.partner_id.ids, body=body, subject=subject, - record_name=activity.res_name, - model_description=model_description, + model_description="Activity", notif_layout="mail.mail_notification_light", ) - activity.last_reminder_local = local_now.replace(tzinfo=None) + activities.update({"last_reminder_local": local_now.replace(tzinfo=None)}) diff --git a/mail_activity_reminder/readme/ROADMAP.rst b/mail_activity_reminder/readme/ROADMAP.rst deleted file mode 100644 index adc78bcf4..000000000 --- a/mail_activity_reminder/readme/ROADMAP.rst +++ /dev/null @@ -1,2 +0,0 @@ - * Maybe, group reminders by receiver and send multiple scheduled remiders - in one message. diff --git a/mail_activity_reminder/static/description/index.html b/mail_activity_reminder/static/description/index.html index 1d9d9ccf9..23102a8ed 100644 --- a/mail_activity_reminder/static/description/index.html +++ b/mail_activity_reminder/static/description/index.html @@ -373,12 +373,11 @@ ul.auto-toc {
-
-

Known issues / Roadmap

-
-
    -
  • Maybe, group reminders by receiver and send multiple scheduled remiders -in one message.
  • -
-
-
-

Bug Tracker

+

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 smashing it by providing a detailed and welcomed @@ -412,15 +402,15 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

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

-

Credits

+

Credits

-

Authors

+

Authors

  • CorporateHub
-

Contributors

+

Contributors

-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association

OCA, or the Odoo Community Association, is a nonprofit organization whose