[IMP] mail: ease the use and specification of notification emails layout
This commit proposes to ease the use and specification of layout used to encapsulate email body when sending notification emails. This is done through two means * message_post_with_template now supports the custom layout parameter that allows to set the layout to use when sending notification emails in the message_post process. We have to rely on the context as it is the current way of using it in the composer. It is likely to change in a near future; * composer now supports through context (as we have no other choice) specific notification values to give to the notification layout rendering; This commit is related to task 51122 (and PR #24052).
This commit is contained in:
committed by
Thibault Delavallée
parent
caf400fa7c
commit
1184f7872d
@@ -2076,6 +2076,7 @@ class MailThread(models.AbstractModel):
|
||||
kwargs['message_type'] = 'notification'
|
||||
res_id = kwargs.get('res_id', self.ids and self.ids[0] or 0)
|
||||
res_ids = kwargs.get('res_id') and [kwargs['res_id']] or self.ids
|
||||
notif_layout = kwargs.pop('notif_layout', None)
|
||||
|
||||
# Create the composer
|
||||
composer = self.env['mail.compose.message'].with_context(
|
||||
@@ -2086,6 +2087,7 @@ class MailThread(models.AbstractModel):
|
||||
default_model=kwargs.get('model', self._name),
|
||||
default_res_id=res_id,
|
||||
default_template_id=template_id,
|
||||
custom_layout=notif_layout,
|
||||
).create(kwargs)
|
||||
# Simulate the onchange (like trigger in form the view) only
|
||||
# when having a template in single-email mode
|
||||
|
||||
@@ -85,7 +85,7 @@ class Partner(models.Model):
|
||||
'signature': signature,
|
||||
'website_url': website_url,
|
||||
'company': company,
|
||||
'model_name': model_name,
|
||||
'model_description': model_name,
|
||||
'record': record,
|
||||
'record_name': record_name,
|
||||
'tracking_values': tracking,
|
||||
|
||||
@@ -198,6 +198,7 @@ class MailComposer(models.TransientModel):
|
||||
""" Process the wizard content and proceed with sending the related
|
||||
email(s), rendering any template patterns on the fly if needed. """
|
||||
notif_layout = self._context.get('custom_layout')
|
||||
ctx_notif_values = self._context.get('notif_values', {})
|
||||
for wizard in self:
|
||||
# Duplicate attachments linked to the email.template.
|
||||
# Indeed, basic mail.compose.message wizard duplicates attachments in mass
|
||||
@@ -246,14 +247,15 @@ class MailComposer(models.TransientModel):
|
||||
if wizard.composition_mode == 'mass_mail':
|
||||
batch_mails |= Mail.create(mail_values)
|
||||
else:
|
||||
notif_values = dict(
|
||||
add_sign=not bool(wizard.template_id),
|
||||
mail_auto_delete=wizard.template_id.auto_delete if wizard.template_id else False,
|
||||
**ctx_notif_values)
|
||||
post_params = dict(
|
||||
message_type=wizard.message_type,
|
||||
subtype_id=subtype_id,
|
||||
notif_layout=notif_layout,
|
||||
notif_values={
|
||||
'add_sign': not bool(wizard.template_id),
|
||||
'mail_auto_delete': wizard.template_id.auto_delete if wizard.template_id else False,
|
||||
},
|
||||
notif_values=notif_values,
|
||||
**mail_values)
|
||||
if ActiveModel._name == 'mail.thread' and wizard.model:
|
||||
post_params['model'] = wizard.model
|
||||
|
||||
Reference in New Issue
Block a user