Skip to content
Snippets Groups Projects
Commit 158fa968 authored by Haresh Kansara's avatar Haresh Kansara Committed by Thibault Delavallée
Browse files

[IMP] survey: add optional encapsulation layout when sending survey emails

This commit adds possibility to add a notification layout when sending
an email in survey using their specific composer. Purpose of this task is to
allow to send some technical template-based emails using the default
notification layouts defined in mail. It allows to avoid redefining the whole
layout in the template itself. This way email body content is simpler.

This commit is linked to task ID 1843224 (and 1868112) and to PR #25313
(and #25889).
parent c1f250d5
Branches
Tags
No related merge requests found
......@@ -124,7 +124,9 @@ class TestSurvey(TransactionCase):
default_survey_id=correct_survey.id,
default_use_template=bool(template),
default_template_id=template and template.id or False,
default_composition_mode='comment')
default_composition_mode='comment',
notif_layout='mail.mail_notification_light',
)
self.assertDictEqual(action, {
'type': 'ir.actions.act_window',
......
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging
import re
import uuid
......@@ -10,9 +11,12 @@ from odoo import api, fields, models, _
from odoo.exceptions import UserError
from odoo.tools import pycompat
_logger = logging.getLogger(__name__)
emails_split = re.compile(r"[;,\n\r]+")
email_validator = re.compile(r"[^@]+@[^@]+\.[^@]+")
class SurveyMailComposeMessage(models.TransientModel):
_name = 'survey.mail.compose.message'
_inherit = 'mail.compose.message'
......@@ -73,6 +77,11 @@ class SurveyMailComposeMessage(models.TransientModel):
#------------------------------------------------------
# Wizard validation and send
#------------------------------------------------------
@api.multi
def send_mail_action(self):
return self.send_mail()
@api.multi
def send_mail(self, auto_commit=False):
""" Process the wizard content and proceed with sending the related
......@@ -81,6 +90,7 @@ class SurveyMailComposeMessage(models.TransientModel):
SurveyUserInput = self.env['survey.user_input']
Partner = self.env['res.partner']
Mail = self.env['mail.mail']
notif_layout = self.env.context.get('notif_layout', self.env.context.get('custom_layout'))
def create_response_and_send_mail(wizard, token, partner_id, email):
""" Create one mail by recipients and replace __URL__ by link with identification token """
......@@ -106,6 +116,22 @@ class SurveyMailComposeMessage(models.TransientModel):
values['recipient_ids'] = [(4, partner_id)]
else:
values['email_to'] = email
# optional support of notif_layout in context
if notif_layout:
try:
template = self.env.ref(notif_layout, raise_if_not_found=True)
except ValueError:
_logger.warning('QWeb template %s not found when sending survey mails. Sending without layouting.' % (notif_layout))
else:
template_ctx = {
'message': self.env['mail.message'].sudo().new(dict(body=values['body_html'], record_name=wizard.survey_id.title)),
'model_description': self.env['ir.model']._get('survey.survey').display_name,
'company': self.env.user.company_id,
}
body = template.render(template_ctx, engine='ir.qweb', minimal_qcontext=True)
values['body_html'] = self.env['mail.thread']._replace_local_links(body)
Mail.create(values).send()
def create_token(wizard, partner_id, email):
......
......@@ -69,7 +69,7 @@
<button string="Close" class="btn-primary" special="cancel" />
</footer>
<footer attrs="{'invisible':['|',('public','=',False),('public','in',['public_link'])]}">
<button string="Send" name="send_mail" type="object" class="btn-primary" />
<button string="Send" name="send_mail_action" type="object" class="btn-primary" />
<button string="Cancel" class="btn-default" special="cancel" />
<group class="oe_right" col="1">
<div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment