Browse Source
Now uses an email template instead of a simple mail
Now uses an email template instead of a simple mail
Add a default e-mail template Add the code we used to test the failure of scheduler (the import directive is commented)pull/1297/head
David BEAL
13 years ago
committed by
Pedro M. Baeza
6 changed files with 123 additions and 57 deletions
-
6scheduler_error_mailer/__init__.py
-
19scheduler_error_mailer/__openerp__.py
-
76scheduler_error_mailer/ir_cron.py
-
8scheduler_error_mailer/ir_cron.xml
-
32scheduler_error_mailer/ir_cron_email_tpl.xml
-
39scheduler_error_mailer/test_fail_scheduler.py
@ -1,55 +1,49 @@ |
|||||
# -*- encoding: utf-8 -*- |
# -*- encoding: utf-8 -*- |
||||
################################################################################# |
################################################################################# |
||||
# # |
|
||||
# Model module for OpenERP # |
|
||||
# Copyright (C) 2010 Sébastien BEAU <sebastien.beau@akretion.comr> # |
|
||||
# # |
|
||||
# This program is free software: you can redistribute it and/or modify # |
|
||||
# it under the terms of the GNU Affero General Public License as # |
|
||||
# published by the Free Software Foundation, either version 3 of the # |
|
||||
# License, or (at your option) any later version. # |
|
||||
# # |
|
||||
# This program is distributed in the hope that it will be useful, # |
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
|
||||
# GNU Affero General Public License for more details. # |
|
||||
# # |
|
||||
# You should have received a copy of the GNU Affero General Public License # |
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. # |
|
||||
# # |
|
||||
################################################################################# |
|
||||
|
# |
||||
|
# Scheduler error mailer module for OpenERP |
||||
|
# Copyright (C) 2012 Akretion |
||||
|
# @author: Sébastien Beau <sebastien.beau@akretion.com> |
||||
|
# @author David Beal <bealdavid@gmail.com> |
||||
|
# @author Alexis de Lattre <alexis.delattre@akretion.com> |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
|
||||
from osv import osv, fields |
from osv import osv, fields |
||||
import netsvc |
|
||||
|
from datetime import datetime |
||||
|
|
||||
|
|
||||
class ir_cron(osv.osv, netsvc.Agent): |
|
||||
|
class ir_cron(osv.osv): |
||||
_inherit = "ir.cron" |
_inherit = "ir.cron" |
||||
|
|
||||
_columns = { |
_columns = { |
||||
'email_to' : fields.char('TO', size=256, help="If an error occure with this scheduler an email will be send"), |
|
||||
'message' : fields.text('Message', help="If an error occure with this scheduler this message will be send via email"), |
|
||||
'send_email' : fields.boolean('Active'), |
|
||||
'email_account' : fields.many2one('poweremail.core_accounts', 'FROM') |
|
||||
|
'email_template' : fields.many2one('email.template', 'E-mail template'), |
||||
} |
} |
||||
|
|
||||
|
|
||||
def _handle_callback_exception(self, cr, uid, model, func, args, job_id, job_exception): |
def _handle_callback_exception(self, cr, uid, model, func, args, job_id, job_exception): |
||||
|
|
||||
res = super(ir_cron, self)._handle_callback_exception(cr, uid, model, func, args, job_id, job_exception) |
res = super(ir_cron, self)._handle_callback_exception(cr, uid, model, func, args, job_id, job_exception) |
||||
job = self.read(cr, uid, job_id, ['send_email', 'message', 'email_TO', 'email_account', 'name']) |
|
||||
#TODO USE POWEREMAIL TEMPLATE |
|
||||
if job['send_email']: |
|
||||
addresses = {'To' : job['email_TO']} |
|
||||
mail_obj = self.pool.get('poweremail.mailbox') |
|
||||
id = mail_obj.create(cr, uid, { |
|
||||
'pem_to' : job['email_TO'], |
|
||||
'pem_subject' : "OPENERP : error when excecuting scheduler " + job["name"], |
|
||||
'pem_body_text' : job['message'], |
|
||||
'pem_account_id' : job['email_account'][0], |
|
||||
'mail_type' : 'text/plain', |
|
||||
'folder' : 'outbox', |
|
||||
'state' :'na', |
|
||||
}) |
|
||||
mail_obj.send_this_mail(cr, uid, [id]) |
|
||||
return res |
|
||||
ir_cron() |
|
||||
|
|
||||
|
my_cron = self.browse(cr, uid, job_id) |
||||
|
|
||||
|
if my_cron.email_template.id: |
||||
|
# we put the job_exception in context to be able to get it inside the mail template |
||||
|
context = {'job_exception': job_exception} |
||||
|
id_mail_messsage = self.pool.get('email.template').send_mail(cr, uid, |
||||
|
my_cron.email_template.id, my_cron.id, force_send=True, context=context) |
||||
|
|
||||
|
return res |
@ -0,0 +1,32 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<!-- |
||||
|
Copyright (C) 2012 Akretion |
||||
|
The licence is in the file __openerp__.py |
||||
|
--> |
||||
|
|
||||
|
<openerp> |
||||
|
<!-- Email template --> |
||||
|
<data noupdate="1"> |
||||
|
|
||||
|
<record id="scheduler_error_mailer" model="email.template"> |
||||
|
<field name="name">Scheduler error</field> |
||||
|
<field name="email_from">${object.user_id.user_email or ''}</field> |
||||
|
<field name="subject">[DB ${object._cr.dbname}] Scheduler '${object.name or ''}' FAILED</field> |
||||
|
<field name="email_to">${object.user_id.user_email or ''}</field> |
||||
|
<field name="model_id" ref="base.model_ir_cron"/> |
||||
|
<field name="auto_delete" eval="True"/> |
||||
|
<field name="body_text"><![CDATA[ |
||||
|
On the database '${object._cr.dbname}', OpenERP has run the scheduler '${object.name or ''}' but it failed. Here is the error message : |
||||
|
|
||||
|
${hasattr(context.get('ctx').get('job_exception'), 'value') and context.get('ctx').get('job_exception').value or context.get('ctx').get('job_exception')} |
||||
|
|
||||
|
You may check the logs of OpenERP to get more information about this failure. |
||||
|
|
||||
|
The next action on this task is scheduled on ${object.nextcall or ''}. |
||||
|
|
||||
|
-- |
||||
|
Automatic e-mail sent by OpenERP. Do not reply. |
||||
|
]]></field> |
||||
|
</record> |
||||
|
</data> |
||||
|
</openerp> |
@ -0,0 +1,39 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# Scheduler error mailer module for OpenERP |
||||
|
# Copyright (C) 2012 Akretion |
||||
|
# @author David Beal <bealdavid@gmail.com> |
||||
|
# @author Alexis de Lattre <alexis.delattre@akretion.com> |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
|
||||
|
from osv import fields, osv |
||||
|
from tools.translate import _ |
||||
|
|
||||
|
class test_fail_scheduler(osv.osv_memory): |
||||
|
_name = "test.fail.scheduler" |
||||
|
_description = "Test scheduler failure" |
||||
|
|
||||
|
def test_fail(self, cr, uid, context=None): |
||||
|
""" This a test fail, only for debugging purpose |
||||
|
DO NOT UNCOMMENT IMPORT IN init.py IN PRODUCTION ENVIRONNEMENT |
||||
|
""" |
||||
|
|
||||
|
raise osv.except_osv(_('Error :'), _("task failure")) |
||||
|
# context['tytytyty'] |
||||
|
|
||||
|
test_fail_scheduler() |
Write
Preview
Loading…
Cancel
Save
Reference in new issue