Atchuthan, Sodexis
9 years ago
committed by
Pedro M. Baeza
11 changed files with 213 additions and 203 deletions
-
67scheduler_error_mailer/README.rst
-
26scheduler_error_mailer/__init__.py
-
49scheduler_error_mailer/__openerp__.py
-
38scheduler_error_mailer/data/ir_cron_email_tpl.xml
-
27scheduler_error_mailer/demo/ir_cron_demo.xml
-
76scheduler_error_mailer/ir_cron.py
-
24scheduler_error_mailer/ir_cron.xml
-
26scheduler_error_mailer/ir_cron_demo.xml
-
6scheduler_error_mailer/models/__init__.py
-
55scheduler_error_mailer/models/ir_cron.py
-
22scheduler_error_mailer/views/ir_cron.xml
@ -0,0 +1,67 @@ |
|||||
|
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg |
||||
|
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html |
||||
|
:alt: License: AGPL-3 |
||||
|
|
||||
|
====================== |
||||
|
Scheduler Error Mailer |
||||
|
====================== |
||||
|
|
||||
|
This module adds the possibility to send an e-mail when a scheduler raises |
||||
|
an error. |
||||
|
|
||||
|
Configuration |
||||
|
============= |
||||
|
|
||||
|
To configure this module, you need to: |
||||
|
|
||||
|
#. Go to Settings -> Technical -> Automation -> Scheduled Actions |
||||
|
#. Choose the scheduled Actions you want to send the error email and select the E-mail Template in the Error E-mail Template field. |
||||
|
|
||||
|
Usage |
||||
|
===== |
||||
|
|
||||
|
To use this module, you need to: |
||||
|
|
||||
|
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas |
||||
|
:alt: Try me on Runbot |
||||
|
:target: https://runbot.odoo-community.org/runbot/149/9.0 |
||||
|
|
||||
|
Bug Tracker |
||||
|
=========== |
||||
|
|
||||
|
Bugs are tracked on `GitHub Issues |
||||
|
<https://github.com/OCA/server-tools/issues>`_. In case of trouble, please |
||||
|
check there if your issue has already been reported. If you spotted it first, |
||||
|
help us smashing it by providing a detailed and welcomed feedback. |
||||
|
|
||||
|
Credits |
||||
|
======= |
||||
|
|
||||
|
Images |
||||
|
------ |
||||
|
|
||||
|
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. |
||||
|
|
||||
|
Contributors |
||||
|
------------ |
||||
|
|
||||
|
* Sébastien BEAU <sebastien.beau@akretion.com> |
||||
|
* David Beal <bealdavid@gmail.com> |
||||
|
* Alexis de Lattre <alexis.delattre@akretion.com> |
||||
|
* Sodexis <dev@sodexis.com> |
||||
|
|
||||
|
|
||||
|
Maintainer |
||||
|
---------- |
||||
|
|
||||
|
.. image:: https://odoo-community.org/logo.png |
||||
|
:alt: Odoo Community Association |
||||
|
:target: https://odoo-community.org |
||||
|
|
||||
|
This module is maintained by the OCA. |
||||
|
|
||||
|
OCA, or the Odoo Community Association, is a nonprofit organization whose |
||||
|
mission is to support the collaborative development of Odoo features and |
||||
|
promote its widespread use. |
||||
|
|
||||
|
To contribute to this module, please visit https://odoo-community.org. |
@ -1,24 +1,6 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
############################################################################## |
|
||||
# |
|
||||
# Scheduler Error Mailer module for OpenERP |
|
||||
# Copyright (C) 2012-2013 Akretion (http://www.akretion.com/) |
|
||||
# @author: Sébastien Beau <sebastien.beau@akretion.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/>. |
|
||||
# |
|
||||
############################################################################## |
|
||||
|
# © 2012-2013 Akretion Sébastien BEAU,David Beal,Alexis de Lattre |
||||
|
# © 2016 Sodexis |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
from . import ir_cron |
|
||||
|
from . import models |
@ -1,48 +1,21 @@ |
|||||
# -*- encoding: utf-8 -*- |
|
||||
############################################################################## |
|
||||
# |
|
||||
# Scheduler Error Mailer module for OpenERP |
|
||||
# Copyright (C) 2012-2013 Akretion (http://www.akretion.com/) |
|
||||
# @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/>. |
|
||||
# |
|
||||
############################################################################## |
|
||||
|
|
||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2012-2013 Akretion Sébastien BEAU,David Beal,Alexis de Lattre |
||||
|
# © 2016 Sodexis |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
{ |
{ |
||||
'name': 'Scheduler Error Mailer', |
'name': 'Scheduler Error Mailer', |
||||
'summary': 'Send an e-mail when a scheduler fails', |
|
||||
'version': '8.0.1.0.0', |
|
||||
|
'version': '9.0.1.0.0', |
||||
'category': 'Extra Tools', |
'category': 'Extra Tools', |
||||
'license': 'AGPL-3', |
'license': 'AGPL-3', |
||||
'description': """ |
|
||||
Scheduler Error Mailer |
|
||||
====================== |
|
||||
|
|
||||
This module adds the possibility to send an e-mail when a scheduler raises |
|
||||
an error.""", |
|
||||
'author': "Akretion,Odoo Community Association (OCA)", |
|
||||
|
'author': "Akretion,Sodexis,Odoo Community Association (OCA)", |
||||
'website': 'http://www.akretion.com/', |
'website': 'http://www.akretion.com/', |
||||
'depends': ['email_template'], |
|
||||
|
'depends': ['mail'], |
||||
'data': [ |
'data': [ |
||||
'ir_cron.xml', |
|
||||
'ir_cron_email_tpl.xml', |
|
||||
|
'data/ir_cron_email_tpl.xml', |
||||
|
'views/ir_cron.xml', |
||||
], |
], |
||||
'demo': ['ir_cron_demo.xml'], |
|
||||
|
'demo': ['demo/ir_cron_demo.xml'], |
||||
'images': ['images/scheduler_error_mailer.jpg'], |
'images': ['images/scheduler_error_mailer.jpg'], |
||||
'installable': False, |
|
||||
|
'installable': True, |
||||
} |
} |
@ -0,0 +1,27 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<!-- |
||||
|
scheduler_error_mailer for Odoo |
||||
|
Copyright (C) 2012-2013 Akretion Sébastien BEAU,David Beal,Alexis de Lattre |
||||
|
Copyright (C) 2016 Sodexis |
||||
|
The licence is in the file __openerp__.py |
||||
|
--> |
||||
|
|
||||
|
<odoo> |
||||
|
<data noupdate="1"> |
||||
|
|
||||
|
<record id="test_scheduler_error_mailer" model="ir.cron"> |
||||
|
<field name="name">Test Scheduler Error Mailer</field> |
||||
|
<field name="active" eval="False"/> |
||||
|
<field name="user_id" ref="base.user_root"/> |
||||
|
<field name="interval_number">1</field> |
||||
|
<field name="interval_type">hours</field> |
||||
|
<field name="numbercall">-1</field> |
||||
|
<!-- don't limit the number of calls --> |
||||
|
<field name="doall" eval="True"/> |
||||
|
<field name="model">ir.cron</field> |
||||
|
<field name="function">_test_scheduler_failure</field> |
||||
|
<field name="email_template_id" ref="scheduler_error_mailer.scheduler_error_mailer"/> |
||||
|
</record> |
||||
|
|
||||
|
</data> |
||||
|
</odoo> |
@ -1,76 +0,0 @@ |
|||||
# -*- encoding: utf-8 -*- |
|
||||
############################################################################## |
|
||||
# |
|
||||
# Scheduler Error Mailer module for OpenERP |
|
||||
# Copyright (C) 2012-2013 Akretion (http://www.akretion.com/) |
|
||||
# @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 openerp import SUPERUSER_ID |
|
||||
from openerp.osv import orm, fields |
|
||||
from openerp.tools.translate import _ |
|
||||
import logging |
|
||||
|
|
||||
|
|
||||
_logger = logging.getLogger(__name__) |
|
||||
|
|
||||
|
|
||||
class ir_cron(orm.Model): |
|
||||
_inherit = "ir.cron" |
|
||||
|
|
||||
_columns = { |
|
||||
'email_template_id': fields.many2one( |
|
||||
'email.template', |
|
||||
'Error E-mail Template', |
|
||||
oldname="email_template", |
|
||||
help="Select the email template that will be " |
|
||||
"sent when this scheduler fails."), |
|
||||
} |
|
||||
|
|
||||
def _handle_callback_exception(self, cr, uid, model_name, method_name, |
|
||||
args, job_id, job_exception): |
|
||||
|
|
||||
res = super(ir_cron, self)._handle_callback_exception( |
|
||||
cr, uid, model_name, method_name, args, job_id, job_exception) |
|
||||
|
|
||||
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 print it inside |
|
||||
# the email template |
|
||||
context = { |
|
||||
'job_exception': job_exception, |
|
||||
'dbname': cr.dbname, |
|
||||
} |
|
||||
|
|
||||
_logger.debug("Sending scheduler error email with context=%s", |
|
||||
context) |
|
||||
|
|
||||
self.pool['email.template'].send_mail( |
|
||||
cr, SUPERUSER_ID, my_cron.email_template_id.id, my_cron.id, |
|
||||
force_send=True, context=context) |
|
||||
|
|
||||
return res |
|
||||
|
|
||||
def _test_scheduler_failure(self, cr, uid, context=None): |
|
||||
"""This function is used to test and debug this module""" |
|
||||
|
|
||||
raise orm.except_orm( |
|
||||
_('Error :'), |
|
||||
_("Task failure with UID = %d.") % uid) |
|
@ -1,24 +0,0 @@ |
|||||
<?xml version="1.0" encoding="utf-8"?> |
|
||||
<!-- |
|
||||
Copyright (C) 2012-2013 Akretion (http://www.akretion.com/) |
|
||||
The licence is in the file __openerp__.py |
|
||||
--> |
|
||||
|
|
||||
<openerp> |
|
||||
<data> |
|
||||
|
|
||||
|
|
||||
<record id="ir_cron_error_mailer_view" model="ir.ui.view"> |
|
||||
<field name="name">ir.cron.error.mailer.form</field> |
|
||||
<field name="model">ir.cron</field> |
|
||||
<field name="inherit_id" ref="base.ir_cron_view"/> |
|
||||
<field name="arch" type="xml"> |
|
||||
<field name="doall" position="after"> |
|
||||
<field name="email_template_id" /> |
|
||||
</field> |
|
||||
</field> |
|
||||
</record> |
|
||||
|
|
||||
|
|
||||
</data> |
|
||||
</openerp> |
|
@ -1,26 +0,0 @@ |
|||||
<?xml version="1.0" encoding="utf-8"?> |
|
||||
|
|
||||
<!-- |
|
||||
Copyright (C) 2013 Akretion (http://www.akretion.com/) |
|
||||
@author Alexis de Lattre <alexis.delattre@akretion.com> |
|
||||
The licence is in the file __openerp__.py |
|
||||
--> |
|
||||
|
|
||||
<openerp> |
|
||||
<data noupdate="1"> |
|
||||
|
|
||||
<record id="test_scheduler_error_mailer" model="ir.cron"> |
|
||||
<field name="name">Test Scheduler Error Mailer</field> |
|
||||
<field name="active" eval="False"/> |
|
||||
<field name="user_id" ref="base.user_root"/> |
|
||||
<field name="interval_number">1</field> |
|
||||
<field name="interval_type">hours</field> |
|
||||
<field name="numbercall">-1</field> <!-- don't limit the number of calls --> |
|
||||
<field name="doall" eval="True"/> |
|
||||
<field name="model">ir.cron</field> |
|
||||
<field name="function">_test_scheduler_failure</field> |
|
||||
<field name="email_template_id" ref="scheduler_error_mailer"/> |
|
||||
</record> |
|
||||
|
|
||||
</data> |
|
||||
</openerp> |
|
@ -0,0 +1,6 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2012-2013 Akretion Sébastien BEAU,David Beal,Alexis de Lattre |
||||
|
# © 2016 Sodexis |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from . import ir_cron |
@ -0,0 +1,55 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2012-2013 Akretion Sébastien BEAU,David Beal,Alexis de Lattre |
||||
|
# © 2016 Sodexis |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
|
||||
|
from openerp import models, fields, api, _ |
||||
|
from openerp.exceptions import UserError |
||||
|
import logging |
||||
|
|
||||
|
|
||||
|
_logger = logging.getLogger(__name__) |
||||
|
|
||||
|
|
||||
|
class IrCron(models.Model): |
||||
|
_inherit = "ir.cron" |
||||
|
|
||||
|
email_template_id = fields.Many2one( |
||||
|
comodel_name="mail.template", |
||||
|
string="Error E-mail Template", |
||||
|
help="Select the email template that will be sent when " |
||||
|
"this scheduler fails." |
||||
|
) |
||||
|
|
||||
|
@api.model |
||||
|
def _handle_callback_exception( |
||||
|
self, model_name, method_name, args, job_id, job_exception): |
||||
|
res = super(IrCron, self)._handle_callback_exception( |
||||
|
model_name, method_name, args, job_id, job_exception) |
||||
|
|
||||
|
my_cron = self.browse(job_id) |
||||
|
|
||||
|
if my_cron.email_template_id: |
||||
|
# we put the job_exception in context to be able to print it inside |
||||
|
# the email template |
||||
|
context = { |
||||
|
'job_exception': job_exception, |
||||
|
'dbname': self._cr.dbname, |
||||
|
} |
||||
|
|
||||
|
_logger.debug( |
||||
|
"Sending scheduler error email with context=%s", context) |
||||
|
|
||||
|
self.env['mail.template'].browse( |
||||
|
my_cron.email_template_id.id |
||||
|
).with_context(context).sudo().send_mail( |
||||
|
my_cron.id, force_send=True) |
||||
|
|
||||
|
return res |
||||
|
|
||||
|
@api.model |
||||
|
def _test_scheduler_failure(self): |
||||
|
"""This function is used to test and debug this module""" |
||||
|
|
||||
|
raise UserError( |
||||
|
_("Task failure with UID = %d.") % self._uid) |
@ -0,0 +1,22 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<!-- |
||||
|
scheduler_error_mailer for Odoo |
||||
|
Copyright (C) 2012-2013 Akretion Sébastien BEAU,David Beal,Alexis de Lattre |
||||
|
Copyright (C) 2016 Sodexis |
||||
|
The licence is in the file __openerp__.py |
||||
|
--> |
||||
|
|
||||
|
<odoo> |
||||
|
|
||||
|
<record id="ir_cron_view" model="ir.ui.view"> |
||||
|
<field name="name">ir.cron.error.mailer.form</field> |
||||
|
<field name="model">ir.cron</field> |
||||
|
<field name="inherit_id" ref="base.ir_cron_view"/> |
||||
|
<field name="arch" type="xml"> |
||||
|
<field name="doall" position="after"> |
||||
|
<field name="email_template_id"/> |
||||
|
</field> |
||||
|
</field> |
||||
|
</record> |
||||
|
|
||||
|
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue