[IMP] improve handling of account move lines when computing statement balance
authorRaphael Collet <rco@openerp.com>
Tue, 20 Sep 2011 08:06:17 +0000 (10:06 +0200)
committerRaphael Collet <rco@openerp.com>
Tue, 20 Sep 2011 08:06:17 +0000 (10:06 +0200)
bzr revid: rco@openerp.com-20110920080617-drxwikpe46t6bzp1

addons/account/account_bank_statement.py

index 7c419fd..949e3b8 100644 (file)
@@ -55,24 +55,21 @@ class account_bank_statement(osv.osv):
         statements = self.browse(cursor, user, ids, context=context)
         for statement in statements:
             res[statement.id] = statement.balance_start
-            currency_id = statement.currency.id
+            stmt_currency_id = statement.currency.id
+            stmt_account_ids = (statement.journal_id.default_debit_account_id.id,
+                                statement.journal_id.default_credit_account_id.id)
+            # add debits and credits of move lines related to the statement's journal
             for line in statement.move_line_ids:
-                if currency_id == company_currency_id:
-                    if line.debit > 0:
-                        if line.account_id.id == \
-                                statement.journal_id.default_debit_account_id.id:
-                            res[statement.id] += line.debit
+                if line.account_id.id in stmt_account_ids:
+                    if stmt_currency_id == company_currency_id:
+                        res[statement.id] += line.debit - line.credit
                     else:
-                        if line.account_id.id == \
-                                statement.journal_id.default_credit_account_id.id:
-                            res[statement.id] -= line.credit
-                else:
-                    if line.amount_currency > 0:
                         res[statement.id] += line.amount_currency
-
+            # add amounts of statement lines with no corresponding move lines
             if statement.state == 'draft':
                 for line in statement.line_ids:
                     res[statement.id] += line.amount
+        
         for r in res:
             res[r] = round(res[r], 2)
         return res