diff --git a/migrations/5.0.23.12.0/post-0002_update_poweremail_preview_view.py b/migrations/5.0.23.12.0/post-0002_update_poweremail_preview_view.py
new file mode 100644
index 0000000..5f32126
--- /dev/null
+++ b/migrations/5.0.23.12.0/post-0002_update_poweremail_preview_view.py
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+import logging
+import pooler
+from oopgrade.oopgrade import load_data, load_data_records
+
+
+def up(cursor, installed_version):
+ if not installed_version:
+ return
+ pool = pooler.get_pool(cursor.dbname)
+ logger = logging.getLogger('openerp.migration')
+
+ pool.get("poweremail.preview")._auto_init(cursor, context={'module': 'poweremail'})
+ logger.info("Updating XML wizard_poweremail_preview.xml")
+ load_data_records(
+ cursor, 'poweremail', 'wizard/wizard_poweremail_preview.xml', ['poweremail_preview_form'], mode='update')
+ logger.info("XMLs succesfully updated.")
+
+
+def down(cursor, installed_version):
+ pass
+
+migrate = up
diff --git a/wizard/wizard_poweremail_preview.py b/wizard/wizard_poweremail_preview.py
index 16ca6e3..2109ae8 100644
--- a/wizard/wizard_poweremail_preview.py
+++ b/wizard/wizard_poweremail_preview.py
@@ -28,6 +28,16 @@ def _ref_models(self, cursor, uid, context=None):
return res
+ def get_save_to_draft(self, cursor, uid, context=None):
+ template_obj = self.pool.get('poweremail.templates')
+
+ if not context:
+ context = {}
+ template_ids = context.get('active_ids', [])
+
+ res = template_obj.read(cursor, uid, template_ids, ['save_to_drafts'])[0]['save_to_drafts']
+ return res
+
_columns = {
'model_ref': fields.reference(
"Template reference", selection=_ref_models,
@@ -40,11 +50,16 @@ def _ref_models(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),
+ 'save_to_drafts_prev': fields.boolean('Save to Drafts',
+ help="When automatically sending emails generated from"
+ " this template, save them into the Drafts folder rather"
+ " than sending them immediately."),
'state': fields.selection([('init', 'Init'), ('end', 'End')], 'State'),
}
_defaults = {
'state': lambda *a: 'init',
+ 'save_to_drafts_prev': get_save_to_draft
}
def on_change_ref(self, cr, uid, ids, model_ref, context=None):
@@ -109,6 +124,16 @@ def action_generate_static_mail(self, cursor, uid, ids, context=None):
# message: The expression to be evaluated
# template: BrowseRecord object of the current template
# return: Computed message (unicode) or u""
+
+ pem_too = get_value(
+ cursor, uid, model_id, message=template.def_to,
+ template=template, context=context
+ )
+ def_subject = get_value(
+ cursor, uid, model_id, message=template.def_subject,
+ template=template, context=context
+ )
+
body_text = get_value(
cursor, uid, model_id, message=template.def_body_text,
template=template, context=context
@@ -117,10 +142,10 @@ def action_generate_static_mail(self, cursor, uid, ids, context=None):
mail_vals = {
'pem_from': tools.ustr(from_account['name']) + \
"<" + tools.ustr(from_account['email_id']) + ">",
- 'pem_to': template.def_to,
+ 'pem_to': pem_too,
'pem_cc': False,
'pem_bcc': False,
- 'pem_subject': template.name,
+ 'pem_subject': def_subject,
'pem_body_text': body_text,
'pem_account_id': from_account['id'],
'priority': '1',
@@ -130,6 +155,9 @@ def action_generate_static_mail(self, cursor, uid, ids, context=None):
}
mailbox_id = mailbox_obj.create(cursor, uid, mail_vals)
+ if wizard.save_to_drafts_prev:
+ mailbox_obj.write(cursor, uid, mailbox_id, {'folder': 'drafts'}, context=context)
+
mailbox_ids.append(mailbox_id)
wizard.write({'state': 'end'}, context=context)
diff --git a/wizard/wizard_poweremail_preview.xml b/wizard/wizard_poweremail_preview.xml
index 9479075..847c9ec 100644
--- a/wizard/wizard_poweremail_preview.xml
+++ b/wizard/wizard_poweremail_preview.xml
@@ -15,6 +15,7 @@
+