diff --git a/addons/account_product_template/account_product.py b/addons/account_product_template/account_product.py index 953e60f73aa..1fd28689b0d 100644 --- a/addons/account_product_template/account_product.py +++ b/addons/account_product_template/account_product.py @@ -26,20 +26,6 @@ class product_template(osv.osv): 'email_template_id': fields.many2one('email.template','Product Email Template'), } -class email_template(osv.osv): - _inherit = 'email.template' - - def default_get(self, cr, uid, fields, context=None): - res = super(email_template, self).default_get(cr, uid, fields, context) - if context.get('form_view_ref') == 'account_product_template.view_email_template_form_product': - res['email_from'] = '${(user.email)|safe}' - res['email_to'] = '${(object.partner_id.email)|safe}' - res['partner_to'] = '${object.partner_id.id}' - res['name'] = context.get('product_name') - res['subject'] = context.get('product_name') - res['model_id'] = self.pool.get('ir.model').search(cr, uid, [('model', '=', 'account.invoice')], context=context) - return res - class account_invoice(osv.Model): _inherit = 'account.invoice' @@ -47,20 +33,22 @@ class account_invoice(osv.Model): if context is None: context = {} mail_obj = self.pool.get('mail.compose.message') + template_obj = self.pool.get('email.template') res = super(account_invoice, self).invoice_validate(cr, uid, ids, context=context) - invoice = self.browse(cr, uid, ids[0], context=context) - for line in invoice.invoice_line: + for invoice in self.browse(cr, uid, ids, context=context): # fetch the partner's id and subscribe the partner to the invoice if invoice.partner_id.id not in invoice.message_follower_ids: self.message_subscribe(cr, uid, [invoice.id], [invoice.partner_id.id], context=context) - if line.product_id.email_template_id: - message_wiz_id = mail_obj.create(cr, uid, { - 'model': 'account.invoice', - 'res_id': ids[0], - 'template_id': line.product_id.email_template_id.id, - 'body': line.product_id.email_template_id.body_html - }, context=context) - mail_obj.send_mail(cr, uid, [message_wiz_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_obj.create(cr, uid, { + 'model': 'account.invoice', + 'res_id': invoice.id, + 'body': mail.body_html, + }, context=context) + mail_obj.send_mail(cr, uid, [message_wiz_id], context=context) return res # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/addons/account_product_template/account_product_template_demo.xml b/addons/account_product_template/account_product_template_demo.xml index 3835d33a766..c2d792c1479 100644 --- a/addons/account_product_template/account_product_template_demo.xml +++ b/addons/account_product_template/account_product_template_demo.xml @@ -4,9 +4,8 @@ Online Training ${(user.email or '')|safe} - ${object.partner_id.id} Online Training - + diff --git a/addons/account_product_template/account_product_view.xml b/addons/account_product_template/account_product_view.xml index 21045e03a07..848c67d4a5a 100644 --- a/addons/account_product_template/account_product_view.xml +++ b/addons/account_product_template/account_product_view.xml @@ -7,10 +7,6 @@ 100
- - - -

Body

@@ -23,7 +19,7 @@ - + diff --git a/addons/email_template/email_template.py b/addons/email_template/email_template.py index 8a16c01a156..36622c3ba14 100644 --- a/addons/email_template/email_template.py +++ b/addons/email_template/email_template.py @@ -213,6 +213,12 @@ class email_template(osv.osv): 'auto_delete': True, } + def default_get(self, cr, uid, fields, context=None): + res = super(email_template, self).default_get(cr, uid, fields, context) + if context.get('default_model'): + res['model_id'] = self.pool.get('ir.model').search(cr, uid, [('model', '=', context.get('default_model'))], context=context)[0] + return res + def create_action(self, cr, uid, ids, context=None): action_obj = self.pool.get('ir.actions.act_window') data_obj = self.pool.get('ir.model.data')