From 82cc2db1e08324b45b8c4af26a26c272d690f777 Mon Sep 17 00:00:00 2001 From: Gerard Parareda Date: Tue, 6 Aug 2024 12:40:26 +0200 Subject: [PATCH] IMP Allow env variables in template preview --- .../post-0002_update_preview_email_view.py | 16 ++++++++++++++++ poweremail_template.py | 4 +++- wizard/wizard_poweremail_preview.py | 10 +++++++--- wizard/wizard_poweremail_preview.xml | 1 + 4 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 migrations/5.0.24.9.0/post-0002_update_preview_email_view.py diff --git a/migrations/5.0.24.9.0/post-0002_update_preview_email_view.py b/migrations/5.0.24.9.0/post-0002_update_preview_email_view.py new file mode 100644 index 0000000..0e422d2 --- /dev/null +++ b/migrations/5.0.24.9.0/post-0002_update_preview_email_view.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +from oopgrade.oopgrade import load_data_records + + +def up(cursor, installed_version): + if not installed_version: + return + + load_data_records(cursor, 'poweremail', 'wizard/wizard_poweremail_preview.xml', ['poweremail_preview_form']) + + +def down(cursor, installed_version): + pass + + +migrate = up diff --git a/poweremail_template.py b/poweremail_template.py index c26dd65..ebaa2d2 100644 --- a/poweremail_template.py +++ b/poweremail_template.py @@ -186,7 +186,9 @@ def get_value(cursor, user, recid, message=None, template=None, context=None): context = {} ctx = context.copy() ctx['browse_reference'] = True - ctx['lang'] = context.get('lang', get_email_default_lang()) + ctx['lang'] = context.get('lang', False) + if not ctx['lang']: + ctx['lang'] = get_email_default_lang() object = pool.get(template.object_name.model).simple_browse(cursor, user, recid, context=ctx) env = context.copy() env.update({ diff --git a/wizard/wizard_poweremail_preview.py b/wizard/wizard_poweremail_preview.py index 0fc7f12..e91a68b 100644 --- a/wizard/wizard_poweremail_preview.py +++ b/wizard/wizard_poweremail_preview.py @@ -54,6 +54,7 @@ def get_save_to_draft(self, cursor, uid, context=None): 'body_text': fields.text('Body', readonly=True), 'body_html': fields.text('Body', readonly=True), 'report': fields.char('Report Name', size=100, readonly=True), + 'env': fields.text('Extra scope variables'), 'state': fields.selection([('init', 'Init'), ('end', 'End'), ('error', 'Error')], 'State'), 'save_to_drafts_prev': fields.boolean('Save to Drafts', help="When automatically sending emails generated from" @@ -67,7 +68,7 @@ def get_save_to_draft(self, cursor, uid, context=None): } def action_generate_static_mail(self, cr, uid, ids, context=None): - wizard_values = self.read(cr, uid, ids, ['model_ref'], context=context) + wizard_values = self.read(cr, uid, ids, ['model_ref', 'env'], context=context) if context is None: context = {} @@ -75,7 +76,8 @@ def action_generate_static_mail(self, cr, uid, ids, context=None): return {} vals = {} - model_name, record_id = wizard_values[0]['model_ref'].split(',') + wizard_values = wizard_values[0] + model_name, record_id = wizard_values['model_ref'].split(',') record_id = int(record_id) template = self.pool.get('poweremail.templates').browse(cr, uid, context['active_id'], context=context) # Search translated template @@ -87,7 +89,9 @@ def action_generate_static_mail(self, cr, uid, ids, context=None): template = self.pool.get('poweremail.templates').browse(cr, uid, context['active_id'], ctx) mail_fields = ['to', 'cc', 'bcc', 'subject', 'body_text', 'body_html', 'report'] - ctx.update({'raise_exception': True}) + ctx['raise_exception'] = True + if wizard_values['env']: + ctx.update(eval(wizard_values['env'])) for field in mail_fields: try: if field == 'report': diff --git a/wizard/wizard_poweremail_preview.xml b/wizard/wizard_poweremail_preview.xml index ea6dc85..48a5a8d 100644 --- a/wizard/wizard_poweremail_preview.xml +++ b/wizard/wizard_poweremail_preview.xml @@ -14,6 +14,7 @@ +