From b54f116d8698b21e0b0cc4981f44d0264f3f83c0 Mon Sep 17 00:00:00 2001 From: Amit Vora Date: Tue, 20 May 2014 16:34:19 +0530 Subject: [PATCH] [IMP ]add failure_reason field and counting number of fail mail [IMP] improve help and change field name fail_mail to fail_counter and change method name of counting fail mail --- addons/mail/mail_mail.py | 9 ++++++--- addons/mail/mail_mail_view.xml | 5 ++++- addons/mail/res_config.py | 9 +++++++++ addons/mail/res_config_view.xml | 9 +++++++++ addons/mail/static/src/css/mail.css | 1 - addons/mail/tests/test_mail_features.py | 9 ++++++++- 6 files changed, 36 insertions(+), 6 deletions(-) diff --git a/addons/mail/mail_mail.py b/addons/mail/mail_mail.py index aeea2c0b1a5..3409c983bd8 100644 --- a/addons/mail/mail_mail.py +++ b/addons/mail/mail_mail.py @@ -30,6 +30,7 @@ from openerp.addons.base.ir.ir_mail_server import MailDeliveryException from openerp.osv import fields, osv from openerp.tools.safe_eval import safe_eval as eval from openerp.tools.translate import _ +import openerp.tools as tools _logger = logging.getLogger(__name__) @@ -60,6 +61,7 @@ class mail_mail(osv.Model): 'email_cc': fields.char('Cc', help='Carbon copy message recipients'), 'body_html': fields.text('Rich-text Contents', help="Rich-text/HTML message"), 'headers': fields.text('Headers', copy=False), + 'failure_reason': fields.text('Failure Reason', help="Failure reason. This is usually the exception thrown by the email server, stored to ease the debugging of mailing issues.", readonly=1), # Auto-detected based on create() - if 'mail_message_id' was passed then this mail is a notification # and during unlink() we will not cascade delete the parent and its attachments 'notification': fields.boolean('Is Notification', @@ -296,7 +298,7 @@ class mail_mail(osv.Model): mail.write({'state': 'sent', 'message_id': res}) mail_sent = True else: - mail.write({'state': 'exception'}) + mail.write({'state': 'exception', 'failure_reason': _('Error without exception. Probably due do sending an email without computed recipients.')}) mail_sent = False # /!\ can't use mail.state here, as mail.refresh() will cause an error @@ -312,8 +314,9 @@ class mail_mail(osv.Model): mail.id, mail.message_id) raise except Exception as e: - _logger.exception('failed sending mail.mail %s', mail.id) - mail.write({'state': 'exception'}) + failure_reason = tools.ustr(e) + _logger.exception('failed sending mail (id: %s) due to %s', mail.id, failure_reason) + mail.write({'state': 'exception', 'failure_reason': failure_reason}) self._postprocess_sent_message(cr, uid, mail, context=context, mail_sent=False) if raise_exception: if isinstance(e, AssertionError): diff --git a/addons/mail/mail_mail_view.xml b/addons/mail/mail_mail_view.xml index 233f407b8e1..bf516840f47 100644 --- a/addons/mail/mail_mail_view.xml +++ b/addons/mail/mail_mail_view.xml @@ -52,6 +52,9 @@ + + + @@ -116,7 +119,7 @@ mail.mail form tree,form - {'search_default_outgoing': 1} + {} diff --git a/addons/mail/res_config.py b/addons/mail/res_config.py index 2c94b432dc3..e238d9ab105 100644 --- a/addons/mail/res_config.py +++ b/addons/mail/res_config.py @@ -20,7 +20,9 @@ ############################################################################## import urlparse +import datetime +from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT from openerp.osv import osv, fields @@ -28,11 +30,18 @@ class project_configuration(osv.TransientModel): _inherit = 'base.config.settings' _columns = { + 'fail_counter': fields.integer('Fail Mail', readonly=True), 'alias_domain': fields.char('Alias Domain', help="If you have setup a catch-all email domain redirected to " "the OpenERP server, enter the domain name here."), } + def get_default_fail_counter(self, cr, uid, ids, context=None): + previous_date = datetime.datetime.now() - datetime.timedelta(days=30) + return { + 'fail_counter': self.pool.get('mail.mail').search(cr, uid, [('date', '>=', previous_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT)), ('state', '=', 'exception')], count=True, context=context), + } + def get_default_alias_domain(self, cr, uid, ids, context=None): alias_domain = self.pool.get("ir.config_parameter").get_param(cr, uid, "mail.catchall.domain", default=None, context=context) if alias_domain is None: diff --git a/addons/mail/res_config_view.xml b/addons/mail/res_config_view.xml index d3797ba2dcc..aa0b9f176a3 100644 --- a/addons/mail/res_config_view.xml +++ b/addons/mail/res_config_view.xml @@ -6,6 +6,15 @@ base.config.settings + + +