Skip to content

Commit

Permalink
Merge pull request #43663 from ljain112/fix-pcv-eneque
Browse files Browse the repository at this point in the history
fix: run gl_entries and closing voucher processes in same function
  • Loading branch information
ruthra-kumar authored Oct 15, 2024
2 parents f0adc16 + af4daa5 commit e3ab46a
Showing 1 changed file with 20 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def on_cancel(self):
)
if gle_count > 5000:
frappe.enqueue(
make_reverse_gl_entries,
process_cancellation,
voucher_type="Period Closing Voucher",
voucher_no=self.name,
queue="long",
Expand All @@ -71,9 +71,7 @@ def on_cancel(self):
alert=True,
)
else:
make_reverse_gl_entries(voucher_type="Period Closing Voucher", voucher_no=self.name)

self.delete_closing_entries()
process_cancellation(voucher_type="Period Closing Voucher", voucher_no=self.name)

def validate_future_closing_vouchers(self):
if frappe.db.exists(
Expand All @@ -86,12 +84,6 @@ def validate_future_closing_vouchers(self):
)
)

def delete_closing_entries(self):
closing_balance = frappe.qb.DocType("Account Closing Balance")
frappe.qb.from_(closing_balance).delete().where(
closing_balance.period_closing_voucher == self.name
).run()

def validate_account_head(self):
closing_account_type = frappe.get_cached_value("Account", self.closing_account_head, "root_type")

Expand Down Expand Up @@ -166,14 +158,7 @@ def make_gl_entries(self, get_opening_entries=False):
closing_entries = self.get_grouped_gl_entries(get_opening_entries=get_opening_entries)
if len(gl_entries + closing_entries) > 3000:
frappe.enqueue(
process_gl_entries,
gl_entries=gl_entries,
voucher_name=self.name,
timeout=3000,
)

frappe.enqueue(
process_closing_entries,
process_gl_and_closing_entries,
gl_entries=gl_entries,
closing_entries=closing_entries,
voucher_name=self.name,
Expand All @@ -187,8 +172,9 @@ def make_gl_entries(self, get_opening_entries=False):
alert=True,
)
else:
process_gl_entries(gl_entries, self.name)
process_closing_entries(gl_entries, closing_entries, self.name, self.company, self.posting_date)
process_gl_and_closing_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 @@ -374,38 +360,38 @@ def get_balances_based_on_dimensions(
return query.run(as_dict=1)


def process_gl_entries(gl_entries, voucher_name):
def process_gl_and_closing_entries(gl_entries, closing_entries, voucher_name, company, closing_date):
from erpnext.accounts.doctype.account_closing_balance.account_closing_balance import (
make_closing_entries,
)
from erpnext.accounts.general_ledger import make_gl_entries

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


def process_closing_entries(gl_entries, closing_entries, voucher_name, company, closing_date):
from erpnext.accounts.doctype.account_closing_balance.account_closing_balance import (
make_closing_entries,
)

try:
make_closing_entries(gl_entries + closing_entries, voucher_name, company, closing_date)
except Exception as e:
frappe.db.rollback()
frappe.log_error(e)


def make_reverse_gl_entries(voucher_type, voucher_no):
def process_cancellation(voucher_type, voucher_no):
from erpnext.accounts.general_ledger import make_reverse_gl_entries

try:
make_reverse_gl_entries(voucher_type=voucher_type, voucher_no=voucher_no)
delete_closing_entries(voucher_no)
frappe.db.set_value("Period Closing Voucher", voucher_no, "gle_processing_status", "Completed")
except Exception as e:
frappe.db.rollback()
frappe.log_error(e)
frappe.db.set_value("Period Closing Voucher", voucher_no, "gle_processing_status", "Failed")


def delete_closing_entries(voucher_no):
closing_balance = frappe.qb.DocType("Account Closing Balance")
frappe.qb.from_(closing_balance).delete().where(
closing_balance.period_closing_voucher == voucher_no
).run()

0 comments on commit e3ab46a

Please sign in to comment.