From 2443f20c0e6e080c9aa42ffdc3317241e5e36b78 Mon Sep 17 00:00:00 2001 From: Ronaldo Cuentas Alave Date: Tue, 19 Mar 2024 16:21:43 +0100 Subject: [PATCH 1/3] add correccions i millores en la previsualitzacio --- wizard/wizard_poweremail_preview.py | 32 ++++++++++++++++++++++++++-- wizard/wizard_poweremail_preview.xml | 1 + 2 files changed, 31 insertions(+), 2 deletions(-) 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 @@ +