diff options
| author | ryv-odoo <ryv@odoo.com> | 2019-10-11 14:39:25 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2019-12-02 10:51:02 +0000 |
| commit | 47ff160b422ac317a5cdca19edfba42c4889656d (patch) | |
| tree | 1658c666e1c8a2e1fd895c9a073795d632e38b50 /addons/mail/wizard/email_template_preview.py | |
| parent | 2b4e172c6f686c0c577d4a1b1d99b65b721ed900 (diff) | |
[REF] mail: improve and refactor mail template preview
PURPOSE
Improve mail template preview wizard by improve its views and displaying
more rendered fields. It helps users knowing what will be sent to customers.
SPECIFICATIONS
Rename template model to mail_template_preview to better match the mail
template namespace.
Remove _inherit on mail.template and instead choose fields to compute
and display. Indeed lot of fields are unnecessary or badly computed.
Instead just add fields on the wizard that depends on mail template
and will be computed based on mail_template_id field of wizard.
Improve error management.
LINKS
Task 2085912
PR #38708
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons/mail/wizard/email_template_preview.py')
| -rw-r--r-- | addons/mail/wizard/email_template_preview.py | 58 |
1 files changed, 0 insertions, 58 deletions
diff --git a/addons/mail/wizard/email_template_preview.py b/addons/mail/wizard/email_template_preview.py deleted file mode 100644 index 57e0b4d3fec..00000000000 --- a/addons/mail/wizard/email_template_preview.py +++ /dev/null @@ -1,58 +0,0 @@ -# -*- coding: utf-8 -*- -# Part of Odoo. See LICENSE file for full copyright and licensing details. - -from odoo import api, fields, models - - -class TemplatePreview(models.TransientModel): - _inherit = "mail.template" - _name = "email_template.preview" - _description = "Email Template Preview" - - @api.model - def _get_records(self): - """ Return Records of particular Email Template's Model """ - template_id = self._context.get('template_id') - default_res_id = self._context.get('default_res_id') - if not template_id: - return [] - template = self.env['mail.template'].browse(int(template_id)) - records = self.env[template.model_id.model].search([], order="id desc", limit=10) - records |= records.browse(default_res_id) - return records.name_get() - - @api.model - def _get_languages(self): - return self.env['res.lang'].get_installed() - - @api.model - def default_get(self, fields): - result = super(TemplatePreview, self).default_get(fields) - - template = self._context.get('template_id') and self.env['mail.template'].browse(self._context['template_id']) or False - if 'res_id' in fields and not result.get('res_id'): - records = self._get_records() - result['res_id'] = records and records[0][0] or False # select first record as a Default - if template and 'model_id' in fields and not result.get('model_id'): - result['model_id'] = template.model_id.id - if template and 'preview_lang' in fields and not result.get('preview_lang') and result.get('res_id'): - result['preview_lang'] = template.lang and template.generate_email(result['res_id'], ['lang'])['lang'] or template._context.get('lang') - return result - - res_id = fields.Selection(_get_records, 'Sample Document') - partner_ids = fields.Many2many('res.partner', string='Recipients') - attachment_ids = fields.Many2many(string='Attachments', store=False) - preview_lang = fields.Selection(_get_languages, string='Template Preview Language') - - @api.onchange('res_id', 'preview_lang') - def on_change_res_id(self): - if not self.res_id: - return {} - mail_values = {} - if self._context.get('template_id'): - template = self.env['mail.template'].browse(self._context['template_id']) - self.name = template.name - mail_values = template.with_context(template_preview_lang=self.preview_lang).generate_email( - self.res_id, ['subject', 'body_html', 'email_from', 'email_to', 'partner_to', 'email_cc', 'reply_to', 'scheduled_date']) - for field in ['email_from', 'email_to', 'email_cc', 'reply_to', 'subject', 'body_html', 'partner_to', 'partner_ids', 'attachment_ids']: - setattr(self, field, mail_values.get(field, False)) |
