Merge branch 'develop' into dims_in_gl_report
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.js b/erpnext/accounts/report/general_ledger/general_ledger.js
index 1fc0f79..fb0d359 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.js
+++ b/erpnext/accounts/report/general_ledger/general_ledger.js
@@ -147,6 +147,12 @@
}
},
{
+ "fieldname": "include_dimensions",
+ "label": __("Consider Accounting Dimensions"),
+ "fieldtype": "Check",
+ "default": 0
+ },
+ {
"fieldname": "show_opening_entries",
"label": __("Show Opening Entries"),
"fieldtype": "Check"
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py
index 0a72f6a..0599707 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.py
+++ b/erpnext/accounts/report/general_ledger/general_ledger.py
@@ -106,15 +106,20 @@
return filters
def get_result(filters, account_details):
- gl_entries = get_gl_entries(filters)
+ accounting_dimensions = []
+ if filters.get("include_dimensions"):
+ accounting_dimensions = get_accounting_dimensions()
- data = get_data_with_opening_closing(filters, account_details, gl_entries)
+ gl_entries = get_gl_entries(filters, accounting_dimensions)
+
+ data = get_data_with_opening_closing(filters, account_details,
+ accounting_dimensions, gl_entries)
result = get_result_as_list(data, filters)
return result
-def get_gl_entries(filters):
+def get_gl_entries(filters, accounting_dimensions):
currency_map = get_currency(filters)
select_fields = """, debit, credit, debit_in_account_currency,
credit_in_account_currency """
@@ -128,6 +133,10 @@
filters['company_fb'] = frappe.db.get_value("Company",
filters.get("company"), 'default_finance_book')
+ dimension_fields = ""
+ if accounting_dimensions:
+ dimension_fields = ', '.join(accounting_dimensions) + ','
+
distributed_cost_center_query = ""
if filters and filters.get('cost_center'):
select_fields_with_percentage = """, debit*(DCC_allocation.percentage_allocation/100) as debit, credit*(DCC_allocation.percentage_allocation/100) as credit, debit_in_account_currency*(DCC_allocation.percentage_allocation/100) as debit_in_account_currency,
@@ -141,7 +150,7 @@
party_type,
party,
voucher_type,
- voucher_no,
+ voucher_no, {dimension_fields}
cost_center, project,
against_voucher_type,
against_voucher,
@@ -160,13 +169,14 @@
{conditions}
AND posting_date <= %(to_date)s
AND cost_center = DCC_allocation.parent
- """.format(select_fields_with_percentage=select_fields_with_percentage, conditions=get_conditions(filters).replace("and cost_center in %(cost_center)s ", ''))
+ """.format(dimension_fields=dimension_fields,select_fields_with_percentage=select_fields_with_percentage, conditions=get_conditions(filters).replace("and cost_center in %(cost_center)s ", ''))
gl_entries = frappe.db.sql(
"""
select
name as gl_entry, posting_date, account, party_type, party,
- voucher_type, voucher_no, cost_center, project,
+ voucher_type, voucher_no, {dimension_fields}
+ cost_center, project,
against_voucher_type, against_voucher, account_currency,
remarks, against, is_opening, creation {select_fields}
from `tabGL Entry`
@@ -174,7 +184,7 @@
{distributed_cost_center_query}
{order_by_statement}
""".format(
- select_fields=select_fields, conditions=get_conditions(filters), distributed_cost_center_query=distributed_cost_center_query,
+ dimension_fields=dimension_fields, select_fields=select_fields, conditions=get_conditions(filters), distributed_cost_center_query=distributed_cost_center_query,
order_by_statement=order_by_statement
),
filters, as_dict=1)
@@ -247,12 +257,12 @@
return "and {}".format(" and ".join(conditions)) if conditions else ""
-def get_data_with_opening_closing(filters, account_details, gl_entries):
+def get_data_with_opening_closing(filters, account_details, accounting_dimensions, gl_entries):
data = []
gle_map = initialize_gle_map(gl_entries, filters)
- totals, entries = get_accountwise_gle(filters, gl_entries, gle_map)
+ totals, entries = get_accountwise_gle(filters, accounting_dimensions, gl_entries, gle_map)
# Opening for filtered account
data.append(totals.opening)
@@ -318,7 +328,7 @@
return gle_map
-def get_accountwise_gle(filters, gl_entries, gle_map):
+def get_accountwise_gle(filters, accounting_dimensions, gl_entries, gle_map):
totals = get_totals_dict()
entries = []
consolidated_gle = OrderedDict()
@@ -350,8 +360,11 @@
if filters.get("group_by") != _('Group by Voucher (Consolidated)'):
gle_map[gle.get(group_by)].entries.append(gle)
elif filters.get("group_by") == _('Group by Voucher (Consolidated)'):
- key = (gle.get("voucher_type"), gle.get("voucher_no"),
- gle.get("account"), gle.get("cost_center"))
+ keylist = [gle.get("voucher_type"), gle.get("voucher_no"), gle.get("account")]
+ for dim in accounting_dimensions:
+ keylist.append(gle.get(dim))
+ keylist.append(gle.get("cost_center"))
+ key = tuple(keylist)
if key not in consolidated_gle:
consolidated_gle.setdefault(key, gle)
else:
@@ -478,7 +491,19 @@
"options": "Project",
"fieldname": "project",
"width": 100
- },
+ }
+ ])
+
+ if filters.get("include_dimensions"):
+ for dim in get_accounting_dimensions(as_list = False):
+ columns.append({
+ "label": _(dim.label),
+ "options": dim.label,
+ "fieldname": dim.fieldname,
+ "width": 100
+ })
+
+ columns.extend([
{
"label": _("Cost Center"),
"options": "Cost Center",