perf(minor): general ledger report (#27987)
This commit is contained in:
parent
fdb8e1855d
commit
ecbe4b16b8
@ -6,7 +6,7 @@ from collections import OrderedDict
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _, _dict
|
from frappe import _, _dict
|
||||||
from frappe.utils import cstr, flt, getdate
|
from frappe.utils import cstr, getdate
|
||||||
|
|
||||||
from erpnext import get_company_currency, get_default_company
|
from erpnext import get_company_currency, get_default_company
|
||||||
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import (
|
||||||
@ -17,6 +17,8 @@ from erpnext.accounts.report.financial_statements import get_cost_centers_with_c
|
|||||||
from erpnext.accounts.report.utils import convert_to_presentation_currency, get_currency
|
from erpnext.accounts.report.utils import convert_to_presentation_currency, get_currency
|
||||||
from erpnext.accounts.utils import get_account_currency
|
from erpnext.accounts.utils import get_account_currency
|
||||||
|
|
||||||
|
# to cache translations
|
||||||
|
TRANSLATIONS = frappe._dict()
|
||||||
|
|
||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
if not filters:
|
if not filters:
|
||||||
@ -42,10 +44,20 @@ def execute(filters=None):
|
|||||||
|
|
||||||
columns = get_columns(filters)
|
columns = get_columns(filters)
|
||||||
|
|
||||||
|
update_translations()
|
||||||
|
|
||||||
res = get_result(filters, account_details)
|
res = get_result(filters, account_details)
|
||||||
|
|
||||||
return columns, res
|
return columns, res
|
||||||
|
|
||||||
|
def update_translations():
|
||||||
|
TRANSLATIONS.update(
|
||||||
|
dict(
|
||||||
|
OPENING = _('Opening'),
|
||||||
|
TOTAL = _('Total'),
|
||||||
|
CLOSING_TOTAL = _('Closing (Opening + Total)')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
def validate_filters(filters, account_details):
|
def validate_filters(filters, account_details):
|
||||||
if not filters.get("company"):
|
if not filters.get("company"):
|
||||||
@ -351,9 +363,9 @@ def get_totals_dict():
|
|||||||
credit_in_account_currency=0.0
|
credit_in_account_currency=0.0
|
||||||
)
|
)
|
||||||
return _dict(
|
return _dict(
|
||||||
opening = _get_debit_credit_dict(_('Opening')),
|
opening = _get_debit_credit_dict(TRANSLATIONS.OPENING),
|
||||||
total = _get_debit_credit_dict(_('Total')),
|
total = _get_debit_credit_dict(TRANSLATIONS.TOTAL),
|
||||||
closing = _get_debit_credit_dict(_('Closing (Opening + Total)'))
|
closing = _get_debit_credit_dict(TRANSLATIONS.CLOSING_TOTAL)
|
||||||
)
|
)
|
||||||
|
|
||||||
def group_by_field(group_by):
|
def group_by_field(group_by):
|
||||||
@ -378,22 +390,23 @@ def get_accountwise_gle(filters, accounting_dimensions, gl_entries, gle_map):
|
|||||||
entries = []
|
entries = []
|
||||||
consolidated_gle = OrderedDict()
|
consolidated_gle = OrderedDict()
|
||||||
group_by = group_by_field(filters.get('group_by'))
|
group_by = group_by_field(filters.get('group_by'))
|
||||||
|
group_by_voucher_consolidated = filters.get("group_by") == 'Group by Voucher (Consolidated)'
|
||||||
|
|
||||||
if filters.get('show_net_values_in_party_account'):
|
if filters.get('show_net_values_in_party_account'):
|
||||||
account_type_map = get_account_type_map(filters.get('company'))
|
account_type_map = get_account_type_map(filters.get('company'))
|
||||||
|
|
||||||
def update_value_in_dict(data, key, gle):
|
def update_value_in_dict(data, key, gle):
|
||||||
data[key].debit += flt(gle.debit)
|
data[key].debit += gle.debit
|
||||||
data[key].credit += flt(gle.credit)
|
data[key].credit += gle.credit
|
||||||
|
|
||||||
data[key].debit_in_account_currency += flt(gle.debit_in_account_currency)
|
data[key].debit_in_account_currency += gle.debit_in_account_currency
|
||||||
data[key].credit_in_account_currency += flt(gle.credit_in_account_currency)
|
data[key].credit_in_account_currency += gle.credit_in_account_currency
|
||||||
|
|
||||||
if filters.get('show_net_values_in_party_account') and \
|
if filters.get('show_net_values_in_party_account') and \
|
||||||
account_type_map.get(data[key].account) in ('Receivable', 'Payable'):
|
account_type_map.get(data[key].account) in ('Receivable', 'Payable'):
|
||||||
net_value = flt(data[key].debit) - flt(data[key].credit)
|
net_value = data[key].debit - data[key].credit
|
||||||
net_value_in_account_currency = flt(data[key].debit_in_account_currency) \
|
net_value_in_account_currency = data[key].debit_in_account_currency \
|
||||||
- flt(data[key].credit_in_account_currency)
|
- data[key].credit_in_account_currency
|
||||||
|
|
||||||
if net_value < 0:
|
if net_value < 0:
|
||||||
dr_or_cr = 'credit'
|
dr_or_cr = 'credit'
|
||||||
@ -411,19 +424,29 @@ def get_accountwise_gle(filters, accounting_dimensions, gl_entries, gle_map):
|
|||||||
data[key].against_voucher += ', ' + gle.against_voucher
|
data[key].against_voucher += ', ' + gle.against_voucher
|
||||||
|
|
||||||
from_date, to_date = getdate(filters.from_date), getdate(filters.to_date)
|
from_date, to_date = getdate(filters.from_date), getdate(filters.to_date)
|
||||||
for gle in gl_entries:
|
show_opening_entries = filters.get("show_opening_entries")
|
||||||
if (gle.posting_date < from_date or
|
|
||||||
(cstr(gle.is_opening) == "Yes" and not filters.get("show_opening_entries"))):
|
|
||||||
update_value_in_dict(gle_map[gle.get(group_by)].totals, 'opening', gle)
|
|
||||||
update_value_in_dict(totals, 'opening', gle)
|
|
||||||
|
|
||||||
update_value_in_dict(gle_map[gle.get(group_by)].totals, 'closing', gle)
|
for gle in gl_entries:
|
||||||
|
group_by_value = gle.get(group_by)
|
||||||
|
|
||||||
|
if (gle.posting_date < from_date or (cstr(gle.is_opening) == "Yes" and not show_opening_entries)):
|
||||||
|
if not group_by_voucher_consolidated:
|
||||||
|
update_value_in_dict(gle_map[group_by_value].totals, 'opening', gle)
|
||||||
|
update_value_in_dict(gle_map[group_by_value].totals, 'closing', gle)
|
||||||
|
|
||||||
|
update_value_in_dict(totals, 'opening', gle)
|
||||||
update_value_in_dict(totals, 'closing', gle)
|
update_value_in_dict(totals, 'closing', gle)
|
||||||
|
|
||||||
elif gle.posting_date <= to_date:
|
elif gle.posting_date <= to_date:
|
||||||
if filters.get("group_by") != 'Group by Voucher (Consolidated)':
|
if not group_by_voucher_consolidated:
|
||||||
gle_map[gle.get(group_by)].entries.append(gle)
|
update_value_in_dict(gle_map[group_by_value].totals, 'total', gle)
|
||||||
elif filters.get("group_by") == 'Group by Voucher (Consolidated)':
|
update_value_in_dict(gle_map[group_by_value].totals, 'closing', gle)
|
||||||
|
update_value_in_dict(totals, 'total', gle)
|
||||||
|
update_value_in_dict(totals, 'closing', gle)
|
||||||
|
|
||||||
|
gle_map[group_by_value].entries.append(gle)
|
||||||
|
|
||||||
|
elif group_by_voucher_consolidated:
|
||||||
keylist = [gle.get("voucher_type"), gle.get("voucher_no"), gle.get("account")]
|
keylist = [gle.get("voucher_type"), gle.get("voucher_no"), gle.get("account")]
|
||||||
for dim in accounting_dimensions:
|
for dim in accounting_dimensions:
|
||||||
keylist.append(gle.get(dim))
|
keylist.append(gle.get(dim))
|
||||||
@ -435,9 +458,7 @@ def get_accountwise_gle(filters, accounting_dimensions, gl_entries, gle_map):
|
|||||||
update_value_in_dict(consolidated_gle, key, gle)
|
update_value_in_dict(consolidated_gle, key, gle)
|
||||||
|
|
||||||
for key, value in consolidated_gle.items():
|
for key, value in consolidated_gle.items():
|
||||||
update_value_in_dict(gle_map[value.get(group_by)].totals, 'total', value)
|
|
||||||
update_value_in_dict(totals, 'total', value)
|
update_value_in_dict(totals, 'total', value)
|
||||||
update_value_in_dict(gle_map[value.get(group_by)].totals, 'closing', value)
|
|
||||||
update_value_in_dict(totals, 'closing', value)
|
update_value_in_dict(totals, 'closing', value)
|
||||||
entries.append(value)
|
entries.append(value)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user