diff --git a/addons/mail/models/mail_render_mixin.py b/addons/mail/models/mail_render_mixin.py index c2fafe1d56e..eb5bcbef882 100644 --- a/addons/mail/models/mail_render_mixin.py +++ b/addons/mail/models/mail_render_mixin.py @@ -3,28 +3,28 @@ from odoo import api, fields, models -class MailRenderMixin(models.AbstractModel): +class MailRenderMixin(models.AbstractModel): _name = 'mail.render.mixin' _description = 'Mail Render Mixin' model_object_field = fields.Many2one( 'ir.model.fields', string="Field", store=False, help="Select target field from the related document model.\n" - "If it is a relationship field you will be able to select " - "a target field at the destination of the relationship.") + "If it is a relationship field you will be able to select " + "a target field at the destination of the relationship.") sub_object = fields.Many2one( 'ir.model', 'Sub-model', readonly=True, store=False, help="When a relationship field is selected as first field, " - "this field shows the document model the relationship goes to.") + "this field shows the document model the relationship goes to.") sub_model_object_field = fields.Many2one( 'ir.model.fields', 'Sub-field', store=False, help="When a relationship field is selected as first field, " - "this field lets you select the target field within the " - "destination document model (sub-model).") + "this field lets you select the target field within the " + "destination document model (sub-model).") null_value = fields.Char('Default Value', store=False, help="Optional value to use if the target field is empty") copyvalue = fields.Char( - 'Placeholder Expression',store=False, + 'Placeholder Expression', store=False, help="Final placeholder expression, to be copy-pasted in the desired template field.") @api.onchange('model_object_field', 'sub_model_object_field', 'null_value') @@ -65,4 +65,4 @@ class MailRenderMixin(models.AbstractModel): if null_value: expression += " or '''%s'''" % null_value expression += "}" - return expression + return expression diff --git a/addons/mail/models/mail_template.py b/addons/mail/models/mail_template.py index 43082e2d47b..466d5bbf8eb 100644 --- a/addons/mail/models/mail_template.py +++ b/addons/mail/models/mail_template.py @@ -91,6 +91,7 @@ class MailTemplate(models.Model): res['model_id'] = self.env['ir.model']._get(res.pop('model')).id return res + # description name = fields.Char('Name') model_id = fields.Many2one('ir.model', 'Applies to', help="The type of document this template can be used with") model = fields.Char('Related Document Model', related='model_id.model', index=True, store=True, readonly=True) @@ -105,6 +106,7 @@ class MailTemplate(models.Model): email_from = fields.Char('From', help="Sender address (placeholders may be used here). If not set, the default " "value will be the author's email alias if configured, or email address.") + # recipients use_default_to = fields.Boolean( 'Default recipients', help="Default recipients of the record:\n" @@ -115,32 +117,28 @@ class MailTemplate(models.Model): help="Comma-separated ids of recipient partners (placeholders may be used here)") email_cc = fields.Char('Cc', help="Carbon copy recipients (placeholders may be used here)") reply_to = fields.Char('Reply-To', help="Preferred response address (placeholders may be used here)") - mail_server_id = fields.Many2one('ir.mail_server', 'Outgoing Mail Server', readonly=False, - help="Optional preferred server for outgoing mails. If not set, the highest " - "priority one will be used.") + # content body_html = fields.Html('Body', translate=True, sanitize=False) - report_name = fields.Char('Report Filename', translate=True, - help="Name to use for the generated report file (may contain placeholders)\n" - "The extension can be omitted and will then come from the report type.") - report_template = fields.Many2one('ir.actions.report', 'Optional report to print and attach') - ref_ir_act_window = fields.Many2one('ir.actions.act_window', 'Sidebar action', readonly=True, copy=False, - help="Sidebar action to make this template available on records " - "of the related document model") attachment_ids = fields.Many2many('ir.attachment', 'email_template_attachment_rel', 'email_template_id', 'attachment_id', 'Attachments', help="You may attach files to this template, to be added to all " "emails created from this template") - auto_delete = fields.Boolean('Auto Delete', default=True, help="This option permanently removes any track of email after send, including from the Technical menu in the Settings, in order to preserve storage space of your Odoo database.") - + report_name = fields.Char('Report Filename', translate=True, + help="Name to use for the generated report file (may contain placeholders)\n" + "The extension can be omitted and will then come from the report type.") + report_template = fields.Many2one('ir.actions.report', 'Optional report to print and attach') + # options + mail_server_id = fields.Many2one('ir.mail_server', 'Outgoing Mail Server', readonly=False, + help="Optional preferred server for outgoing mails. If not set, the highest " + "priority one will be used.") scheduled_date = fields.Char('Scheduled Date', help="If set, the queue manager will send the email after the date. If not set, the email will be send as soon as possible. Jinja2 placeholders may be used.") - - @api.onchange('model_id') - def onchange_model_id(self): - # TDE CLEANME: should'nt it be a stored related ? - if self.model_id: - self.model = self.model_id.model - else: - self.model = False + auto_delete = fields.Boolean( + 'Auto Delete', default=True, + help="This option permanently removes any track of email after send, including from the Technical menu in the Settings, in order to preserve storage space of your Odoo database.") + # contextual action + ref_ir_act_window = fields.Many2one('ir.actions.act_window', 'Sidebar action', readonly=True, copy=False, + help="Sidebar action to make this template available on records " + "of the related document model") def unlink(self): self.unlink_action() @@ -178,9 +176,9 @@ class MailTemplate(models.Model): return True - # ---------------------------------------- + # ------------------------------------------------------------ # RENDERING - # ---------------------------------------- + # ------------------------------------------------------------ @api.model def render_post_process(self, html): @@ -246,6 +244,10 @@ class MailTemplate(models.Model): return multi_mode and results or results[res_ids[0]] + # ------------------------------------------------------------ + # MESSAGE/EMAIL VALUES GENERATION + # ------------------------------------------------------------ + def get_email_template(self, res_ids): multi_mode = True if isinstance(res_ids, int): @@ -393,9 +395,9 @@ class MailTemplate(models.Model): return multi_mode and results or results[res_ids[0]] - # ---------------------------------------- + # ------------------------------------------------------------ # EMAIL - # ---------------------------------------- + # ------------------------------------------------------------ def _send_check_access(self, res_ids): records = self.env[self.model].browse(res_ids) diff --git a/addons/sms/models/sms_template.py b/addons/sms/models/sms_template.py index d09dd26a703..46c8841dc2a 100644 --- a/addons/sms/models/sms_template.py +++ b/addons/sms/models/sms_template.py @@ -38,6 +38,10 @@ class SMSTemplate(models.Model): name=_("%s (copy)") % self.name) return super(SMSTemplate, self).copy(default=default) + def unlink(self): + self.sudo().mapped('sidebar_action_id').unlink() + return super(SMSTemplate, self).unlink() + def action_create_sidebar_action(self): ActWindow = self.env['ir.actions.act_window'] view = self.env.ref('sms.sms_composer_view_form') @@ -64,6 +68,10 @@ class SMSTemplate(models.Model): template.sidebar_action_id.unlink() return True + # ------------------------------------------------------------ + # RENDERING + # ------------------------------------------------------------ + def _get_context_lang_per_id(self, res_ids): self.ensure_one() if res_ids is None: @@ -74,7 +82,8 @@ class SMSTemplate(models.Model): results = dict((res_id, self.with_context(lang=lang)) for res_id in res_ids) else: rendered_langs = self._render_template(self.lang, self.model, res_ids) - results = dict((res_id, self.with_context(lang=lang) if lang else self) + results = dict( + (res_id, self.with_context(lang=lang) if lang else self) for res_id, lang in rendered_langs.items()) return results @@ -103,7 +112,3 @@ class SMSTemplate(models.Model): def _render_template(self, template_txt, model, res_ids): """ Render the jinja template """ return self.env['mail.template']._render_template(template_txt, model, res_ids) - - def unlink(self): - self.sudo().mapped('sidebar_action_id').unlink() - return super(SMSTemplate, self).unlink()