def send_this_mail(self, cr, uid, ids=None, context=None):
result = True
+ attachment_pool = self.pool.get('ir.attachment')
for id in (ids or []):
try:
account_obj = self.pool.get('email_template.account')
payload = {}
if values['attachments_ids']:
for attid in values['attachments_ids']:
- attachment = self.pool.get('ir.attachment').browse(cr, uid, attid, context)#,['datas_fname','datas'])
+ attachment = attachment_pool.browse(cr, uid, attid, context)#,['datas_fname','datas'])
payload[attachment.datas_fname] = attachment.datas
result = account_obj.send_mail(cr, uid,
[values['account_id'][0]],
message_id=values['message_id'],
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)
+ account = account_obj.browse(cr, uid, values['account_id'][0], context=context)
+ if account.auto_delete:
+ self.write(cr, uid, id, {'folder': 'trash'}, context=context)
+ self.unlink(cr, uid, [id], context=context)
+ # Remove attachments for this mail
+ attachment_pool.unlink(cr, uid, values['attachments_ids'], context=context)
+ else:
+ 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:
error = result['error_msg']
self.historise(cr, uid, [id], error, context)