Browse Source

[FIX] mail.tempale seems not work in cron task, replaced with direct call of mail.mail

pull/620/head
archetipo 9 years ago
committed by Dave Lasley
parent
commit
6bf182252f
  1. 1
      auto_backup/__openerp__.py
  2. 27
      auto_backup/data/autobackup_mail_template.xml
  3. 35
      auto_backup/model/backup_scheduler.py

1
auto_backup/__openerp__.py

@ -35,7 +35,6 @@
"data": [
"view/bkp_conf_view.xml",
"data/backup_data.xml",
"data/autobackup_mail_template.xml",
"security/ir.model.access.csv"
],
"active": False,

27
auto_backup/data/autobackup_mail_template.xml

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data noupdate="0">
<record id="email_template_autobackup_error_noificaiton" model="email.template">
<field name="name">Auto Backup Error notification</field>
<field name="email_from">auto_backup@${object.name}</field>
<field name="subject">Backup from ${object.host} - (${object.sftpip}) failed</field>
<field name="email_to">${object.emailtonotify}</field>
<field name="model_id" ref="auto_backup.model_db_backup" />
<field name="body_html">
<![CDATA[
<p>Dear,</p>
<p>The backup for the server ${object.host} (IP: ${object.sftpip}) failed.</p>
<p>Please check the following details:</p>
<p>IP address SFTP server: ${object.sftpip}</p>
<p>Username: ${object.sftpusername}</p>
<p>Password: ${object.sftppassword}</p>
<p>Error details: ${object.lasterrorlog}</p>
<p>With kind regards</p>
]]></field>
</record>
</data>
</openerp>

35
auto_backup/model/backup_scheduler.py

@ -225,6 +225,7 @@ class db_backup(models.Model):
@api.model
def schedule_backup(self):
for rec in self.search([]):
db_list = self.get_db_list(rec.host, rec.port)
if rec.name in db_list:
@ -349,15 +350,31 @@ class db_backup(models.Model):
# an e-mail notification about this.
if rec.sendmailsftpfail:
try:
self.write({'lasterrorlog': tools.ustr(e)})
abk_template = self.env.ref(
'auto_backup.'
'email_template_autobackup_error_noificaiton',
False
ir_mail_server = self.env['ir.mail_server']
message = (
"Dear,\n\nThe backup for the server %s"
" (IP: %s) failed.Please check"
" the following details:\n\n"
"IP address SFTP server: %s \nUsername: %s"
"\nPassword: %s"
"\n\nError details: %s \n\nWith kind regards"
) % (
rec.host, rec.sftpip, rec.sftpip,
rec.sftpusername, rec.sftppassword,
tools.ustr(e)
)
msg = ir_mail_server.build_email(
"auto_backup@%s.com" % rec.name,
[rec.emailtonotify],
"Backup from %s ( %s ) failed" % (
rec.host, rec.sftpip),
message)
ir_mail_server.send_email(msg)
except Exception as e:
_logger.debug(
'Exception! %s' % tools.ustr(e)
)
abk_template.send_mail(self.id)
except Exception:
pass
# Remove all old files (on local server) in case this is configured..
# This is done after the SFTP writing to prevent unusual behaviour:
@ -386,5 +403,3 @@ class db_backup(models.Model):
if delta.days >= rec.daystokeep:
os.remove(fullpath)
return True
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
Loading…
Cancel
Save