[FIX] email_tempalte : view and error on email

bzr revid: dhara@dhara-laptop-20100624105226-4n11kv5289wnt96p
This commit is contained in:
Dhara 2010-06-24 16:22:26 +05:30
parent ab6882dc3c
commit e2a068e03f
4 changed files with 36 additions and 35 deletions

View File

@ -108,7 +108,8 @@ class email_template(osv.osv):
'enforce_from_account':fields.many2one(
'email_template.account',
string="Enforce From Account",
help="Emails will be sent only from this account."),
help="Emails will be sent only from this account(which are approved).",
domain=[('state','=','approved')]),
'from_email' : fields.related('enforce_from_account', 'email_id',
type='char', string='From',),
'def_to':fields.char(
@ -580,8 +581,8 @@ class email_template(osv.osv):
context)
print 'Sending', mailbox_id
self.pool.get('email_template.mailbox').send_this_mail(cursor, user, [mailbox_id], context)
return mailbox_id
def generate_mail(self,
cursor,
@ -595,6 +596,7 @@ class email_template(osv.osv):
if not template:
raise Exception("The requested template could not be loaded")
print 'loaded', record_ids
result = True
for record_id in record_ids:
mailbox_id = self._generate_mailbox_item_from_template(
cursor,
@ -625,7 +627,9 @@ class email_template(osv.osv):
{'folder':'outbox'},
context=context
)
return True
# TODO : manage return value of all the records
result = self.pool.get('email_template.mailbox').send_this_mail(cursor, user, [mailbox_id], context)
return result
email_template()
@ -641,7 +645,7 @@ class email_template_preview(osv.osv_memory):
if 'template_id' in context.keys():
ref_obj_id = self.pool.get('email.template').read(cr, uid, context['template_id'], ['object_name'], context)
ref_obj_name = self.pool.get('ir.model').read(cr, uid, ref_obj_id['object_name'][0], ['model'], context)['model']
ref_obj_ids = self.pool.get(ref_obj_name).search(cr, uid, [], context=context)
ref_obj_ids = self.pool.get(ref_obj_name).search(cr, uid, [], 0, 20, 'id desc', context=context)
ref_obj_recs = self.pool.get(ref_obj_name).name_get(cr, uid, ref_obj_ids, context)
return ref_obj_recs

View File

@ -266,7 +266,7 @@ class email_template_account(osv.osv):
return result
def send_mail(self, cr, uid, ids, addresses, subject='', body=None, payload=None, context=None):
#TODO: Replace all this crap with a single email object
#TODO: Replace all this with a single email object
if body is None:
body = {}
if payload is None:
@ -320,19 +320,20 @@ class email_template_account(osv.osv):
msg.attach(part)
except Exception, error:
logger.notifyChannel(_("Email Template"), netsvc.LOG_ERROR, _("Mail from Account %s failed. Probable Reason:MIME Error\nDescription: %s") % (id, error))
return error
return {'error_msg': "Server Send Error\nDescription: %s"%error}
try:
#print msg['From'],toadds
serv.sendmail(msg['From'], addresses_l['all'], msg.as_string())
except Exception, error:
logger.notifyChannel(_("Email Template"), netsvc.LOG_ERROR, _("Mail from Account %s failed. Probable Reason:Server Send Error\nDescription: %s") % (id, error))
return error
return {'error_msg': "Server Send Error\nDescription: %s"%error}
#The mail sending is complete
serv.close()
logger.notifyChannel(_("Email Template"), netsvc.LOG_INFO, _("Mail from Account %s successfully Sent.") % (id))
return True
else:
logger.notifyChannel(_("Email Template"), netsvc.LOG_ERROR, _("Mail from Account %s failed. Probable Reason:Account not approved") % id)
return {'error_msg':"Mail from Account %s failed. Probable Reason:Account not approved"% id}
def extracttime(self, time_as_string):
"""
@ -394,7 +395,6 @@ class email_template_account(osv.osv):
return date_as_date
def send_receive(self, cr, uid, ids, context=None):
self.get_mails(cr, uid, ids, context)
for id in ids:
ctx = context.copy()
ctx['filters'] = [('account_id', '=', id)]

View File

@ -56,18 +56,19 @@ class email_template_mailbox(osv.osv):
values['subject'] or u'',
{'text':values.get('body_text', u'') or u'', 'html':values.get('body_html', u'') or u''},
payload=payload, context=context)
if result == True:
self.write(cr, uid, id, {'folder':'sent', 'state':'na', 'date_mail':time.strftime("%Y-%m-%d %H:%M:%S")}, context)
self.historise(cr, uid, [id], "Email sent successfully", context)
else:
self.historise(cr, uid, [id], result, context)
error = result['error_msg']
self.historise(cr, uid, [id], error, context)
except Exception, error:
logger = netsvc.Logger()
logger.notifyChannel(_("Power Email"), netsvc.LOG_ERROR, _("Sending of Mail %s failed. Probable Reason:Could not login to server\nError: %s") % (id, error))
self.historise(cr, uid, [id], error, context)
self.write(cr, uid, id, {'state':'na'}, context)
return True
return result
def historise(self, cr, uid, ids, message='', context=None):
for id in ids:

View File

@ -8,33 +8,29 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Email Preview">
<field name="rel_model" />
<newline />
<field name="rel_model_ref" on_change="on_change_ref(rel_model_ref, context)" />
<newline />
<field name="to" />
<newline />
<field name="cc" />
<newline />
<field name="bcc" />
<newline />
<field name="subject" />
<newline />
<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" />
<newline/>
<button icon="gtk-ok" special="cancel" string="OK" colspan="2"/>
<group col="4" colspan="4">
<field name="rel_model" />
<field name="rel_model_ref" on_change="on_change_ref(rel_model_ref, context)"/>
</group>
<group col="8" colspan="4">
<field name="to" />
<field name="cc" />
<field name="bcc" />
<field name="subject" />
</group>
<group col="4" colspan="4">
<separator string= "Body(Text)" colspan="2"/>
<separator string= "Body(Html)" colspan="2"/>
<newline/>
<field name="body_text" nolabel="1" colspan="2"/>
<field name="body_html" nolabel="1" colspan="2"/>
</group>
<field name="report" colspan="2"/>
<button icon="gtk-ok" special="cancel" string="OK" colspan="1"/>
</form>
</field>
</record>
<record id="wizard_email_template_preview" model="ir.actions.act_window">
<field name="name">Template Preview</field>
<field name="res_model">email_template.preview</field>