From 088d5e8dd3439752a32e06f77ae38cfee6dfb98b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Debauche?= Date: Mon, 17 May 2021 14:29:54 +0000 Subject: [PATCH] [IMP] survey: use new mail.composer.mixin Using this mixin allows to hide details about jinja-based computation for main fields used when posting messages or sending emails. Notably subject and body computation that was duplicated in several addons are now done in a mixin. It also eases their maintenance or evolution when qweb rendering will be available. It also eases support of lang when necessary. Task ID-2534550 (Template usage improvement) Task ID-2477164 (Composer mixin) COM PR odoo/odoo#70889 ENT PR odoo/enterprise#18352 UPG PR odoo/upgrade#2496 --- addons/survey/__manifest__.py | 2 +- addons/survey/wizard/survey_invite.py | 31 +++++--------------- addons/survey/wizard/survey_invite_views.xml | 1 + 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/addons/survey/__manifest__.py b/addons/survey/__manifest__.py index 12ec1e16e53..fdc1e41dfc5 100644 --- a/addons/survey/__manifest__.py +++ b/addons/survey/__manifest__.py @@ -2,7 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. { 'name': 'Surveys', - 'version': '3.3', + 'version': '3.4', 'category': 'Marketing/Surveys', 'description': """ Create beautiful surveys and visualize answers diff --git a/addons/survey/wizard/survey_invite.py b/addons/survey/wizard/survey_invite.py index 48cfabb8f26..c2366c997d3 100644 --- a/addons/survey/wizard/survey_invite.py +++ b/addons/survey/wizard/survey_invite.py @@ -15,6 +15,7 @@ emails_split = re.compile(r"[;,\n\r]+") class SurveyInvite(models.TransientModel): _name = 'survey.invite' + _inherit = 'mail.composer.mixin' _description = 'Survey Invitation Wizard' @api.model @@ -28,14 +29,9 @@ class SurveyInvite(models.TransientModel): return self.env.user.partner_id # composer content - subject = fields.Char('Subject', compute='_compute_subject', readonly=False, store=True) - body = fields.Html('Contents', sanitize_style=True, compute='_compute_body', readonly=False, store=True) attachment_ids = fields.Many2many( 'ir.attachment', 'survey_mail_compose_message_ir_attachments_rel', 'wizard_id', 'attachment_id', string='Attachments') - template_id = fields.Many2one( - 'mail.template', 'Use template', index=True, - domain="[('model', '=', 'survey.user_input')]") # origin email_from = fields.Char('From', default=_get_default_from, help="Email address of the sender.") author_id = fields.Many2one( @@ -106,6 +102,11 @@ class SurveyInvite(models.TransientModel): for invite in self: invite.survey_start_url = werkzeug.urls.url_join(base_url, invite.survey_id.get_start_url()) if invite.survey_id else False + # Overrides of mail.composer.mixin + @api.depends('survey_id') # fake trigger otherwise not computed in new mode + def _compute_render_model(self): + self.render_model = 'survey.user_input' + @api.onchange('emails') def _onchange_emails(self): if self.emails and (self.survey_users_login_required and not self.survey_id.users_can_signup): @@ -138,22 +139,6 @@ class SurveyInvite(models.TransientModel): ', '.join(invalid_partners.mapped('name')) )) - @api.depends('template_id') - def _compute_subject(self): - for invite in self: - if invite.template_id: - invite.subject = invite.template_id.subject - elif not invite.subject: - invite.subject = False - - @api.depends('template_id') - def _compute_body(self): - for invite in self: - if invite.template_id: - invite.body = invite.template_id.body_html - elif not invite.body: - invite.body = False - @api.model_create_multi def create(self, vals_list): for values in vals_list: @@ -210,8 +195,8 @@ class SurveyInvite(models.TransientModel): def _send_mail(self, answer): """ Create mail specific for recipient containing notably its access token """ - subject = self.env['mail.render.mixin'].with_context(safe=True)._render_template(self.subject, 'survey.user_input', answer.ids, post_process=True)[answer.id] - body = self.env['mail.render.mixin']._render_template(self.body, 'survey.user_input', answer.ids, post_process=True)[answer.id] + subject = self._render_field('subject', answer.ids, post_process=False)[answer.id] + body = self._render_field('body', answer.ids, post_process=True)[answer.id] # post the message mail_values = { 'email_from': self.email_from, diff --git a/addons/survey/wizard/survey_invite_views.xml b/addons/survey/wizard/survey_invite_views.xml index 1c2d66cc59c..bcd1e0b4c0d 100644 --- a/addons/survey/wizard/survey_invite_views.xml +++ b/addons/survey/wizard/survey_invite_views.xml @@ -13,6 +13,7 @@ +