Merge lp:~openerp-dev/openobject-addons/5.0-opw-7285-pso into lp:openobject-addons/5.0

Proposed by Priyesh (OpenERP)
Status: Merged
Merged at revision: 2924
Proposed branch: lp:~openerp-dev/openobject-addons/5.0-opw-7285-pso
Merge into: lp:openobject-addons/5.0
Diff against target: 38 lines (+11/-13)
1 file modified
account/account_bank_statement.py (+11/-13)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/5.0-opw-7285-pso
Reviewer Review Type Date Requested Status
Raphael Collet (OpenERP) (community) Approve
qdp (OpenERP) Approve
Review via email: mp+76019@code.launchpad.net

Description of the change

Hello,

Improved balance computation of bank statement for multi-currency (case:7285)

To reproduce:
1. Currency of Bank Journal = ARS, Company currency = EUR
2. Create a Bank statement (so it's currency = ARS)
3. Create a start balance = 0 ans end balance = 100
4. Create entry lines: First line with 20, and second line with 80 (so these amounts are in ARS)
5. Confirm the bank Statement
6. The Balance will be correct (100), and on Real entries tab, you'll lines with amounts converted in EUR
7. Now change the ARS rate (date = today)
8. Go back to the Confirmed Bank Statement and reload it, you'll face the problem that the Balance changed...so the balance is now not correct anymore

Thanks,
Priyesh

To post a comment you must log in.
Revision history for this message
Raphael Collet (OpenERP) (rco-openerp) wrote :

I have reworked a bit the code.
This also fixes a missing test on line.account_id when adding line.amount_currency.
Quentin should review this one...

Revision history for this message
qdp (OpenERP) (qdp) wrote :

Seems correct, but i didn't run it or tried with a real instance. I guess it's good to be merged if you did so.

as discussed, it should be a good idea to also include:
- a check that raises an error if the statement's journal and its default accounts don't share the same configuration for secondary currency.
- a domain in the account.move.line m2m of bank statements when going by "periodical processing \ bank reconciliation \ .." in order to make sure that people encode there only accounting entries with a correct secondary currency set.

Thanks,
Quentin

review: Approve
Revision history for this message
Raphael Collet (OpenERP) (rco-openerp) wrote :

Use case tested with success.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/account_bank_statement.py'
2--- account/account_bank_statement.py 2010-11-04 15:09:45 +0000
3+++ account/account_bank_statement.py 2011-09-20 08:23:52 +0000
4@@ -55,23 +55,21 @@
5 statements = self.browse(cursor, user, ids, context=context)
6 for statement in statements:
7 res[statement.id] = statement.balance_start
8- currency_id = statement.currency.id
9+ stmt_currency_id = statement.currency.id
10+ stmt_account_ids = (statement.journal_id.default_debit_account_id.id,
11+ statement.journal_id.default_credit_account_id.id)
12+ # add debits and credits of move lines related to the statement's journal
13 for line in statement.move_line_ids:
14- if line.debit > 0:
15- if line.account_id.id == \
16- statement.journal_id.default_debit_account_id.id:
17- res[statement.id] += res_currency_obj.compute(cursor,
18- user, company_currency_id, currency_id,
19- line.debit, context=context)
20- else:
21- if line.account_id.id == \
22- statement.journal_id.default_credit_account_id.id:
23- res[statement.id] -= res_currency_obj.compute(cursor,
24- user, company_currency_id, currency_id,
25- line.credit, context=context)
26+ if line.account_id.id in stmt_account_ids:
27+ if stmt_currency_id == company_currency_id:
28+ res[statement.id] += line.debit - line.credit
29+ else:
30+ res[statement.id] += line.amount_currency
31+ # add amounts of statement lines with no corresponding move lines
32 if statement.state == 'draft':
33 for line in statement.line_ids:
34 res[statement.id] += line.amount
35+
36 for r in res:
37 res[r] = round(res[r], 2)
38 return res