Browse Source
[IMP] dynamic_accounts_report: speedup generating General Ledge, Partner Ledger and Balance Sheet
pull/190/head
Eugene Molotov
4 years ago
No known key found for this signature in database
GPG Key ID: D656FCE7543D05F9
3 changed files with
16 additions and
9 deletions
-
dynamic_accounts_report/wizard/balance_sheet.py
-
dynamic_accounts_report/wizard/general_ledger.py
-
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 |
|
|
@ -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 |
|
|
|
|
|
@ -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) |
|
|
|
|
|
|
|
|
|
@ -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) |
|
|
|