From 3c817a8a77791a3a9ab1ff547a005482d79f6193 Mon Sep 17 00:00:00 2001 From: "rpa (Open ERP)" Date: Thu, 26 Aug 2010 18:11:51 +0530 Subject: [PATCH] [ADD]: email_template: Added a boolean field "auto_delete" on email account which completely removes email and its attachments from mailbox when sent successfully bzr revid: rpa@tinyerp.com-20100826124151-imphq5kagsqtjsos --- addons/email_template/email_template_account.py | 3 +++ addons/email_template/email_template_account_view.xml | 3 ++- addons/email_template/email_template_mailbox.py | 14 +++++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/addons/email_template/email_template_account.py b/addons/email_template/email_template_account.py index 1a1b6db..3f049ee 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 a73fc07..3234589 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 3f52b93..2eb0df1 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) -- 1.7.10.4