diff --git a/dynamic_accounts_report/wizard/balance_sheet.py b/dynamic_accounts_report/wizard/balance_sheet.py index 0c23807f4..a6c3daa13 100644 --- a/dynamic_accounts_report/wizard/balance_sheet.py +++ b/dynamic_accounts_report/wizard/balance_sheet.py @@ -1,4 +1,5 @@ import time +from collections import defaultdict from odoo import fields, models, api, _ import io @@ -469,11 +470,11 @@ class BalanceSheetView(models.TransientModel): params = (tuple(accounts.ids),) + tuple(where_params) cr.execute(sql, params) + balance_dict = defaultdict(float) for row in cr.dictfetchall(): - balance = 0 - for line in move_lines.get(row['account_id']): - balance += round(line['debit'], 2) - round(line['credit'], 2) + balance = balance_dict[row['account_id']] row['balance'] += (round(balance, 2)) + balance_dict[row['account_id']] += round(row['debit'], 2) - round(row['credit'], 2) row['m_id'] = row['account_id'] move_lines[row.pop('account_id')].append(row) # Calculate the debit, credit and balance for Accounts diff --git a/dynamic_accounts_report/wizard/general_ledger.py b/dynamic_accounts_report/wizard/general_ledger.py index 51a80c4f1..77ddefcba 100644 --- a/dynamic_accounts_report/wizard/general_ledger.py +++ b/dynamic_accounts_report/wizard/general_ledger.py @@ -336,11 +336,16 @@ class GeneralView(models.TransientModel): params = (tuple(accounts.ids),) + tuple(where_params) cr.execute(sql, params) + balance_dict = {} for row in cr.dictfetchall(): - balance = 0 - for line in move_lines.get(row['account_id']): - balance += round(line['debit'],2) - round(line['credit'],2) + if row['account_id'] in balance_dict: + balance = balance_dict[row['account_id']] + else: + balance = balance_dict[row['account_id']] = 0 + for line in move_lines.get(row['account_id']): + balance += round(line['debit'], 2) - round(line['credit'], 2) row['balance'] += round(balance,2) + balance_dict[row['account_id']] += round(row['debit'], 2) - round(row['credit'], 2) row['m_id'] = row['account_id'] move_lines[row.pop('account_id')].append(row) diff --git a/dynamic_accounts_report/wizard/partner_leadger.py b/dynamic_accounts_report/wizard/partner_leadger.py index f7bddd88c..ad51b861e 100644 --- a/dynamic_accounts_report/wizard/partner_leadger.py +++ b/dynamic_accounts_report/wizard/partner_leadger.py @@ -1,4 +1,5 @@ import time +from collections import defaultdict from odoo import fields, models, api, _ import io @@ -298,12 +299,12 @@ class PartnerView(models.TransientModel): account_list = { x.id : {'name' : x.name, 'code': x.code} for x in accounts} + balance_dict = defaultdict(float) for row in cr.dictfetchall(): - balance = 0 if row['partner_id'] in move_lines: - for line in move_lines.get(row['partner_id']): - balance += round(line['debit'],2) - round(line['credit'],2) + balance = balance_dict[row['partner_id']] row['balance'] += (round(balance, 2)) + balance_dict[row['partner_id']] += round(row['debit'], 2) - round(row['credit'], 2) row['m_id'] = row['account_id'] row['account_name'] = account_list[row['account_id']]['name'] + "(" +account_list[row['account_id']]['code'] + ")" move_lines[row.pop('partner_id')].append(row)