[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
This commit is contained in:
@@ -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']:
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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'),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user