Added finance book in trial balance and fixed cost center not working issue in trial balance

This commit is contained in:
Rohit Waghchaure 2019-01-15 15:52:52 +05:30
parent df7215dcb2
commit bdee57ca8d
2 changed files with 41 additions and 18 deletions

View File

@ -12,21 +12,6 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() {
"default": frappe.defaults.get_user_default("Company"),
"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"),
@ -60,6 +45,27 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() {
"fieldtype": "Date",
"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"),
@ -75,6 +81,11 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() {
"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,

View File

@ -67,11 +67,10 @@ def get_data(filters):
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 @@ def get_rootwise_opening_balances(filters, report_type):
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 @@ def get_rootwise_opening_balances(filters, report_type):
"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)