From c97250eff69ece37c95236ef82993115060c6dc3 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Fri, 20 Dec 2013 18:19:09 +0100 Subject: [PATCH] [FIX] Avoid a crash when the next period doesn't exist (for example : you are in December 2013 and FY 2014 is not created yet). Add prefer_normal_period in period selection. --- account_reversal/account_reversal.py | 1 + .../wizard/account_move_reverse.py | 24 ++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/account_reversal/account_reversal.py b/account_reversal/account_reversal.py index 2b7edcfac..14ca4043b 100644 --- a/account_reversal/account_reversal.py +++ b/account_reversal/account_reversal.py @@ -65,6 +65,7 @@ class account_move(orm.Model): period_obj = self.pool.get('account.period') period_ctx = context.copy() period_ctx['company_id'] = move.company_id.id + period_ctx['account_period_prefer_normal'] = True if not reversal_period_id: reversal_period_id = period_obj.find( diff --git a/account_reversal/wizard/account_move_reverse.py b/account_reversal/wizard/account_move_reverse.py index 0b25abbd7..1d682345a 100644 --- a/account_reversal/wizard/account_move_reverse.py +++ b/account_reversal/wizard/account_move_reverse.py @@ -62,15 +62,23 @@ class account_move_reversal(orm.TransientModel): } def _next_period_first_date(self, cr, uid, context=None): + if context is None: + context = {} + res = False + period_ctx = context.copy() + period_ctx['account_period_prefer_normal'] = True period_obj = self.pool.get('account.period') - current_period_id = period_obj.find(cr, uid, context=context)[0] - current_period = period_obj.browse( - cr, uid, current_period_id, context=context) - next_period_id = period_obj.next( - cr, uid, current_period, 1, context=context) - next_period = period_obj.browse( - cr, uid, next_period_id, context=context) - return next_period.date_start + today_period_id = period_obj.find(cr, uid, context=period_ctx) + if today_period_id: + today_period = period_obj.browse( + cr, uid, today_period_id[0], context=context) + next_period_id = period_obj.next( + cr, uid, today_period, 1, context=context) + if next_period_id: + next_period = period_obj.browse( + cr, uid, next_period_id, context=context) + res = next_period.date_start + return res _defaults = { 'date': _next_period_first_date,