From d2b6bc8391e61242374cc507779081a72efe3247 Mon Sep 17 00:00:00 2001 From: Matthieu Dietrich Date: Wed, 7 Jan 2015 15:49:37 +0100 Subject: [PATCH 1/3] Add history line + error message if reconciliation fails --- account_easy_reconcile/easy_reconcile.py | 15 +++++++++++++++ account_easy_reconcile/easy_reconcile.xml | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/account_easy_reconcile/easy_reconcile.py b/account_easy_reconcile/easy_reconcile.py index 34d0604c..ff65ad91 100644 --- a/account_easy_reconcile/easy_reconcile.py +++ b/account_easy_reconcile/easy_reconcile.py @@ -139,6 +139,7 @@ class AccountEasyReconcileMethod(orm.Model): class AccountEasyReconcile(orm.Model): _name = 'account.easy.reconcile' + _inherit = ['mail.thread'] _description = 'account easy reconcile' def _get_total_unrec(self, cr, uid, ids, name, arg, context=None): @@ -283,6 +284,20 @@ class AccountEasyReconcile(orm.Model): 'reconcile_ids': [(4, rid) for rid in reconcile_ids], 'reconcile_partial_ids': [(4, rid) for rid in partial_ids], }, context=context) + except Exception as e: + # In case of error, we log it in the mail thread, + # and create an empty history line; otherwise, the cron + # will just loop on this reconcile task. + message = "There was an error during reconciliation : %s" \ + % e.value + self.message_post(cr, uid, rec.id, + body=message, context=context) + self.pool.get('easy.reconcile.history').create(new_cr, uid, { + 'easy_reconcile_id': rec.id, + 'date': fields.datetime.now(), + 'reconcile_ids': [], + 'reconcile_partial_ids': [], + }) finally: if ctx['commit_every']: new_cr.commit() diff --git a/account_easy_reconcile/easy_reconcile.xml b/account_easy_reconcile/easy_reconcile.xml index 1a95139b..076bd3b3 100644 --- a/account_easy_reconcile/easy_reconcile.xml +++ b/account_easy_reconcile/easy_reconcile.xml @@ -71,6 +71,10 @@ The lines should have the same amount (with the write-off) and the same referenc +
+ + +
From 7784845f29ea7b07698bcdd3db9e12973aa2395c Mon Sep 17 00:00:00 2001 From: Matthieu Dietrich Date: Thu, 8 Jan 2015 12:06:18 +0100 Subject: [PATCH 2/3] Add stack trace in case of exception --- account_easy_reconcile/easy_reconcile.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/account_easy_reconcile/easy_reconcile.py b/account_easy_reconcile/easy_reconcile.py index ff65ad91..04482992 100644 --- a/account_easy_reconcile/easy_reconcile.py +++ b/account_easy_reconcile/easy_reconcile.py @@ -25,6 +25,9 @@ from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT from openerp.tools.translate import _ from openerp import pooler +import logging +_logger = logging.getLogger(__name__) + class EasyReconcileOptions(orm.AbstractModel): """Options of a reconciliation profile @@ -285,13 +288,15 @@ class AccountEasyReconcile(orm.Model): 'reconcile_partial_ids': [(4, rid) for rid in partial_ids], }, context=context) except Exception as e: - # In case of error, we log it in the mail thread, - # and create an empty history line; otherwise, the cron - # will just loop on this reconcile task. + # In case of error, we log it in the mail thread, log the + # stack trace and create an empty history line; otherwise, + # the cron will just loop on this reconcile task. message = "There was an error during reconciliation : %s" \ % e.value self.message_post(cr, uid, rec.id, body=message, context=context) + _logger.exception("The reconcile task %s had an exception: %s", + rec.name, e.value) self.pool.get('easy.reconcile.history').create(new_cr, uid, { 'easy_reconcile_id': rec.id, 'date': fields.datetime.now(), From 152add76f9605c577ede86a0d8a675b88532483d Mon Sep 17 00:00:00 2001 From: Matthieu Dietrich Date: Thu, 8 Jan 2015 12:17:29 +0100 Subject: [PATCH 3/3] logger before message (to catch evental DB cursor issues) --- account_easy_reconcile/easy_reconcile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/account_easy_reconcile/easy_reconcile.py b/account_easy_reconcile/easy_reconcile.py index 04482992..89af1759 100644 --- a/account_easy_reconcile/easy_reconcile.py +++ b/account_easy_reconcile/easy_reconcile.py @@ -291,12 +291,12 @@ class AccountEasyReconcile(orm.Model): # In case of error, we log it in the mail thread, log the # stack trace and create an empty history line; otherwise, # the cron will just loop on this reconcile task. + _logger.exception("The reconcile task %s had an exception: %s", + rec.name, e.value) message = "There was an error during reconciliation : %s" \ % e.value self.message_post(cr, uid, rec.id, body=message, context=context) - _logger.exception("The reconcile task %s had an exception: %s", - rec.name, e.value) self.pool.get('easy.reconcile.history').create(new_cr, uid, { 'easy_reconcile_id': rec.id, 'date': fields.datetime.now(),