Browse Source

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

pull/636/head
archetipo 9 years ago
committed by Dave Lasley
parent
commit
b59b2d7357
  1. 1
      auto_backup/__openerp__.py
  2. 27
      auto_backup/data/autobackup_mail_template.xml
  3. 37
      auto_backup/model/backup_scheduler.py

1
auto_backup/__openerp__.py

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

37
auto_backup/model/backup_scheduler.py

@ -225,6 +225,7 @@ class db_backup(models.Model):
@api.model @api.model
def schedule_backup(self): def schedule_backup(self):
for rec in self.search([]): for rec in self.search([]):
db_list = self.get_db_list(rec.host, rec.port) db_list = self.get_db_list(rec.host, rec.port)
if rec.name in db_list: if rec.name in db_list:
@ -349,15 +350,31 @@ class db_backup(models.Model):
# an e-mail notification about this. # an e-mail notification about this.
if rec.sendmailsftpfail: if rec.sendmailsftpfail:
try: try:
self.write({'lasterrorlog': tools.ustr(e)})
abk_template = self.env.ref(
'auto_backup.'
'email_template_autobackup_error_noificaiton',
False
)
abk_template.send_mail(self.id)
except Exception:
pass
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)
)
# Remove all old files (on local server) in case this is configured.. # Remove all old files (on local server) in case this is configured..
# This is done after the SFTP writing to prevent unusual behaviour: # 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: if delta.days >= rec.daystokeep:
os.remove(fullpath) os.remove(fullpath)
return True return True
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
Loading…
Cancel
Save