[FIX][IMP] email_template view and preview button for wi

bzr revid: dhara@dhara-laptop-20100615060421-3346bwibul6kf2ig
This commit is contained in:
Dhara 2010-06-15 11:34:21 +05:30
parent 32c6c7993d
commit 0f3b579a54
3 changed files with 62 additions and 47 deletions

View File

@ -20,19 +20,17 @@
<newline />
<field name="subject" />
<newline />
<field name="body_text" />
<newline />
<!-- <field name="body_html" widget="text_html" />-->
<!--
Removed text_html because it doesnt work in GTK
And TinyMCE messes up the HTML in Web Client
-->
<field name="body_html"/>
<separator string= "Body(Text)" colspan="2"/>
<newline/>
<field name="body_text" nolabel="1" colspan="2"/>
<newline/>
<separator string= "Body(Html)" colspan="2"/>
<newline/>
<field name="body_html" nolabel="1" colspan="2"/>
<newline />
<field name="report" />
<group>
<button icon="gtk-ok" special="cancel" string="OK" />
</group>
<newline/>
<button icon="gtk-ok" special="cancel" string="OK" colspan="2"/>
</form>
</field>
</record>

View File

@ -27,6 +27,7 @@ from dateutil.relativedelta import relativedelta
from osv import fields, osv
import netsvc
import tools
from tools.translate import _
_intervalTypes = {
'hours': lambda interval: relativedelta(hours=interval),
@ -278,41 +279,6 @@ class marketing_campaign_activity(osv.osv):
print 'Sending Email Init', activity.name
return self.pool.get('email.template').generate_mail(cr, uid, activity.email_template_id.id, [workitem.res_id], context=context)
#if not template.enforce_from_account:
# self.pool.get('marketing.campaign.workitem').write(cr, uid, [workitem.id], {
# 'error_msg': 'There is no account defined for the email',
# 'state': 'exception'
# })
# return False
#if not workitem.partner_id.email:
# self.pool.get('marketing.campaign.workitem').write(cr, uid, [workitem.id], {
# 'error_msg': "There is no email defined for the partner",
# 'state': 'exception'
# })
# return False
#vals = {
# 'email_from': tools.ustr(accounts.name) + "<" + tools.ustr(accounts.email_id) + ">",
# 'email_to': template.email_to,
# 'email_cc': template.email_cc,
# 'email_bcc': template.email_bcc,
# 'subject': template.def_subject,
# 'body_text': template.def_body_text,
# 'body_html': template.def_body_html,
# 'account_id': accounts.id,
# 'state':'na',
# 'mail_type':'multipart/alternative' #Options:'multipart/mixed','multipart/alternative','text/plain','text/html'
#}
# # if accounts.use_sign:
# # signature = self.pool.get('res.users').read(cr, uid, uid, ['signature'], context)['signature']
# # if signature:
# # vals['pem_body_text'] = tools.ustr(vals['pem_body_text'] or '') + signature
# # vals['pem_body_html'] = tools.ustr(vals['pem_body_html'] or '') + signature
##Create partly the mail and later update attachments
#print 'Sending Email', vals
#mail_id = self.pool.get('email_template.mailbox').create(cr, uid, vals, context)
return True
def process_wi_action(self, cr, uid, activity, workitem, context={}):
context = {}
server_obj = self.pool.get('ir.actions.server')
@ -470,6 +436,42 @@ class marketing_campaign_workitem(osv.osv):
if workitem_ids:
self.process(cr, uid, workitem_ids, context)
def preview(self, cr, uid, ids, context):
res = {}
wi_obj = self.browse(cr, uid, ids)[0]
if wi_obj.activity_id.type == 'email':
data_obj = self.pool.get('ir.model.data')
data_id = data_obj._get_id(cr, uid, 'email_template', 'email_template_preview_form')
if data_id:
view_id = data_obj.browse(cr, uid, data_id, context=context).res_id
res = {
'name': _('Email Preview'),
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'email_template.preview',
'view_id': False,
'context': context,
'views': [(view_id, 'form')],
'type': 'ir.actions.act_window',
'target': 'new',
'nodestroy':True,
'context': "{'template_id':%d,'rel_model_ref':%d}"%
(wi_obj.activity_id.email_template_id.id,
wi_obj.res_id)
}
elif wi_obj.activity_id.type == 'paper':
datas = {'ids': [wi_obj.res_id],
'model': wi_obj.object_id.model}
res = {
'type' : 'ir.actions.report.xml',
'report_name': wi_obj.activity_id.report_id.report_name,
'datas' : datas,
'nodestroy': True,
}
return res
marketing_campaign_workitem()
class email_template(osv.osv):
@ -478,6 +480,21 @@ class email_template(osv.osv):
'object_name': lambda obj, cr, uid, context: context.get('object_id',False),
}
email_template()
class email_template_preview(osv.osv_memory):
_inherit = "email_template.preview"
def _default_rel_model(self, cr, uid, context=None):
if 'rel_model_ref' in context :
return context['rel_model_ref']
else :
return False
_defaults = {
'rel_model_ref' : _default_rel_model
}
email_template_preview()
class report_xml(osv.osv):
_inherit = 'ir.actions.report.xml'

View File

@ -289,7 +289,7 @@
<field name="email_template_id" attrs="{'required':[('type','=','email')]}" />
</group>
<group colspan="4" attrs="{'invisible':[('type','!=','paper')]}" >
<field name="report_id" attrs="{'required':[('type','=','paper')]}"/>
<field name="report_id" attrs="{'required':[('type','=','paper')]}" context="{'object_id':object_id}"/>
<field name="report_directory_id" attrs="{'required':[('type','=','paper')]}" />
</group>
<group colspan="4" attrs="{'invisible':[('type','!=','action')]}" >