[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.
This commit is contained in:
XavierDo
2018-10-02 13:07:02 +02:00
parent 64d7da4198
commit 775e8a9f2d
2 changed files with 17 additions and 21 deletions
+5 -13
View File
@@ -364,23 +364,15 @@
</div> </div>
</template> </template>
<record id="mail_template_channel_send_guidelines" model="mail.template"> <template id="mail_channel_send_guidelines">
<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">
<div> <div>
<p>Hello ${object.name or ''},</p> <p>Hello <t t-esc="partner.name"/>,</p>
<p>Please find below the guidelines of the ${ctx['channel'].name} channel.</p> <p>Please find below the guidelines of the <t t-esc="channel.name"/> channel.</p>
<p> <p>
${ctx['channel'].moderation_guidelines_msg} <t t-esc="channel.moderation_guidelines_msg"/>
</p> </p>
<p></p> <p></p>
</div> </div>
</field> </template>
<field name="user_signature" eval="False"/>
</record>
</data> </data>
</odoo> </odoo>
+12 -8
View File
@@ -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'): 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) success = self._send_guidelines(self.channel_partner_ids)
if not success: 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: else:
raise UserError("Only an administrator or a moderator can send guidelines to channel members!") 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 """ Send guidelines of a given channel. Returns False if template used for guidelines
not found. Caller may have to handle this return value. """ not found. Caller may have to handle this return value. """
self.ensure_one() self.ensure_one()
template = self.env.ref('mail.mail_template_channel_send_guidelines', raise_if_not_found=False) view = self.env.ref('mail.mail_channel_send_guidelines', raise_if_not_found=False)
if not template: if not view:
_logger.warning('Template "mail.mail_template_channel_send_guidelines" was not found.') _logger.warning('View "mail.mail_channel_send_guidelines" was not found.')
return False return False
banned_emails = self.env['mail.moderation'].sudo().search([ banned_emails = self.env['mail.moderation'].sudo().search([
('status', '=', 'ban'), ('status', '=', 'ban'),
('channel_id', 'in', self.ids) ('channel_id', 'in', self.ids)
]).mapped('email') ]).mapped('email')
for partner in partners.filtered(lambda p: p.email and not (p.email in banned_emails)): 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 create_values = {
# linked to res.partner model the current user could not have the rights to modify this model. It 'body_html': view.render({'channel': self, 'partner': partner}, engine='ir.qweb', minimal_qcontext=True),
# means it could prevent users to create the mail.message necessary for the mail.mail. 'subject': "Guidelines of channel %s" % self.name,
template.with_context(lang=partner.lang, channel=self).sudo().send_mail(partner.id) '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 return True
@api.multi @api.multi