Merge pull request #36214 from deepeshgarg007/tb_cancelled_entries

fix: Trial Balance report considering cancelled entries
This commit is contained in:
Deepesh Garg 2023-07-20 18:48:03 +05:30 committed by GitHub
commit 76db0b63ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 24 deletions

View File

@ -126,23 +126,22 @@ class PeriodClosingVoucher(AccountsController):
def make_gl_entries(self, get_opening_entries=False): def make_gl_entries(self, get_opening_entries=False):
gl_entries = self.get_gl_entries() gl_entries = self.get_gl_entries()
closing_entries = self.get_grouped_gl_entries(get_opening_entries=get_opening_entries) closing_entries = self.get_grouped_gl_entries(get_opening_entries=get_opening_entries)
if gl_entries: if len(gl_entries) > 5000:
if len(gl_entries) > 5000: frappe.enqueue(
frappe.enqueue( process_gl_entries,
process_gl_entries, gl_entries=gl_entries,
gl_entries=gl_entries, closing_entries=closing_entries,
closing_entries=closing_entries, voucher_name=self.name,
voucher_name=self.name, company=self.company,
company=self.company, closing_date=self.posting_date,
closing_date=self.posting_date, queue="long",
queue="long", )
) frappe.msgprint(
frappe.msgprint( _("The GL Entries will be processed in the background, it can take a few minutes."),
_("The GL Entries will be processed in the background, it can take a few minutes."), alert=True,
alert=True, )
) else:
else: process_gl_entries(gl_entries, closing_entries, self.name, self.company, self.posting_date)
process_gl_entries(gl_entries, closing_entries, self.name, self.company, self.posting_date)
def get_grouped_gl_entries(self, get_opening_entries=False): def get_grouped_gl_entries(self, get_opening_entries=False):
closing_entries = [] closing_entries = []
@ -330,17 +329,15 @@ def process_gl_entries(gl_entries, closing_entries, voucher_name, company, closi
from erpnext.accounts.general_ledger import make_gl_entries from erpnext.accounts.general_ledger import make_gl_entries
try: try:
make_gl_entries(gl_entries, merge_entries=False) if gl_entries:
make_gl_entries(gl_entries, merge_entries=False)
make_closing_entries(gl_entries + closing_entries, voucher_name, company, closing_date) make_closing_entries(gl_entries + closing_entries, voucher_name, company, closing_date)
frappe.db.set_value( frappe.db.set_value("Period Closing Voucher", voucher_name, "gle_processing_status", "Completed")
"Period Closing Voucher", gl_entries[0].get("voucher_no"), "gle_processing_status", "Completed"
)
except Exception as e: except Exception as e:
frappe.db.rollback() frappe.db.rollback()
frappe.log_error(e) frappe.log_error(e)
frappe.db.set_value( frappe.db.set_value("Period Closing Voucher", voucher_name, "gle_processing_status", "Failed")
"Period Closing Voucher", gl_entries[0].get("voucher_no"), "gle_processing_status", "Failed"
)
def make_reverse_gl_entries(voucher_type, voucher_no): def make_reverse_gl_entries(voucher_type, voucher_no):

View File

@ -231,6 +231,9 @@ def get_opening_balance(
(closing_balance.posting_date < filters.from_date) | (closing_balance.is_opening == "Yes") (closing_balance.posting_date < filters.from_date) | (closing_balance.is_opening == "Yes")
) )
if doctype == "GL Entry":
opening_balance = opening_balance.where(closing_balance.is_cancelled == 0)
if ( if (
not filters.show_unclosed_fy_pl_balances not filters.show_unclosed_fy_pl_balances
and report_type == "Profit and Loss" and report_type == "Profit and Loss"