[IMP] use product.template model for templates
bzr revid: tpa@tinyerp.com-20140123134233-vp52fv0e047bbfgk
This commit is contained in:
parent
a8d65e4fa9
commit
43ba81ad1b
|
@ -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,18 +33,20 @@ 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)
|
||||
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': ids[0],
|
||||
'template_id': line.product_id.email_template_id.id,
|
||||
'body': line.product_id.email_template_id.body_html
|
||||
'res_id': invoice.id,
|
||||
'body': mail.body_html,
|
||||
}, context=context)
|
||||
mail_obj.send_mail(cr, uid, [message_wiz_id], context=context)
|
||||
return res
|
||||
|
|
|
@ -4,9 +4,8 @@
|
|||
<record id="online_training_template" model="email.template">
|
||||
<field name="name">Online Training</field>
|
||||
<field name="email_from">${(user.email or '')|safe}</field>
|
||||
<field name="partner_to">${object.partner_id.id}</field>
|
||||
<field name="subject">Online Training</field>
|
||||
<field name="model_id" ref="account.model_account_invoice"/>
|
||||
<field name="model_id" ref="product.model_product_template"/>
|
||||
<field name="auto_delete" eval="True"/>
|
||||
<field name="body_html"><![CDATA[
|
||||
<html>
|
||||
|
|
|
@ -7,10 +7,6 @@
|
|||
<field name="priority">100</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Templates" version="7.0">
|
||||
<field name="email_from" invisible="1"/>
|
||||
<field name="partner_to" invisible="1"/>
|
||||
<field name="subject" invisible="1"/>
|
||||
<field name="model_id" invisible="1"/>
|
||||
<h3>Body</h3>
|
||||
<field name="body_html" placeholder="Rich-text/HTML content of the message (placeholders may be used here)"/>
|
||||
<field name="attachment_ids" nolabel="1" widget="many2many_binary"/>
|
||||
|
@ -23,7 +19,7 @@
|
|||
<field name="inherit_id" ref="product.product_normal_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="list_price" position="after">
|
||||
<field name="email_template_id" domain="[('model','=','account.invoice')]" context="{'form_view_ref':'account_product_template.view_email_template_form_product','product_name': name}"/>
|
||||
<field name="email_template_id" domain="[('model','=','product.template')]" context="{'form_view_ref':'account_product_template.view_email_template_form_product','default_model': 'product.template','default_subject': name, 'default_name': name}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue