Skip to content

Commit

Permalink
fix: Trial Balance report considering cancelled entries
Browse files Browse the repository at this point in the history
(cherry picked from commit fd58bbf)
  • Loading branch information
deepeshgarg007 authored and mergify[bot] committed Jul 20, 2023
1 parent bd82ae5 commit ca4f86d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,22 @@ def check_if_previous_year_closed(self):
def make_gl_entries(self, get_opening_entries=False):
gl_entries = self.get_gl_entries()
closing_entries = self.get_grouped_gl_entries(get_opening_entries=get_opening_entries)
if gl_entries:
if len(gl_entries) > 5000:
frappe.enqueue(
process_gl_entries,
gl_entries=gl_entries,
closing_entries=closing_entries,
voucher_name=self.name,
company=self.company,
closing_date=self.posting_date,
queue="long",
)
frappe.msgprint(
_("The GL Entries will be processed in the background, it can take a few minutes."),
alert=True,
)
else:
process_gl_entries(gl_entries, closing_entries, self.name, self.company, self.posting_date)
if len(gl_entries) > 5000:
frappe.enqueue(
process_gl_entries,
gl_entries=gl_entries,
closing_entries=closing_entries,
voucher_name=self.name,
company=self.company,
closing_date=self.posting_date,
queue="long",
)
frappe.msgprint(
_("The GL Entries will be processed in the background, it can take a few minutes."),
alert=True,
)
else:
process_gl_entries(gl_entries, closing_entries, self.name, self.company, self.posting_date)

def get_grouped_gl_entries(self, get_opening_entries=False):
closing_entries = []
Expand Down Expand Up @@ -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

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)
frappe.db.set_value(
"Period Closing Voucher", gl_entries[0].get("voucher_no"), "gle_processing_status", "Completed"
)
frappe.db.set_value("Period Closing Voucher", voucher_name, "gle_processing_status", "Completed")
except Exception as e:
frappe.db.rollback()
frappe.log_error(e)
frappe.db.set_value(
"Period Closing Voucher", gl_entries[0].get("voucher_no"), "gle_processing_status", "Failed"
)
frappe.db.set_value("Period Closing Voucher", voucher_name, "gle_processing_status", "Failed")


def make_reverse_gl_entries(voucher_type, voucher_no):
Expand Down
3 changes: 3 additions & 0 deletions erpnext/accounts/report/trial_balance/trial_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ def get_opening_balance(
(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 (
not filters.show_unclosed_fy_pl_balances
and report_type == "Profit and Loss"
Expand Down

0 comments on commit ca4f86d

Please sign in to comment.