[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
This commit is contained in:
rpa (Open ERP) 2010-08-26 18:11:51 +05:30
parent 300556bc1f
commit 3c817a8a77
3 changed files with 16 additions and 4 deletions

View File

@ -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)]}),

View File

@ -12,8 +12,9 @@
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Email Account Configuration">
<group colspan="2">
<group colspan="4">
<field name="name" select="1" />
<field name="auto_delete" />
</group>
<notebook colspan="4">
<page string="Outgoing">

View File

@ -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)