mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-02 03:39:11 +00:00
[hot] [fix] trial balance report
This commit is contained in:
@@ -80,12 +80,12 @@ def get_data(company, root_type, balance_must_be, period_list, ignore_closing_en
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
accounts, accounts_by_name = filter_accounts(accounts)
|
accounts, accounts_by_name = filter_accounts(accounts)
|
||||||
|
|
||||||
gl_entries_by_account = {}
|
gl_entries_by_account = {}
|
||||||
for root in frappe.db.sql("""select lft, rgt from tabAccount
|
for root in frappe.db.sql("""select lft, rgt from tabAccount
|
||||||
where root_type=%s and ifnull(parent_account, '') = ''""", root_type, as_dict=1):
|
where root_type=%s and ifnull(parent_account, '') = ''""", root_type, as_dict=1):
|
||||||
set_gl_entries_by_account(company, period_list[0]["from_date"],
|
set_gl_entries_by_account(company, period_list[0]["from_date"],
|
||||||
period_list[-1]["to_date"],root.lft, root.rgt, gl_entries_by_account,
|
period_list[-1]["to_date"],root.lft, root.rgt, gl_entries_by_account,
|
||||||
ignore_closing_entries=ignore_closing_entries)
|
ignore_closing_entries=ignore_closing_entries)
|
||||||
|
|
||||||
calculate_values(accounts_by_name, gl_entries_by_account, period_list)
|
calculate_values(accounts_by_name, gl_entries_by_account, period_list)
|
||||||
@@ -151,7 +151,7 @@ def add_total_row(out, balance_must_be, period_list):
|
|||||||
"account_name": "'" + _("Total ({0})").format(balance_must_be) + "'",
|
"account_name": "'" + _("Total ({0})").format(balance_must_be) + "'",
|
||||||
"account": None
|
"account": None
|
||||||
}
|
}
|
||||||
|
|
||||||
for row in out:
|
for row in out:
|
||||||
if not row.get("parent_account"):
|
if not row.get("parent_account"):
|
||||||
for period in period_list:
|
for period in period_list:
|
||||||
@@ -209,7 +209,7 @@ def sort_root_accounts(roots):
|
|||||||
|
|
||||||
roots.sort(compare_roots)
|
roots.sort(compare_roots)
|
||||||
|
|
||||||
def set_gl_entries_by_account(company, from_date, to_date, root_lft, root_rgt, gl_entries_by_account,
|
def set_gl_entries_by_account(company, from_date, to_date, root_lft, root_rgt, gl_entries_by_account,
|
||||||
ignore_closing_entries=False):
|
ignore_closing_entries=False):
|
||||||
"""Returns a dict like { "account": [gl entries], ... }"""
|
"""Returns a dict like { "account": [gl entries], ... }"""
|
||||||
additional_conditions = []
|
additional_conditions = []
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from __future__ import unicode_literals
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import cint, flt, getdate, formatdate, cstr
|
from frappe.utils import cint, flt, getdate, formatdate, cstr
|
||||||
from erpnext.accounts.report.financial_statements import filter_accounts, get_gl_entries
|
from erpnext.accounts.report.financial_statements import filter_accounts, set_gl_entries_by_account
|
||||||
|
|
||||||
value_fields = ("opening_debit", "opening_credit", "debit", "credit", "closing_debit", "closing_credit")
|
value_fields = ("opening_debit", "opening_credit", "debit", "credit", "closing_debit", "closing_credit")
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ def validate_filters(filters):
|
|||||||
filters.to_date = filters.year_end_date
|
filters.to_date = filters.year_end_date
|
||||||
|
|
||||||
def get_data(filters):
|
def get_data(filters):
|
||||||
accounts = frappe.db.sql("""select name, parent_account, account_name, root_type, report_type, lft, rgt
|
accounts = frappe.db.sql("""select name, parent_account, account_name, root_type, report_type, lft, rgt
|
||||||
from `tabAccount` where company=%s order by lft""", filters.company, as_dict=True)
|
from `tabAccount` where company=%s order by lft""", filters.company, as_dict=True)
|
||||||
|
|
||||||
if not accounts:
|
if not accounts:
|
||||||
@@ -56,8 +56,10 @@ def get_data(filters):
|
|||||||
min_lft, max_rgt = frappe.db.sql("""select min(lft), max(rgt) from `tabAccount`
|
min_lft, max_rgt = frappe.db.sql("""select min(lft), max(rgt) from `tabAccount`
|
||||||
where company=%s""", (filters.company,))[0]
|
where company=%s""", (filters.company,))[0]
|
||||||
|
|
||||||
gl_entries_by_account = get_gl_entries(filters.company, filters.from_date, filters.to_date, min_lft, max_rgt,
|
gl_entries_by_account = {}
|
||||||
ignore_closing_entries=not flt(filters.with_period_closing_entry))
|
|
||||||
|
set_gl_entries_by_account(filters.company, filters.from_date,
|
||||||
|
filters.to_date, min_lft, max_rgt, gl_entries_by_account, ignore_closing_entries=not flt(filters.with_period_closing_entry))
|
||||||
|
|
||||||
opening_balances = get_opening_balances(filters)
|
opening_balances = get_opening_balances(filters)
|
||||||
|
|
||||||
@@ -67,27 +69,27 @@ def get_data(filters):
|
|||||||
data = prepare_data(accounts, filters, total_row)
|
data = prepare_data(accounts, filters, total_row)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_opening_balances(filters):
|
def get_opening_balances(filters):
|
||||||
balance_sheet_opening = get_rootwise_opening_balances(filters, "Balance Sheet")
|
balance_sheet_opening = get_rootwise_opening_balances(filters, "Balance Sheet")
|
||||||
pl_opening = get_rootwise_opening_balances(filters, "Profit and Loss")
|
pl_opening = get_rootwise_opening_balances(filters, "Profit and Loss")
|
||||||
|
|
||||||
balance_sheet_opening.update(pl_opening)
|
balance_sheet_opening.update(pl_opening)
|
||||||
return balance_sheet_opening
|
return balance_sheet_opening
|
||||||
|
|
||||||
|
|
||||||
def get_rootwise_opening_balances(filters, report_type):
|
def get_rootwise_opening_balances(filters, report_type):
|
||||||
additional_conditions = " and posting_date >= %(year_start_date)s" \
|
additional_conditions = " and posting_date >= %(year_start_date)s" \
|
||||||
if report_type == "Profit and Loss" else ""
|
if report_type == "Profit and Loss" else ""
|
||||||
|
|
||||||
if not flt(filters.with_period_closing_entry):
|
if not flt(filters.with_period_closing_entry):
|
||||||
additional_conditions += " and ifnull(voucher_type, '')!='Period Closing Voucher'"
|
additional_conditions += " and ifnull(voucher_type, '')!='Period Closing Voucher'"
|
||||||
|
|
||||||
gle = frappe.db.sql("""
|
gle = frappe.db.sql("""
|
||||||
select
|
select
|
||||||
account, sum(debit) as opening_debit, sum(credit) as opening_credit
|
account, sum(debit) as opening_debit, sum(credit) as opening_credit
|
||||||
from `tabGL Entry`
|
from `tabGL Entry`
|
||||||
where
|
where
|
||||||
company=%(company)s
|
company=%(company)s
|
||||||
{additional_conditions}
|
{additional_conditions}
|
||||||
and (posting_date < %(from_date)s or ifnull(is_opening, 'No') = 'Yes')
|
and (posting_date < %(from_date)s or ifnull(is_opening, 'No') = 'Yes')
|
||||||
@@ -100,11 +102,11 @@ def get_rootwise_opening_balances(filters, report_type):
|
|||||||
"year_start_date": filters.year_start_date
|
"year_start_date": filters.year_start_date
|
||||||
},
|
},
|
||||||
as_dict=True)
|
as_dict=True)
|
||||||
|
|
||||||
opening = frappe._dict()
|
opening = frappe._dict()
|
||||||
for d in gle:
|
for d in gle:
|
||||||
opening.setdefault(d.account, d)
|
opening.setdefault(d.account, d)
|
||||||
|
|
||||||
return opening
|
return opening
|
||||||
|
|
||||||
def calculate_values(accounts, gl_entries_by_account, opening_balances, filters):
|
def calculate_values(accounts, gl_entries_by_account, opening_balances, filters):
|
||||||
@@ -139,7 +141,7 @@ def calculate_values(accounts, gl_entries_by_account, opening_balances, filters)
|
|||||||
|
|
||||||
total_row["debit"] += d["debit"]
|
total_row["debit"] += d["debit"]
|
||||||
total_row["credit"] += d["credit"]
|
total_row["credit"] += d["credit"]
|
||||||
|
|
||||||
|
|
||||||
return total_row
|
return total_row
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user