fix: finance book filters includes the gl data which don't have finance book
This commit is contained in:
parent
93fc6004ad
commit
5f9793e081
@ -10,4 +10,10 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() {
|
|||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"default": 1
|
"default": 1
|
||||||
});
|
});
|
||||||
|
|
||||||
|
frappe.query_reports["Balance Sheet"]["filters"].push({
|
||||||
|
"fieldname": "include_default_book_entries",
|
||||||
|
"label": __("Include Default Book Entries"),
|
||||||
|
"fieldtype": "Check"
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@ -15,4 +15,10 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() {
|
|||||||
"label": __("Accumulated Values"),
|
"label": __("Accumulated Values"),
|
||||||
"fieldtype": "Check"
|
"fieldtype": "Check"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
frappe.query_reports["Cash Flow"]["filters"].push({
|
||||||
|
"fieldname": "include_default_book_entries",
|
||||||
|
"label": __("Include Default Book Entries"),
|
||||||
|
"fieldtype": "Check"
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@ -52,7 +52,7 @@ def execute(filters=None):
|
|||||||
|
|
||||||
for account in cash_flow_account['account_types']:
|
for account in cash_flow_account['account_types']:
|
||||||
account_data = get_account_type_based_data(filters.company,
|
account_data = get_account_type_based_data(filters.company,
|
||||||
account['account_type'], period_list, filters.accumulated_values)
|
account['account_type'], period_list, filters.accumulated_values, filters)
|
||||||
account_data.update({
|
account_data.update({
|
||||||
"account_name": account['label'],
|
"account_name": account['label'],
|
||||||
"account": account['label'],
|
"account": account['label'],
|
||||||
@ -105,13 +105,15 @@ def get_cash_flow_accounts():
|
|||||||
# combine all cash flow accounts for iteration
|
# combine all cash flow accounts for iteration
|
||||||
return [operation_accounts, investing_accounts, financing_accounts]
|
return [operation_accounts, investing_accounts, financing_accounts]
|
||||||
|
|
||||||
def get_account_type_based_data(company, account_type, period_list, accumulated_values):
|
def get_account_type_based_data(company, account_type, period_list, accumulated_values, filters):
|
||||||
data = {}
|
data = {}
|
||||||
total = 0
|
total = 0
|
||||||
for period in period_list:
|
for period in period_list:
|
||||||
start_date = get_start_date(period, accumulated_values, company)
|
start_date = get_start_date(period, accumulated_values, company)
|
||||||
|
|
||||||
amount = get_account_type_based_gl_data(company, start_date, period['to_date'], account_type)
|
amount = get_account_type_based_gl_data(company, start_date,
|
||||||
|
period['to_date'], account_type, filters)
|
||||||
|
|
||||||
if amount and account_type == "Depreciation":
|
if amount and account_type == "Depreciation":
|
||||||
amount *= -1
|
amount *= -1
|
||||||
|
|
||||||
@ -121,14 +123,24 @@ def get_account_type_based_data(company, account_type, period_list, accumulated_
|
|||||||
data["total"] = total
|
data["total"] = total
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_account_type_based_gl_data(company, start_date, end_date, account_type):
|
def get_account_type_based_gl_data(company, start_date, end_date, account_type, filters):
|
||||||
|
cond = ""
|
||||||
|
|
||||||
|
if filters.finance_book:
|
||||||
|
cond = " and finance_book = %s" %(frappe.db.escape(filters.finance_book))
|
||||||
|
if filters.include_default_book_entries:
|
||||||
|
company_fb = frappe.db.get_value("Company", company, 'default_finance_book')
|
||||||
|
|
||||||
|
cond = """ and finance_book in (%s, %s)
|
||||||
|
""" %(frappe.db.escape(filters.finance_book), frappe.db.escape(company_fb))
|
||||||
|
|
||||||
gl_sum = frappe.db.sql_list("""
|
gl_sum = frappe.db.sql_list("""
|
||||||
select sum(credit) - sum(debit)
|
select sum(credit) - sum(debit)
|
||||||
from `tabGL Entry`
|
from `tabGL Entry`
|
||||||
where company=%s and posting_date >= %s and posting_date <= %s
|
where company=%s and posting_date >= %s and posting_date <= %s
|
||||||
and voucher_type != 'Period Closing Voucher'
|
and voucher_type != 'Period Closing Voucher'
|
||||||
and account in ( SELECT name FROM tabAccount WHERE account_type = %s)
|
and account in ( SELECT name FROM tabAccount WHERE account_type = %s) {cond}
|
||||||
""", (company, start_date, end_date, account_type))
|
""".format(cond=cond), (company, start_date, end_date, account_type))
|
||||||
|
|
||||||
return gl_sum[0] if gl_sum and gl_sum[0] else 0
|
return gl_sum[0] if gl_sum and gl_sum[0] else 0
|
||||||
|
|
||||||
|
|||||||
@ -55,5 +55,10 @@ frappe.query_reports["Consolidated Financial Statement"] = {
|
|||||||
"fieldtype": "Check",
|
"fieldtype": "Check",
|
||||||
"default": 0
|
"default": 0
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "include_default_book_entries",
|
||||||
|
"label": __("Include Default Book Entries"),
|
||||||
|
"fieldtype": "Check"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -356,7 +356,8 @@ def set_gl_entries_by_account(from_date, to_date, root_lft, root_rgt, filters, g
|
|||||||
"lft": root_lft,
|
"lft": root_lft,
|
||||||
"rgt": root_rgt,
|
"rgt": root_rgt,
|
||||||
"company": d.name,
|
"company": d.name,
|
||||||
"finance_book": filters.get("finance_book")
|
"finance_book": filters.get("finance_book"),
|
||||||
|
"company_fb": frappe.db.get_value("Company", d.name, 'default_finance_book')
|
||||||
},
|
},
|
||||||
as_dict=True)
|
as_dict=True)
|
||||||
|
|
||||||
@ -387,7 +388,10 @@ def get_additional_conditions(from_date, ignore_closing_entries, filters):
|
|||||||
additional_conditions.append("gl.posting_date >= %(from_date)s")
|
additional_conditions.append("gl.posting_date >= %(from_date)s")
|
||||||
|
|
||||||
if filters.get("finance_book"):
|
if filters.get("finance_book"):
|
||||||
additional_conditions.append("ifnull(finance_book, '') in (%(finance_book)s, '')")
|
if filters.get("include_default_book_entries"):
|
||||||
|
additional_conditions.append("finance_book in (%(finance_book)s, %(company_fb)s)")
|
||||||
|
else:
|
||||||
|
additional_conditions.append("finance_book in (%(finance_book)s)")
|
||||||
|
|
||||||
return " and {}".format(" and ".join(additional_conditions)) if additional_conditions else ""
|
return " and {}".format(" and ".join(additional_conditions)) if additional_conditions else ""
|
||||||
|
|
||||||
|
|||||||
@ -355,6 +355,10 @@ def set_gl_entries_by_account(
|
|||||||
"to_date": to_date,
|
"to_date": to_date,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if filters.get("include_default_book_entries"):
|
||||||
|
gl_filters["company_fb"] = frappe.db.get_value("Company",
|
||||||
|
company, 'default_finance_book')
|
||||||
|
|
||||||
for key, value in filters.items():
|
for key, value in filters.items():
|
||||||
if value:
|
if value:
|
||||||
gl_filters.update({
|
gl_filters.update({
|
||||||
@ -399,7 +403,10 @@ def get_additional_conditions(from_date, ignore_closing_entries, filters):
|
|||||||
additional_conditions.append("cost_center in %(cost_center)s")
|
additional_conditions.append("cost_center in %(cost_center)s")
|
||||||
|
|
||||||
if filters.get("finance_book"):
|
if filters.get("finance_book"):
|
||||||
additional_conditions.append("ifnull(finance_book, '') in (%(finance_book)s, '')")
|
if filters.get("include_default_book_entries"):
|
||||||
|
additional_conditions.append("finance_book in (%(finance_book)s, %(company_fb)s)")
|
||||||
|
else:
|
||||||
|
additional_conditions.append("finance_book in (%(finance_book)s)")
|
||||||
|
|
||||||
if accounting_dimensions:
|
if accounting_dimensions:
|
||||||
for dimension in accounting_dimensions:
|
for dimension in accounting_dimensions:
|
||||||
|
|||||||
@ -217,6 +217,11 @@ frappe.query_reports["General Ledger"] = {
|
|||||||
"label": __("Show Opening Entries"),
|
"label": __("Show Opening Entries"),
|
||||||
"fieldtype": "Check"
|
"fieldtype": "Check"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "include_default_book_entries",
|
||||||
|
"label": __("Include Default Book Entries"),
|
||||||
|
"fieldtype": "Check"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -134,6 +134,10 @@ def get_gl_entries(filters):
|
|||||||
sum(debit_in_account_currency) as debit_in_account_currency,
|
sum(debit_in_account_currency) as debit_in_account_currency,
|
||||||
sum(credit_in_account_currency) as credit_in_account_currency"""
|
sum(credit_in_account_currency) as credit_in_account_currency"""
|
||||||
|
|
||||||
|
if filters.get("include_default_book_entries"):
|
||||||
|
filters['company_fb'] = frappe.db.get_value("Company",
|
||||||
|
filters.get("company"), 'default_finance_book')
|
||||||
|
|
||||||
gl_entries = frappe.db.sql(
|
gl_entries = frappe.db.sql(
|
||||||
"""
|
"""
|
||||||
select
|
select
|
||||||
@ -189,7 +193,10 @@ def get_conditions(filters):
|
|||||||
conditions.append("project in %(project)s")
|
conditions.append("project in %(project)s")
|
||||||
|
|
||||||
if filters.get("finance_book"):
|
if filters.get("finance_book"):
|
||||||
conditions.append("ifnull(finance_book, '') in (%(finance_book)s, '')")
|
if filters.get("include_default_book_entries"):
|
||||||
|
conditions.append("finance_book in (%(finance_book)s, %(company_fb)s)")
|
||||||
|
else:
|
||||||
|
conditions.append("finance_book in (%(finance_book)s)")
|
||||||
|
|
||||||
from frappe.desk.reportview import build_match_conditions
|
from frappe.desk.reportview import build_match_conditions
|
||||||
match_conditions = build_match_conditions("GL Entry")
|
match_conditions = build_match_conditions("GL Entry")
|
||||||
|
|||||||
@ -41,6 +41,11 @@ frappe.require("assets/erpnext/js/financial_statements.js", function() {
|
|||||||
"fieldname": "accumulated_values",
|
"fieldname": "accumulated_values",
|
||||||
"label": __("Accumulated Values"),
|
"label": __("Accumulated Values"),
|
||||||
"fieldtype": "Check"
|
"fieldtype": "Check"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fieldname": "include_default_book_entries",
|
||||||
|
"label": __("Include Default Book Entries"),
|
||||||
|
"fieldtype": "Check"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@ -105,7 +105,7 @@ def get_rootwise_opening_balances(filters, report_type):
|
|||||||
if filters.finance_book:
|
if filters.finance_book:
|
||||||
fb_conditions = " and finance_book = %(finance_book)s"
|
fb_conditions = " and finance_book = %(finance_book)s"
|
||||||
if filters.include_default_book_entries:
|
if filters.include_default_book_entries:
|
||||||
fb_conditions = " and (finance_book in (%(finance_book)s, %(company_fb)s) or finance_book is null)"
|
fb_conditions = " and (finance_book in (%(finance_book)s, %(company_fb)s))"
|
||||||
|
|
||||||
additional_conditions += fb_conditions
|
additional_conditions += fb_conditions
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user