Skip to content

Commit

Permalink
Merge pull request #146 from gisce/afegir_i_millorar_assistent_previs…
Browse files Browse the repository at this point in the history
…ualitzacio

Mejoras y correcciones en el asistente para previsualizar el correo
  • Loading branch information
lcbautista authored Mar 20, 2024
2 parents 158d885 + aaae654 commit d832d3e
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 @@ -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,
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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',
Expand All @@ -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)
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 @@ -15,6 +15,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-ok" string="Generate Email" type="object"/>
</form>
Expand Down

0 comments on commit d832d3e

Please sign in to comment.