[IMP] account_product_template: cleaned code of email sending.
Now based on a composer, trigerring the onchange with the template, then sending the email. This replicates the email sending with the composer using a template. TODO: fix attachments not being send bzr revid: tde@openerp.com-20140124105406-09gndxy3izhdyq2n
This commit is contained in:
parent
79b36c68ee
commit
9478019191
|
@ -7,8 +7,7 @@ class account_invoice(osv.Model):
|
|||
_inherit = 'account.invoice'
|
||||
|
||||
def invoice_validate_send_email(self, cr, uid, ids, context=None):
|
||||
mail_msg_obj = self.pool['mail.compose.message']
|
||||
template_obj = self.pool['email.template']
|
||||
Composer = self.pool['mail.compose.message']
|
||||
for invoice in self.browse(cr, uid, ids, context=context):
|
||||
# send template only on customer invoice
|
||||
if invoice.type != 'out_invoice':
|
||||
|
@ -18,19 +17,21 @@ class account_invoice(osv.Model):
|
|||
self.message_subscribe(cr, uid, [invoice.id], [invoice.partner_id.id], context=context)
|
||||
for line in invoice.invoice_line:
|
||||
if line.product_id.email_template_id:
|
||||
template_res = template_obj.get_email_template_batch(cr, uid, template_id=line.product_id.email_template_id.id, res_ids=[line.product_id.product_tmpl_id.id], context=context)
|
||||
mail = template_res[line.product_id.product_tmpl_id.id]
|
||||
message_wiz_id = mail_msg_obj.create(cr, uid, {
|
||||
# CLEANME: should define and use a clean API: message_post with a template
|
||||
composer_id = Composer.create(cr, uid, {
|
||||
'model': 'account.invoice',
|
||||
'res_id': invoice.id,
|
||||
'body': mail.body_html,
|
||||
'template_id': line.product_id.email_template_id.id,
|
||||
'composition_mode': 'comment',
|
||||
}, context=context)
|
||||
mail_msg_obj.send_mail(cr, uid, [message_wiz_id], context=context)
|
||||
Composer.write(
|
||||
cr, uid, [composer_id],
|
||||
Composer.onchange_template_id(cr, uid, composer_id, line.product_id.email_template_id.id, 'comment', 'account.invoice', invoice.id)['value']
|
||||
)
|
||||
Composer.send_mail(cr, uid, [composer_id], context=context)
|
||||
return True
|
||||
|
||||
def invoice_validate(self, cr, uid, ids, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
res = super(account_invoice, self).invoice_validate(cr, uid, ids, context=context)
|
||||
self.invoice_validate_send_email(cr, uid, ids, context=context)
|
||||
return res
|
||||
|
|
Loading…
Reference in New Issue