Merge lp:~akretion-team/account-financial-tools/70-reversal-fix-improve into lp:~account-core-editors/account-financial-tools/7.0

Proposed by Alexis de Lattre
Status: Merged
Approved by: Yannick Vaucher @ Camptocamp
Approved revision: 136
Merged at revision: 147
Proposed branch: lp:~akretion-team/account-financial-tools/70-reversal-fix-improve
Merge into: lp:~account-core-editors/account-financial-tools/7.0
Diff against target: 47 lines (+17/-8)
2 files modified
account_reversal/account_reversal.py (+1/-0)
account_reversal/wizard/account_move_reverse.py (+16/-8)
To merge this branch: bzr merge lp:~akretion-team/account-financial-tools/70-reversal-fix-improve
Reviewer Review Type Date Requested Status
Yannick Vaucher @ Camptocamp code review, no tests Approve
Pedro Manuel Baeza code review Approve
Review via email: mp+200378@code.launchpad.net

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

LGTM

review: Approve (code review)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

LGTM

review: Approve (code review, no tests)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account_reversal/account_reversal.py'
2--- account_reversal/account_reversal.py 2013-01-14 12:19:55 +0000
3+++ account_reversal/account_reversal.py 2014-01-03 09:23:55 +0000
4@@ -65,6 +65,7 @@
5 period_obj = self.pool.get('account.period')
6 period_ctx = context.copy()
7 period_ctx['company_id'] = move.company_id.id
8+ period_ctx['account_period_prefer_normal'] = True
9
10 if not reversal_period_id:
11 reversal_period_id = period_obj.find(
12
13=== modified file 'account_reversal/wizard/account_move_reverse.py'
14--- account_reversal/wizard/account_move_reverse.py 2013-01-04 11:11:41 +0000
15+++ account_reversal/wizard/account_move_reverse.py 2014-01-03 09:23:55 +0000
16@@ -62,15 +62,23 @@
17 }
18
19 def _next_period_first_date(self, cr, uid, context=None):
20+ if context is None:
21+ context = {}
22+ res = False
23+ period_ctx = context.copy()
24+ period_ctx['account_period_prefer_normal'] = True
25 period_obj = self.pool.get('account.period')
26- current_period_id = period_obj.find(cr, uid, context=context)[0]
27- current_period = period_obj.browse(
28- cr, uid, current_period_id, context=context)
29- next_period_id = period_obj.next(
30- cr, uid, current_period, 1, context=context)
31- next_period = period_obj.browse(
32- cr, uid, next_period_id, context=context)
33- return next_period.date_start
34+ today_period_id = period_obj.find(cr, uid, context=period_ctx)
35+ if today_period_id:
36+ today_period = period_obj.browse(
37+ cr, uid, today_period_id[0], context=context)
38+ next_period_id = period_obj.next(
39+ cr, uid, today_period, 1, context=context)
40+ if next_period_id:
41+ next_period = period_obj.browse(
42+ cr, uid, next_period_id, context=context)
43+ res = next_period.date_start
44+ return res
45
46 _defaults = {
47 'date': _next_period_first_date,

Subscribers

People subscribed via source and target branches