diff --git a/addons/email_template/email_template_account.py b/addons/email_template/email_template_account.py index 1a1b6db0c4e..3f049eea5df 100644 --- a/addons/email_template/email_template_account.py +++ b/addons/email_template/email_template_account.py @@ -81,6 +81,9 @@ class email_template_account(osv.osv): size=64, required=True, readonly=True, select=True, states={'draft':[('readonly', False)]}), + 'auto_delete': fields.boolean('Auto Delete', size=64, readonly=True, + help="Permanently delete emails after sending", + states={'draft':[('readonly', False)]}), 'user':fields.many2one('res.users', 'Related User', required=True, readonly=True, states={'draft':[('readonly', False)]}), diff --git a/addons/email_template/email_template_account_view.xml b/addons/email_template/email_template_account_view.xml index a73fc075c73..3234589fcfb 100644 --- a/addons/email_template/email_template_account_view.xml +++ b/addons/email_template/email_template_account_view.xml @@ -12,8 +12,9 @@ form
- + + diff --git a/addons/email_template/email_template_mailbox.py b/addons/email_template/email_template_mailbox.py index 3f52b9340ac..2eb0df13791 100644 --- a/addons/email_template/email_template_mailbox.py +++ b/addons/email_template/email_template_mailbox.py @@ -63,6 +63,7 @@ class email_template_mailbox(osv.osv): 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') @@ -70,7 +71,7 @@ class email_template_mailbox(osv.osv): 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]], @@ -84,8 +85,15 @@ class email_template_mailbox(osv.osv): 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)