You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
3.2 KiB

  1. # -*- encoding: utf-8 -*-
  2. #################################################################################
  3. # #
  4. # Model module for OpenERP #
  5. # Copyright (C) 2010 Sébastien BEAU <sebastien.beau@akretion.comr> #
  6. # #
  7. # This program is free software: you can redistribute it and/or modify #
  8. # it under the terms of the GNU Affero General Public License as #
  9. # published by the Free Software Foundation, either version 3 of the #
  10. # License, or (at your option) any later version. #
  11. # #
  12. # This program is distributed in the hope that it will be useful, #
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of #
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
  15. # GNU Affero General Public License for more details. #
  16. # #
  17. # You should have received a copy of the GNU Affero General Public License #
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>. #
  19. # #
  20. #################################################################################
  21. from osv import osv, fields
  22. import netsvc
  23. class ir_cron(osv.osv, netsvc.Agent):
  24. _inherit = "ir.cron"
  25. _columns = {
  26. 'email_to' : fields.char('TO', size=256, help="If an error occure with this scheduler an email will be send"),
  27. 'message' : fields.text('Message', help="If an error occure with this scheduler this message will be send via email"),
  28. 'send_email' : fields.boolean('Active'),
  29. 'email_account' : fields.many2one('poweremail.core_accounts', 'FROM')
  30. }
  31. def _handle_callback_exception(self, cr, uid, model, func, args, job_id, job_exception):
  32. res = super(ir_cron, self)._handle_callback_exception(cr, uid, model, func, args, job_id, job_exception)
  33. job = self.read(cr, uid, job_id, ['send_email', 'message', 'email_TO', 'email_account', 'name'])
  34. #TODO USE POWEREMAIL TEMPLATE
  35. if job['send_email']:
  36. addresses = {'To' : job['email_TO']}
  37. mail_obj = self.pool.get('poweremail.mailbox')
  38. id = mail_obj.create(cr, uid, {
  39. 'pem_to' : job['email_TO'],
  40. 'pem_subject' : "OPENERP : error when excecuting scheduler " + job["name"],
  41. 'pem_body_text' : job['message'],
  42. 'pem_account_id' : job['email_account'][0],
  43. 'mail_type' : 'text/plain',
  44. 'folder' : 'outbox',
  45. 'state' :'na',
  46. })
  47. mail_obj.send_this_mail(cr, uid, [id])
  48. return res
  49. ir_cron()