Added finance book in trial balance and fixed cost center not working issue in trial balance
diff --git a/erpnext/accounts/report/trial_balance/trial_balance.js b/erpnext/accounts/report/trial_balance/trial_balance.js
index c09fa71..194f1bd 100644
--- a/erpnext/accounts/report/trial_balance/trial_balance.js
+++ b/erpnext/accounts/report/trial_balance/trial_balance.js
@@ -13,21 +13,6 @@
"reqd": 1
},
{
- "fieldname":"cost_center",
- "label": __("Cost Center"),
- "fieldtype": "Link",
- "options": "Cost Center",
- "get_query": function() {
- var company = frappe.query_report.get_filter_value('company');
- return {
- "doctype": "Cost Center",
- "filters": {
- "company": company,
- }
- }
- }
- },
- {
"fieldname": "fiscal_year",
"label": __("Fiscal Year"),
"fieldtype": "Link",
@@ -61,6 +46,27 @@
"default": frappe.defaults.get_user_default("year_end_date"),
},
{
+ "fieldname":"cost_center",
+ "label": __("Cost Center"),
+ "fieldtype": "Link",
+ "options": "Cost Center",
+ "get_query": function() {
+ var company = frappe.query_report.get_filter_value('company');
+ return {
+ "doctype": "Cost Center",
+ "filters": {
+ "company": company,
+ }
+ }
+ }
+ },
+ {
+ "fieldname":"finance_book",
+ "label": __("Finance Book"),
+ "fieldtype": "Link",
+ "options": "Finance Book",
+ },
+ {
"fieldname": "with_period_closing_entry",
"label": __("Period Closing Entry"),
"fieldtype": "Check",
@@ -75,6 +81,11 @@
"fieldname": "show_unclosed_fy_pl_balances",
"label": __("Show unclosed fiscal year's P&L balances"),
"fieldtype": "Check"
+ },
+ {
+ "fieldname": "include_non_finance_book_entries",
+ "label": __("Include Non Finance Book Entries"),
+ "fieldtype": "Check"
}
],
"formatter": erpnext.financial_statements.formatter,
diff --git a/erpnext/accounts/report/trial_balance/trial_balance.py b/erpnext/accounts/report/trial_balance/trial_balance.py
index 07dcd4e..696e63b 100644
--- a/erpnext/accounts/report/trial_balance/trial_balance.py
+++ b/erpnext/accounts/report/trial_balance/trial_balance.py
@@ -67,11 +67,10 @@
gl_entries_by_account = {}
+ opening_balances = get_opening_balances(filters)
set_gl_entries_by_account(filters.company, filters.from_date,
filters.to_date, min_lft, max_rgt, filters, gl_entries_by_account, ignore_closing_entries=not flt(filters.with_period_closing_entry))
- opening_balances = get_opening_balances(filters)
-
total_row = calculate_values(accounts, gl_entries_by_account, opening_balances, filters, company_currency)
accumulate_values_into_parents(accounts, accounts_by_name)
@@ -98,6 +97,18 @@
if not flt(filters.with_period_closing_entry):
additional_conditions += " and ifnull(voucher_type, '')!='Period Closing Voucher'"
+ if filters.cost_center:
+ lft, rgt = frappe.db.get_value('Cost Center', filters.cost_center, ['lft', 'rgt'])
+ additional_conditions += """ and cost_center in (select name from `tabCost Center`
+ where lft >= %s and rgt <= %s)""" % (lft, rgt)
+
+ if filters.finance_book:
+ fb_conditions = " and finance_book = %(finance_book)s"
+ if filters.include_non_finance_book_entries:
+ fb_conditions = " and (finance_book = %(finance_book)s or finance_book is null)"
+
+ additional_conditions += fb_conditions
+
gle = frappe.db.sql("""
select
account, sum(debit) as opening_debit, sum(credit) as opening_credit
@@ -112,7 +123,8 @@
"company": filters.company,
"from_date": filters.from_date,
"report_type": report_type,
- "year_start_date": filters.year_start_date
+ "year_start_date": filters.year_start_date,
+ "finance_book": filters.finance_book
},
as_dict=True)