summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorTurkesh Patel (Open ERP) <tpa@tinyerp.com>2014-01-23 19:12:33 +0530
committerTurkesh Patel (Open ERP) <tpa@tinyerp.com>2014-01-23 19:12:33 +0530
commit43ba81ad1bfbbd35ad0c641dcfb05ab481eda75c (patch)
tree51e43a3b26234637357f5da5aa9ed6e5dc321d97 /addons
parenta8d65e4fa9c7fa598cd0cf79dfd46f453882eaad (diff)
[IMP] use product.template model for templates
bzr revid: tpa@tinyerp.com-20140123134233-vp52fv0e047bbfgk
Diffstat (limited to 'addons')
-rw-r--r--addons/account_product_template/account_product.py36
-rw-r--r--addons/account_product_template/account_product_template_demo.xml3
-rw-r--r--addons/account_product_template/account_product_view.xml6
-rw-r--r--addons/email_template/email_template.py6
4 files changed, 20 insertions, 31 deletions
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 @@
<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>
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 @@
<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>
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')