Skip to content

Commit

Permalink
Merge branch 'v5_backport' into 56615_mostrar_error_email
Browse files Browse the repository at this point in the history
  • Loading branch information
marcserranotouil authored Mar 21, 2024
2 parents 57bd8f7 + d832d3e commit 520423b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
23 changes: 23 additions & 0 deletions migrations/5.0.23.12.0/post-0002_update_poweremail_preview_view.py
Original file line number Diff line number Diff line change
@@ -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
32 changes: 30 additions & 2 deletions wizard/wizard_poweremail_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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,
Expand All @@ -44,10 +54,15 @@ def _ref_models(self, cursor, uid, context=None):
'body_html': fields.text('Body', readonly=True),
'report': fields.char('Report Name', size=100, readonly=True),
'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"
" this template, save them into the Drafts folder rather"
" than sending them immediately."),
}

_defaults = {
'state': lambda *a: 'init',
'save_to_drafts_prev': get_save_to_draft
}

def action_generate_static_mail(self, cr, uid, ids, context=None):
Expand Down Expand Up @@ -126,6 +141,16 @@ def action_send_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
Expand All @@ -134,10 +159,10 @@ def action_send_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',
Expand All @@ -147,6 +172,9 @@ def action_send_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)
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 @@ -16,6 +16,7 @@
<field name="subject" colspan="4"/>
<field name="body_text" colspan="4"/>
<field name="report" colspan="4"/>
<field name="save_to_drafts_prev" colspan="4"/>
<button icon="gtk-close" special="cancel" string="Close" />
<button name="action_generate_static_mail" icon="gtk-refresh" string="Preview Email" type="object"/>
<button name="action_send_static_mail" icon="send" string="Send Email" type="object"
Expand Down

0 comments on commit 520423b

Please sign in to comment.