Added new option group by voucher(consolidated) in the general ledger report (#15957)
This commit is contained in:
parent
5e85ab3b67
commit
ab76ff0836
@ -196,8 +196,9 @@ frappe.query_reports["General Ledger"] = {
|
|||||||
"fieldname":"group_by",
|
"fieldname":"group_by",
|
||||||
"label": __("Group by"),
|
"label": __("Group by"),
|
||||||
"fieldtype": "Select",
|
"fieldtype": "Select",
|
||||||
"options": ["", "Group by Voucher", "Group by Account", "Group by Party"],
|
"options": ["", __("Group by Voucher"), __("Group by Voucher (Consolidated)"),
|
||||||
"default": "Group by Voucher"
|
__("Group by Account"), __("Group by Party")],
|
||||||
|
"default": __("Group by Voucher (Consolidated)")
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname":"tax_id",
|
"fieldname":"tax_id",
|
||||||
|
@ -16,6 +16,8 @@ def execute(filters=None):
|
|||||||
return [], []
|
return [], []
|
||||||
|
|
||||||
account_details = {}
|
account_details = {}
|
||||||
|
if not filters.get("group_by"):
|
||||||
|
filters['group_by'] = _('Group by Voucher (Consolidated)')
|
||||||
|
|
||||||
if filters and filters.get('print_in_account_currency') and \
|
if filters and filters.get('print_in_account_currency') and \
|
||||||
not filters.get('account'):
|
not filters.get('account'):
|
||||||
@ -48,11 +50,12 @@ def validate_filters(filters, account_details):
|
|||||||
if filters.get("account") and not account_details.get(filters.account):
|
if filters.get("account") and not account_details.get(filters.account):
|
||||||
frappe.throw(_("Account {0} does not exists").format(filters.account))
|
frappe.throw(_("Account {0} does not exists").format(filters.account))
|
||||||
|
|
||||||
if (filters.get("account") and filters.get("group_by") == 'Group by Account'
|
if (filters.get("account") and filters.get("group_by") == _('Group by Account')
|
||||||
and account_details[filters.account].is_group == 0):
|
and account_details[filters.account].is_group == 0):
|
||||||
frappe.throw(_("Can not filter based on Account, if grouped by Account"))
|
frappe.throw(_("Can not filter based on Account, if grouped by Account"))
|
||||||
|
|
||||||
if (filters.get("voucher_no") and filters.get("group_by") == 'Group by Voucher'):
|
if (filters.get("voucher_no")
|
||||||
|
and filters.get("group_by") in [_('Group by Voucher'), _('Group by Voucher (Consolidated)')]):
|
||||||
frappe.throw(_("Can not filter based on Voucher No, if grouped by Voucher"))
|
frappe.throw(_("Can not filter based on Voucher No, if grouped by Voucher"))
|
||||||
|
|
||||||
if filters.from_date > filters.to_date:
|
if filters.from_date > filters.to_date:
|
||||||
@ -114,30 +117,37 @@ def get_result(filters, account_details):
|
|||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def get_gl_entries(filters):
|
def get_gl_entries(filters):
|
||||||
currency_map = get_currency(filters)
|
currency_map = get_currency(filters)
|
||||||
select_fields = """, debit_in_account_currency,
|
select_fields = """, debit, credit, debit_in_account_currency,
|
||||||
credit_in_account_currency""" \
|
credit_in_account_currency """
|
||||||
|
|
||||||
order_by_fields = "posting_date, account"
|
group_by_statement = ''
|
||||||
if filters.get("group_by") == "Group by Voucher":
|
order_by_statement = "order by posting_date, account"
|
||||||
order_by_fields = "posting_date, voucher_type, voucher_no"
|
|
||||||
|
if filters.get("group_by") == _("Group by Voucher"):
|
||||||
|
order_by_statement = "order by posting_date, voucher_type, voucher_no"
|
||||||
|
|
||||||
|
if filters.get("group_by") == _("Group by Voucher (Consolidated)"):
|
||||||
|
group_by_statement = "group by voucher_type, voucher_no, account, cost_center"
|
||||||
|
select_fields = """, sum(debit) as debit, sum(credit) as credit,
|
||||||
|
sum(debit_in_account_currency) as debit_in_account_currency,
|
||||||
|
sum(credit_in_account_currency) as credit_in_account_currency"""
|
||||||
|
|
||||||
gl_entries = frappe.db.sql(
|
gl_entries = frappe.db.sql(
|
||||||
"""
|
"""
|
||||||
select
|
select
|
||||||
posting_date, account, party_type, party,
|
posting_date, account, party_type, party,
|
||||||
debit, credit,
|
|
||||||
voucher_type, voucher_no, cost_center, project,
|
voucher_type, voucher_no, cost_center, project,
|
||||||
against_voucher_type, against_voucher, account_currency,
|
against_voucher_type, against_voucher, account_currency,
|
||||||
remarks, against, is_opening {select_fields}
|
remarks, against, is_opening {select_fields}
|
||||||
from `tabGL Entry`
|
from `tabGL Entry`
|
||||||
where company=%(company)s {conditions}
|
where company=%(company)s {conditions} {group_by_statement}
|
||||||
order by {order_by_fields}
|
{order_by_statement}
|
||||||
""".format(
|
""".format(
|
||||||
select_fields=select_fields, conditions=get_conditions(filters),
|
select_fields=select_fields, conditions=get_conditions(filters),
|
||||||
order_by_fields=order_by_fields
|
group_by_statement=group_by_statement,
|
||||||
|
order_by_statement=order_by_statement
|
||||||
),
|
),
|
||||||
filters, as_dict=1)
|
filters, as_dict=1)
|
||||||
|
|
||||||
@ -204,13 +214,13 @@ def get_data_with_opening_closing(filters, account_details, gl_entries):
|
|||||||
# Opening for filtered account
|
# Opening for filtered account
|
||||||
data.append(totals.opening)
|
data.append(totals.opening)
|
||||||
|
|
||||||
if filters.get("group_by"):
|
if filters.get("group_by") != _('Group by Voucher (Consolidated)'):
|
||||||
for acc, acc_dict in iteritems(gle_map):
|
for acc, acc_dict in iteritems(gle_map):
|
||||||
# acc
|
# acc
|
||||||
if acc_dict.entries:
|
if acc_dict.entries:
|
||||||
# opening
|
# opening
|
||||||
data.append({})
|
data.append({})
|
||||||
if filters.get("group_by") != "Group by Voucher":
|
if filters.get("group_by") != _("Group by Voucher"):
|
||||||
data.append(acc_dict.totals.opening)
|
data.append(acc_dict.totals.opening)
|
||||||
|
|
||||||
data += acc_dict.entries
|
data += acc_dict.entries
|
||||||
@ -219,10 +229,9 @@ def get_data_with_opening_closing(filters, account_details, gl_entries):
|
|||||||
data.append(acc_dict.totals.total)
|
data.append(acc_dict.totals.total)
|
||||||
|
|
||||||
# closing
|
# closing
|
||||||
if filters.get("group_by") != "Group by Voucher":
|
if filters.get("group_by") != _("Group by Voucher"):
|
||||||
data.append(acc_dict.totals.closing)
|
data.append(acc_dict.totals.closing)
|
||||||
data.append({})
|
data.append({})
|
||||||
|
|
||||||
else:
|
else:
|
||||||
data += entries
|
data += entries
|
||||||
|
|
||||||
@ -234,7 +243,6 @@ def get_data_with_opening_closing(filters, account_details, gl_entries):
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def get_totals_dict():
|
def get_totals_dict():
|
||||||
def _get_debit_credit_dict(label):
|
def _get_debit_credit_dict(label):
|
||||||
return _dict(
|
return _dict(
|
||||||
@ -251,12 +259,12 @@ def get_totals_dict():
|
|||||||
)
|
)
|
||||||
|
|
||||||
def group_by_field(group_by):
|
def group_by_field(group_by):
|
||||||
if group_by == 'Group by Party':
|
if group_by == _('Group by Party'):
|
||||||
return 'party'
|
return 'party'
|
||||||
elif group_by == 'Group by Voucher':
|
elif group_by in [_('Group by Voucher (Consolidated)'), _('Group by Account')]:
|
||||||
return 'voucher_no'
|
|
||||||
else:
|
|
||||||
return 'account'
|
return 'account'
|
||||||
|
else:
|
||||||
|
return 'voucher_no'
|
||||||
|
|
||||||
def initialize_gle_map(gl_entries, filters):
|
def initialize_gle_map(gl_entries, filters):
|
||||||
gle_map = frappe._dict()
|
gle_map = frappe._dict()
|
||||||
@ -291,7 +299,7 @@ def get_accountwise_gle(filters, gl_entries, gle_map):
|
|||||||
elif gle.posting_date <= to_date:
|
elif gle.posting_date <= to_date:
|
||||||
update_value_in_dict(gle_map[gle.get(group_by)].totals, 'total', gle)
|
update_value_in_dict(gle_map[gle.get(group_by)].totals, 'total', gle)
|
||||||
update_value_in_dict(totals, 'total', gle)
|
update_value_in_dict(totals, 'total', gle)
|
||||||
if filters.get("group_by"):
|
if filters.get("group_by") != _('Group by Voucher (Consolidated)'):
|
||||||
gle_map[gle.get(group_by)].entries.append(gle)
|
gle_map[gle.get(group_by)].entries.append(gle)
|
||||||
else:
|
else:
|
||||||
entries.append(gle)
|
entries.append(gle)
|
||||||
@ -301,7 +309,6 @@ def get_accountwise_gle(filters, gl_entries, gle_map):
|
|||||||
|
|
||||||
return totals, entries
|
return totals, entries
|
||||||
|
|
||||||
|
|
||||||
def get_result_as_list(data, filters):
|
def get_result_as_list(data, filters):
|
||||||
balance, balance_in_account_currency = 0, 0
|
balance, balance_in_account_currency = 0, 0
|
||||||
inv_details = get_supplier_invoice_details()
|
inv_details = get_supplier_invoice_details()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user