From 4c67871ac88d53d0da0df82b1776dd4cfa8e6d89 Mon Sep 17 00:00:00 2001 From: Nicolas Bessi Date: Mon, 28 Apr 2014 13:18:37 +0200 Subject: [PATCH] [IMP] redability of error message --- account_credit_control/run.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/account_credit_control/run.py b/account_credit_control/run.py index 817643cd7..9a050655b 100644 --- a/account_credit_control/run.py +++ b/account_credit_control/run.py @@ -82,17 +82,22 @@ class CreditControlRun(orm.Model): def _check_run_date(self, cr, uid, ids, controlling_date, context=None): """Ensure that there is no credit line in the future using controlling_date""" run_obj = self.pool['credit.control.run'] - lines = run_obj.search(cr, uid, [('date', '>', controlling_date)], - order='date DESC', limit=1, context=context) - if not lines: - line_obj = self.pool['credit.control.line'] - lines = line_obj.search(cr, uid, [('date', '>', controlling_date)], - order='date DESC', limit=1, context=context) + runs = run_obj.search(cr, uid, [('date', '>', controlling_date)], + order='date DESC', limit=1, context=context) + if runs: + run = run_obj.browse(cr, uid, runs[0], context=context) + raise orm.except_orm(_('Error'), + _('A run has already been executed more ' + 'recently than %s') % (run.date)) + + line_obj = self.pool['credit.control.line'] + lines = line_obj.search(cr, uid, [('date', '>', controlling_date)], + order='date DESC', limit=1, context=context) if lines: line = line_obj.browse(cr, uid, lines[0], context=context) raise orm.except_orm(_('Error'), - _('A run has already been executed more ' - 'recently than %s') % (line.date)) + _('A credit control line more ' + 'recent than %s exists') % (line.date)) return True def _generate_credit_lines(self, cr, uid, run_id, context=None): @@ -153,7 +158,7 @@ class CreditControlRun(orm.Model): """ try: cr.execute('SELECT id FROM credit_control_run' - ' LIMIT 1 FOR UPDATE NOWAIT') + ' LIMIT 1 FOR UPDATE NOWAIT') except Exception as exc: # in case of exception openerp will do a rollback for us and free the lock raise orm.except_orm(_('Error'),