summaryrefslogtreecommitdiff
path: root/addons/mail
diff options
context:
space:
mode:
authorXavierDo <xdo@odoo.com>2018-10-01 14:59:41 +0200
committerXavierDo <xdo@odoo.com>2018-10-02 13:07:02 +0200
commit775e8a9f2de3370e9947a612097ead65afd3b7ed (patch)
tree7402ad9dd3663fdef0c4e5f79754392a9b127d42 /addons/mail
parent64d7da419885301fa2c1b26bf3cde286052cefba (diff)
[FIX] mail: make guideline template a qweb view
The mail template mail_template_channel_send_guidelines should only be used from send_guidelines action. Anyway, with mail_template on activity and all demo done to show this mechanic on contacts, trying to render this one will generate a traceback. This fix transforms the mail_template to qweb view so that it won't be available in mail template.
Diffstat (limited to 'addons/mail')
-rw-r--r--addons/mail/data/mail_data.xml18
-rw-r--r--addons/mail/models/mail_channel.py20
2 files changed, 17 insertions, 21 deletions
diff --git a/addons/mail/data/mail_data.xml b/addons/mail/data/mail_data.xml
index 2f2d36f62f2..a664838b5a9 100644
--- a/addons/mail/data/mail_data.xml
+++ b/addons/mail/data/mail_data.xml
@@ -364,23 +364,15 @@
</div>
</template>
- <record id="mail_template_channel_send_guidelines" model="mail.template">
- <field name="name">Partner: Send channel guidelines</field>
- <field name="model_id" ref="base.model_res_partner"/>
- <field name="email_from">${object.company_id.catchall or object.company_id.email|safe}</field>
- <field name="partner_to">${object.id}</field>
- <field name="subject">Guidelines of channel ${ctx['channel'].name}</field>
- <field name="body_html" type="xml">
+ <template id="mail_channel_send_guidelines">
<div>
-<p>Hello ${object.name or ''},</p>
-<p>Please find below the guidelines of the ${ctx['channel'].name} channel.</p>
+<p>Hello <t t-esc="partner.name"/>,</p>
+<p>Please find below the guidelines of the <t t-esc="channel.name"/> channel.</p>
<p>
-${ctx['channel'].moderation_guidelines_msg}
+<t t-esc="channel.moderation_guidelines_msg"/>
</p>
<p></p>
</div>
-</field>
- <field name="user_signature" eval="False"/>
- </record>
+ </template>
</data>
</odoo>
diff --git a/addons/mail/models/mail_channel.py b/addons/mail/models/mail_channel.py
index d2a375f4fc9..3dcfb6f4436 100644
--- a/addons/mail/models/mail_channel.py
+++ b/addons/mail/models/mail_channel.py
@@ -425,7 +425,7 @@ class Channel(models.Model):
if self.env.user in self.moderator_ids or self.env.user.has_group('base.group_system'):
success = self._send_guidelines(self.channel_partner_ids)
if not success:
- raise UserError('Template "mail.mail_template_channel_send_guidelines" was not found. No email has been sent. Please contact an administrator to fix this issue.')
+ raise UserError('View "mail.mail_channel_send_guidelines" was not found. No email has been sent. Please contact an administrator to fix this issue.')
else:
raise UserError("Only an administrator or a moderator can send guidelines to channel members!")
@@ -434,19 +434,23 @@ class Channel(models.Model):
""" Send guidelines of a given channel. Returns False if template used for guidelines
not found. Caller may have to handle this return value. """
self.ensure_one()
- template = self.env.ref('mail.mail_template_channel_send_guidelines', raise_if_not_found=False)
- if not template:
- _logger.warning('Template "mail.mail_template_channel_send_guidelines" was not found.')
+ view = self.env.ref('mail.mail_channel_send_guidelines', raise_if_not_found=False)
+ if not view:
+ _logger.warning('View "mail.mail_channel_send_guidelines" was not found.')
return False
banned_emails = self.env['mail.moderation'].sudo().search([
('status', '=', 'ban'),
('channel_id', 'in', self.ids)
]).mapped('email')
for partner in partners.filtered(lambda p: p.email and not (p.email in banned_emails)):
- # the sudo is needed because because send_mail will create a message (a mail). As the template is
- # linked to res.partner model the current user could not have the rights to modify this model. It
- # means it could prevent users to create the mail.message necessary for the mail.mail.
- template.with_context(lang=partner.lang, channel=self).sudo().send_mail(partner.id)
+ create_values = {
+ 'body_html': view.render({'channel': self, 'partner': partner}, engine='ir.qweb', minimal_qcontext=True),
+ 'subject': "Guidelines of channel %s" % self.name,
+ 'email_from': partner.company_id.catchall or partner.company_id.email,
+ 'recipient_ids': [(4, partner.id)]
+ }
+ mail = self.env['mail.mail'].create(create_values)
+ mail.send()
return True
@api.multi