From ea3e4d2dc08d1eaefdc3d85a383d176597be9864 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 6 Jan 2023 09:55:48 +0000 Subject: [PATCH] [REF] various: cleanup usage of 'message_notify' Notification method 'message_notify' is sometimes used as a standalone method to send notifications. In that case it is called directly on MailThread abstract model, notably when there is no context record or when it does not inherit from 'mail.thread' directly. This is done mostly in technical models. However in that case some model-specific code is not called, notably methods computing default subject. In this commit we improve some calls to be sure notifications have content enough to be understandable. When possible, we also redirect the notification method on real records inheriting from mail.thread, enabling a more complete process. See community PR for more details. Task-2710804 (Mail: Clean MailThread Posting API) Part-of: odoo/odoo#99482 --- .../data_recycle/models/data_recycle_model.py | 30 +++++++++++-------- addons/hr_holidays/models/hr_leave.py | 3 +- addons/lunch/models/lunch_alert.py | 5 ++-- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/addons/data_recycle/models/data_recycle_model.py b/addons/data_recycle/models/data_recycle_model.py index 16c754ad3e9..bfcc1630999 100644 --- a/addons/data_recycle/models/data_recycle_model.py +++ b/addons/data_recycle/models/data_recycle_model.py @@ -172,20 +172,24 @@ class DataRecycleModel(models.Model): ('recycle_model_id', '=', self.id), ('create_date', '>=', last_date) ]) - - if records_count: - partner_ids = self.notify_user_ids.partner_id.ids + partner_ids = self.notify_user_ids.partner_id.ids if records_count else [] + if partner_ids: menu_id = self.env.ref('data_recycle.menu_data_cleaning_root').id - kwargs = { - 'body': self.env['ir.qweb']._render('data_recycle.notification', { - 'records_count': records_count, - 'res_model_label': self.res_model_id.name, - 'recycle_model_id': self.id, - 'menu_id': menu_id - }), - 'partner_ids': partner_ids, - } - self.env['mail.thread'].with_context(mail_notify_author=True).message_notify(**kwargs) + self.env['mail.thread'].with_context(mail_notify_author=True).message_notify( + body=self.env['ir.qweb']._render( + 'data_recycle.notification', + { + 'records_count': records_count, + 'res_model_label': self.res_model_id.name, + 'recycle_model_id': self.id, + 'menu_id': menu_id + } + ), + model=self._name, + partner_ids=partner_ids, + res_id=self.id, + subject=_('Data to Recycle'), + ) def write(self, vals): if 'active' in vals and not vals['active']: diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index 7ac352cd106..bbe9a79a2b2 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -1624,7 +1624,8 @@ class HolidaysRequest(models.Model): if recipient: self.env['mail.thread'].sudo().message_notify( body=message, - partner_ids=[recipient] + partner_ids=[recipient], + subject=_('Your Time Off'), ) def _track_subtype(self, init_values): diff --git a/addons/lunch/models/lunch_alert.py b/addons/lunch/models/lunch_alert.py index d3e4b3c140f..85351a4d4e4 100644 --- a/addons/lunch/models/lunch_alert.py +++ b/addons/lunch/models/lunch_alert.py @@ -2,7 +2,7 @@ import pytz import logging -from odoo import api, fields, models +from odoo import api, fields, models, _ from odoo.osv import expression from .lunch_supplier import float_to_time @@ -194,5 +194,6 @@ class LunchAlert(models.Model): if partners: self.env['mail.thread'].message_notify( body=self.message, - partner_ids=partners.ids + partner_ids=partners.ids, + subject=_('Your Lunch Order'), )