mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 16:34:46 +00:00
fix: handle finance book properly in trial balance and general ledger (#35085)
* fix: get default fb properly and handle different fb and default fb case * chore: minor UX improvement * fix: handle FBs properly in general ledger
This commit is contained in:
@@ -538,13 +538,20 @@ def apply_additional_conditions(doctype, query, from_date, ignore_closing_entrie
|
|||||||
query = query.where(gl_entry.cost_center.isin(filters.cost_center))
|
query = query.where(gl_entry.cost_center.isin(filters.cost_center))
|
||||||
|
|
||||||
if filters.get("include_default_book_entries"):
|
if filters.get("include_default_book_entries"):
|
||||||
|
company_fb = frappe.get_cached_value("Company", filters.company, "default_finance_book")
|
||||||
|
|
||||||
|
if filters.finance_book and company_fb and cstr(filters.finance_book) != cstr(company_fb):
|
||||||
|
frappe.throw(
|
||||||
|
_("To use a different finance book, please uncheck 'Include Default Book Entries'")
|
||||||
|
)
|
||||||
|
|
||||||
query = query.where(
|
query = query.where(
|
||||||
(gl_entry.finance_book.isin([cstr(filters.finance_book), cstr(filters.company_fb), ""]))
|
(gl_entry.finance_book.isin([cstr(filters.finance_book), cstr(company_fb)]))
|
||||||
| (gl_entry.finance_book.isnull())
|
| (gl_entry.finance_book.isnull())
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
query = query.where(
|
query = query.where(
|
||||||
(gl_entry.finance_book.isin([cstr(filters.company_fb), ""])) | (gl_entry.finance_book.isnull())
|
(gl_entry.finance_book.isin([cstr(filters.finance_book)])) | (gl_entry.finance_book.isnull())
|
||||||
)
|
)
|
||||||
|
|
||||||
if accounting_dimensions:
|
if accounting_dimensions:
|
||||||
|
|||||||
@@ -176,7 +176,8 @@ frappe.query_reports["General Ledger"] = {
|
|||||||
{
|
{
|
||||||
"fieldname": "include_default_book_entries",
|
"fieldname": "include_default_book_entries",
|
||||||
"label": __("Include Default Book Entries"),
|
"label": __("Include Default Book Entries"),
|
||||||
"fieldtype": "Check"
|
"fieldtype": "Check",
|
||||||
|
"default": 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"fieldname": "show_cancelled_entries",
|
"fieldname": "show_cancelled_entries",
|
||||||
|
|||||||
@@ -244,13 +244,23 @@ def get_conditions(filters):
|
|||||||
if filters.get("project"):
|
if filters.get("project"):
|
||||||
conditions.append("project in %(project)s")
|
conditions.append("project in %(project)s")
|
||||||
|
|
||||||
if filters.get("finance_book"):
|
if filters.get("include_default_book_entries"):
|
||||||
if filters.get("include_default_book_entries"):
|
if filters.get("finance_book"):
|
||||||
conditions.append(
|
if filters.get("company_fb") and cstr(filters.get("finance_book")) != cstr(
|
||||||
"(finance_book in (%(finance_book)s, %(company_fb)s, '') OR finance_book IS NULL)"
|
filters.get("company_fb")
|
||||||
)
|
):
|
||||||
|
frappe.throw(
|
||||||
|
_("To use a different finance book, please uncheck 'Include Default Book Entries'")
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
conditions.append("(finance_book in (%(finance_book)s) OR finance_book IS NULL)")
|
||||||
else:
|
else:
|
||||||
conditions.append("finance_book in (%(finance_book)s)")
|
conditions.append("(finance_book in (%(company_fb)s) OR finance_book IS NULL)")
|
||||||
|
else:
|
||||||
|
if filters.get("finance_book"):
|
||||||
|
conditions.append("(finance_book in (%(finance_book)s) OR finance_book IS NULL)")
|
||||||
|
else:
|
||||||
|
conditions.append("(finance_book IS NULL)")
|
||||||
|
|
||||||
if not filters.get("show_cancelled_entries"):
|
if not filters.get("show_cancelled_entries"):
|
||||||
conditions.append("is_cancelled = 0")
|
conditions.append("is_cancelled = 0")
|
||||||
|
|||||||
@@ -248,13 +248,20 @@ def get_opening_balance(
|
|||||||
opening_balance = opening_balance.where(closing_balance.project == filters.project)
|
opening_balance = opening_balance.where(closing_balance.project == filters.project)
|
||||||
|
|
||||||
if filters.get("include_default_book_entries"):
|
if filters.get("include_default_book_entries"):
|
||||||
|
company_fb = frappe.get_cached_value("Company", filters.company, "default_finance_book")
|
||||||
|
|
||||||
|
if filters.finance_book and company_fb and cstr(filters.finance_book) != cstr(company_fb):
|
||||||
|
frappe.throw(
|
||||||
|
_("To use a different finance book, please uncheck 'Include Default Book Entries'")
|
||||||
|
)
|
||||||
|
|
||||||
opening_balance = opening_balance.where(
|
opening_balance = opening_balance.where(
|
||||||
(closing_balance.finance_book.isin([cstr(filters.finance_book), cstr(filters.company_fb), ""]))
|
(closing_balance.finance_book.isin([cstr(filters.finance_book), cstr(company_fb)]))
|
||||||
| (closing_balance.finance_book.isnull())
|
| (closing_balance.finance_book.isnull())
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
opening_balance = opening_balance.where(
|
opening_balance = opening_balance.where(
|
||||||
(closing_balance.finance_book.isin([cstr(filters.finance_book), ""]))
|
(closing_balance.finance_book.isin([cstr(filters.finance_book)]))
|
||||||
| (closing_balance.finance_book.isnull())
|
| (closing_balance.finance_book.isnull())
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user