[IMP] edi,email_template: allow directly sending EDI emails notification without queuing

bzr revid: odo@openerp.com-20111103020803-woh1ydv1z0okfp3i
This commit is contained in:
Olivier Dony 2011-11-03 03:08:03 +01:00
parent 6860e3381c
commit 61eb5220a9
2 changed files with 16 additions and 7 deletions

View File

@ -155,6 +155,8 @@ class edi_document(osv.osv):
model = edi_document.get('__import_model') or edi_document.get('__model')
assert model, 'a `__model` or `__import_model` attribute is required in each EDI document'
model_obj = self.pool.get(model)
assert model_obj, 'model `%s` cannot be found, despite module `%s` being available - '\
'this EDI document seems invalid or unsupported' % (model,module)
record_id = model_obj.edi_import(cr, uid, edi_document, context=context)
res.append((model, record_id))
return res
@ -454,7 +456,8 @@ class EDIMixin(object):
for edi_record in self.browse(local_cr, uid, ids, context=context):
edi_token = self.pool.get('edi.document').export_edi(local_cr, uid, [edi_record], context = context)[0]
edi_context = dict(context, edi_web_url_view=EDI_VIEW_WEB_URL % (web_root_url, local_cr.dbname, edi_token))
self.pool.get('email.template').send_mail(local_cr, uid, mail_tmpl.id, edi_record.id, context=edi_context)
self.pool.get('email.template').send_mail(local_cr, uid, mail_tmpl.id, edi_record.id,
force_send=True, context=edi_context)
except Exception:
_logger.warning('Ignoring EDI mail notification, failed to generate it.', exc_info=True)
finally:

View File

@ -361,20 +361,24 @@ class email_template(osv.osv):
values['attachments'] = attachments
return values
def send_mail(self, cr, uid, template_id, res_id, context=None):
def send_mail(self, cr, uid, template_id, res_id, force_send=False, context=None):
"""Generates a new mail message for the given template and record,
and schedule it for delivery through the ``mail`` module's scheduler.
and schedules it for delivery through the ``mail`` module's scheduler.
:param int template_id: id of the template to render
:param int res_id: id of the record to render the template with
(model is taken from the template)
:param bool force_send: if True, the generated mail.message is
immediately sent after being created, as if the scheduler
was executed for this message only.
:returns: id of the mail.message that was created
"""
mail_message = self.pool.get('mail.message')
ir_attachment = self.pool.get('ir.attachment')
template = self.browse(cr, uid, template_id, context)
values = self.generate_email(cr, uid, template_id, res_id, context=context)
attachments = values.pop('attachments') or {}
message_id = mail_message.create(cr, uid, values, context=context)
msg_id = mail_message.create(cr, uid, values, context=context)
# link attachments
attachment_ids = []
for fname, fcontent in attachments.iteritems():
@ -383,11 +387,13 @@ class email_template(osv.osv):
'datas_fname': fname,
'datas': fcontent,
'res_model': mail_message._name,
'res_id': message_id,
'res_id': msg_id,
}
if context.has_key('default_type'):
del context['default_type']
attachment_ids.append(ir_attachment.create(cr, uid, attachment_data, context))
return message_id
attachment_ids.append(ir_attachment.create(cr, uid, attachment_data, context=context))
if force_send:
mail_message.send(cr, uid, [msg_id], context=context)
return msg_id
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: