Browse Source

base_export_email : Split send email to be able to use easily in other module

pull/115/head
Laetitia Gangloff 10 years ago
parent
commit
6333352165
  1. 35
      base_export_email/ir_actions.py

35
base_export_email/ir_actions.py

@ -35,8 +35,9 @@ class actions_server(orm.Model):
def __init__(self, pool, cr): def __init__(self, pool, cr):
super(actions_server, self).__init__(pool, cr) super(actions_server, self).__init__(pool, cr)
# add state 'export_email' # add state 'export_email'
self._columns['state'].selection.append(('export_email',
_('Export data by email')))
new_state = ('export_email', _('Export data by email'))
if new_state not in self._columns['state'].selection:
self._columns['state'].selection.append(new_state)
return return
_columns = { _columns = {
@ -114,7 +115,23 @@ class actions_server(orm.Model):
cr, uid, obj_ids, export_fields, cr, uid, obj_ids, export_fields,
context=context).get('datas', []) context=context).get('datas', [])
def _send_email(self, cr, uid, action, export_fields, export_data,
def _send_data_email(self, cr, uid, action, export_fields, export_data,
context=None):
"""
Prepare the exported data to send with the template
of the configuration
"""
if action.export_format == 'csv':
export = main.CSVExport()
else:
export = main.ExcelExport()
filename = export.filename(action.model)
content = export.from_data(export_fields, export_data)
return self._send_email(cr, uid, action, filename, content,
context=context)
def _send_email(self, cr, uid, action, filename, content,
context=None): context=None):
""" """
Prepare a message with the exported data to send with the Prepare a message with the exported data to send with the
@ -128,17 +145,15 @@ class actions_server(orm.Model):
(4, partner_id) for partner_id in values.pop('partner_ids', (4, partner_id) for partner_id in values.pop('partner_ids',
[]) [])
] ]
if action.export_format == 'csv':
export = main.CSVExport()
if context and context.get('encoded_base_64'):
data = content
else: else:
export = main.ExcelExport()
filename = export.filename(action.model)
content = export.from_data(export_fields, export_data)
if isinstance(content, unicode): if isinstance(content, unicode):
content = content.encode('utf-8') content = content.encode('utf-8')
data = base64.b64encode(str(content))
data_attach = { data_attach = {
'name': filename, 'name': filename,
'datas': base64.b64encode(str(content)),
'datas': data,
'datas_fname': filename, 'datas_fname': filename,
'description': filename, 'description': filename,
} }
@ -162,7 +177,7 @@ class actions_server(orm.Model):
cr, uid, obj_ids, action, context=context) cr, uid, obj_ids, action, context=context)
# Prepare a message with the exported data to send with the # Prepare a message with the exported data to send with the
# template of the configuration # template of the configuration
self._send_email(
self._send_data_email(
cr, uid, action, export_fields, export_data, cr, uid, action, export_fields, export_data,
context=context) context=context)
return super(actions_server, self).run(cr, uid, ids, context=context) return super(actions_server, self).run(cr, uid, ids, context=context)
Loading…
Cancel
Save