Merge lp:~camptocamp/ocb-addons/opening_entry_foreign_currency_fix_mdh into lp:ocb-addons

Proposed by Matthieu Dietrich @ camptocamp
Status: Merged
Merge reported by: Holger Brunn (Therp)
Merged at revision: not available
Proposed branch: lp:~camptocamp/ocb-addons/opening_entry_foreign_currency_fix_mdh
Merge into: lp:ocb-addons
Diff against target: 27 lines (+1/-9)
1 file modified
account/wizard/account_fiscalyear_close.py (+1/-9)
To merge this branch: bzr merge lp:~camptocamp/ocb-addons/opening_entry_foreign_currency_fix_mdh
Reviewer Review Type Date Requested Status
Holger Brunn (Therp) Approve
Leonardo Pistone code review Approve
Review via email: mp+197526@code.launchpad.net

Commit message

[FIX] correct amount for opening entry in foreign currency

Description of the change

Found this issue: when computing an opening entry, the move lines' domains differ between the amount in system currency (all move lines in the latest FY before the current one, for example FY2012) and the amount in foreign currency (all move lines in previous FY, for example FY2012, 2011, 2010...).

I removed the old method to retrieve the sum of foreign amounts, which used a domain of multiple FYs, and retrieved the correct sum by using the function field "foreign_balance" in the account (since a single FY is specified in the browse() context, only the balance for this FY is retrieved; this is how the correct "account.balance" works).

To post a comment you must log in.
Revision history for this message
Leonardo Pistone (lepistone) wrote :

Thanks Matthieu.

LGTM. Seems like that on base currency foreign_balance is already 0.0, but it's not too bad to check anyway.

review: Approve (code review)
Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :

Thanks for this one! As it was merged into upstream and already got back to ocb via the replay script, I'll set this MP to 'merged'

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/wizard/account_fiscalyear_close.py'
2--- account/wizard/account_fiscalyear_close.py 2012-10-23 16:05:04 +0000
3+++ account/wizard/account_fiscalyear_close.py 2013-12-03 14:04:04 +0000
4@@ -224,14 +224,6 @@
5 query_2nd_part = ""
6 query_2nd_part_args = []
7 for account in obj_acc_account.browse(cr, uid, account_ids, context={'fiscalyear': fy_id}):
8- balance_in_currency = 0.0
9- if account.currency_id:
10- cr.execute('SELECT sum(COALESCE(amount_currency,0.0)) as balance_in_currency FROM account_move_line ' \
11- 'WHERE account_id = %s ' \
12- 'AND ' + query_line + ' ' \
13- 'AND currency_id = %s', (account.id, account.currency_id.id))
14- balance_in_currency = cr.dictfetchone()['balance_in_currency']
15-
16 company_currency_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.currency_id
17 if not currency_obj.is_zero(cr, uid, company_currency_id, abs(account.balance)):
18 if query_2nd_part:
19@@ -246,7 +238,7 @@
20 period.id,
21 account.id,
22 account.currency_id and account.currency_id.id or None,
23- balance_in_currency,
24+ account.foreign_balance if account.currency_id else 0.0,
25 account.company_id.id,
26 'draft')
27 if query_2nd_part: