Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow env variables in template preview #166

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions migrations/5.0.24.9.0/post-0002_update_preview_email_view.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion poweremail_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
10 changes: 7 additions & 3 deletions wizard/wizard_poweremail_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -67,15 +68,16 @@ 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 = {}
if not wizard_values:
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
Expand All @@ -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':
Expand Down
1 change: 1 addition & 0 deletions wizard/wizard_poweremail_preview.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<field name="cc" colspan="2"/>
<field name="bcc" colspan="2"/>
<field name="subject" colspan="4"/>
<field name="env" colspan="4" widget="codeeditor" widget_props="{'lang': 'json'}" height="100"/>
<notebook>
<page string="Body preview">
<field name="body_text" colspan="4" widget="html_preview" nolabel="1"/>
Expand Down