mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-13 14:41:53 +00:00
fix: race condition and repeatable read in process pcv
- Update using child table name to avoid scanning whole table, which
eventually leads to mariadb 1020 (REPEATABLE READ).
- Avoid race condition in final summarization
(cherry picked from commit ff6881764b)
This commit is contained in:
@@ -100,7 +100,7 @@ def start_pcv_processing(docname: str):
|
|||||||
ppcvd = qb.DocType("Process Period Closing Voucher Detail")
|
ppcvd = qb.DocType("Process Period Closing Voucher Detail")
|
||||||
if normal_balances := (
|
if normal_balances := (
|
||||||
qb.from_(ppcvd)
|
qb.from_(ppcvd)
|
||||||
.select(ppcvd.processing_date, ppcvd.report_type, ppcvd.parentfield)
|
.select(ppcvd.name, ppcvd.processing_date, ppcvd.report_type, ppcvd.parentfield)
|
||||||
.where(ppcvd.parent.eq(docname) & ppcvd.status.eq("Queued"))
|
.where(ppcvd.parent.eq(docname) & ppcvd.status.eq("Queued"))
|
||||||
.orderby(ppcvd.parentfield, ppcvd.idx, ppcvd.processing_date)
|
.orderby(ppcvd.parentfield, ppcvd.idx, ppcvd.processing_date)
|
||||||
.limit(4)
|
.limit(4)
|
||||||
@@ -111,12 +111,7 @@ def start_pcv_processing(docname: str):
|
|||||||
for x in normal_balances:
|
for x in normal_balances:
|
||||||
frappe.db.set_value(
|
frappe.db.set_value(
|
||||||
"Process Period Closing Voucher Detail",
|
"Process Period Closing Voucher Detail",
|
||||||
{
|
x.name,
|
||||||
"processing_date": x.processing_date,
|
|
||||||
"parent": docname,
|
|
||||||
"report_type": x.report_type,
|
|
||||||
"parentfield": x.parentfield,
|
|
||||||
},
|
|
||||||
"status",
|
"status",
|
||||||
"Running",
|
"Running",
|
||||||
)
|
)
|
||||||
@@ -127,10 +122,12 @@ def start_pcv_processing(docname: str):
|
|||||||
is_async=True,
|
is_async=True,
|
||||||
enqueue_after_commit=True,
|
enqueue_after_commit=True,
|
||||||
docname=docname,
|
docname=docname,
|
||||||
|
row_name=x.name,
|
||||||
date=x.processing_date,
|
date=x.processing_date,
|
||||||
report_type=x.report_type,
|
report_type=x.report_type,
|
||||||
parentfield=x.parentfield,
|
parentfield=x.parentfield,
|
||||||
)
|
)
|
||||||
|
frappe.db.commit()
|
||||||
else:
|
else:
|
||||||
frappe.db.set_value("Process Period Closing Voucher", docname, "status", "Completed")
|
frappe.db.set_value("Process Period Closing Voucher", docname, "status", "Completed")
|
||||||
|
|
||||||
@@ -254,7 +251,7 @@ def schedule_next_date(docname: str):
|
|||||||
ppcvd = qb.DocType("Process Period Closing Voucher Detail")
|
ppcvd = qb.DocType("Process Period Closing Voucher Detail")
|
||||||
if to_process := (
|
if to_process := (
|
||||||
qb.from_(ppcvd)
|
qb.from_(ppcvd)
|
||||||
.select(ppcvd.processing_date, ppcvd.report_type, ppcvd.parentfield)
|
.select(ppcvd.name, ppcvd.processing_date, ppcvd.report_type, ppcvd.parentfield)
|
||||||
.where(ppcvd.parent.eq(docname) & ppcvd.status.eq("Queued"))
|
.where(ppcvd.parent.eq(docname) & ppcvd.status.eq("Queued"))
|
||||||
.orderby(ppcvd.parentfield, ppcvd.idx, ppcvd.processing_date)
|
.orderby(ppcvd.parentfield, ppcvd.idx, ppcvd.processing_date)
|
||||||
.limit(1)
|
.limit(1)
|
||||||
@@ -264,15 +261,11 @@ def schedule_next_date(docname: str):
|
|||||||
if not is_scheduler_inactive():
|
if not is_scheduler_inactive():
|
||||||
frappe.db.set_value(
|
frappe.db.set_value(
|
||||||
"Process Period Closing Voucher Detail",
|
"Process Period Closing Voucher Detail",
|
||||||
{
|
to_process[0].name,
|
||||||
"processing_date": to_process[0].processing_date,
|
|
||||||
"parent": docname,
|
|
||||||
"report_type": to_process[0].report_type,
|
|
||||||
"parentfield": to_process[0].parentfield,
|
|
||||||
},
|
|
||||||
"status",
|
"status",
|
||||||
"Running",
|
"Running",
|
||||||
)
|
)
|
||||||
|
frappe.db.commit()
|
||||||
frappe.enqueue(
|
frappe.enqueue(
|
||||||
method="erpnext.accounts.doctype.process_period_closing_voucher.process_period_closing_voucher.process_individual_date",
|
method="erpnext.accounts.doctype.process_period_closing_voucher.process_period_closing_voucher.process_individual_date",
|
||||||
queue="long",
|
queue="long",
|
||||||
@@ -280,6 +273,7 @@ def schedule_next_date(docname: str):
|
|||||||
is_async=True,
|
is_async=True,
|
||||||
enqueue_after_commit=True,
|
enqueue_after_commit=True,
|
||||||
docname=docname,
|
docname=docname,
|
||||||
|
row_name=to_process[0].name,
|
||||||
date=to_process[0].processing_date,
|
date=to_process[0].processing_date,
|
||||||
report_type=to_process[0].report_type,
|
report_type=to_process[0].report_type,
|
||||||
parentfield=to_process[0].parentfield,
|
parentfield=to_process[0].parentfield,
|
||||||
@@ -444,6 +438,8 @@ def summarize_and_post_ledger_entries(docname):
|
|||||||
|
|
||||||
make_closing_entries(closing_entries, pcv.name, pcv.company, pcv.period_end_date)
|
make_closing_entries(closing_entries, pcv.name, pcv.company, pcv.period_end_date)
|
||||||
|
|
||||||
|
frappe.db.commit()
|
||||||
|
|
||||||
frappe.db.set_value("Period Closing Voucher", pcv.name, "gle_processing_status", "Completed")
|
frappe.db.set_value("Period Closing Voucher", pcv.name, "gle_processing_status", "Completed")
|
||||||
frappe.db.set_value("Process Period Closing Voucher", docname, "status", "Completed")
|
frappe.db.set_value("Process Period Closing Voucher", docname, "status", "Completed")
|
||||||
|
|
||||||
@@ -529,10 +525,10 @@ def build_dimension_wise_balance_dict(gl_entries):
|
|||||||
return dimension_balances
|
return dimension_balances
|
||||||
|
|
||||||
|
|
||||||
def process_individual_date(docname: str, date, report_type, parentfield):
|
def process_individual_date(docname: str, row_name, date, report_type, parentfield):
|
||||||
current_date_status = frappe.db.get_value(
|
current_date_status = frappe.db.get_value(
|
||||||
"Process Period Closing Voucher Detail",
|
"Process Period Closing Voucher Detail",
|
||||||
{"processing_date": date, "report_type": report_type, "parentfield": parentfield},
|
row_name,
|
||||||
"status",
|
"status",
|
||||||
)
|
)
|
||||||
if current_date_status != "Running":
|
if current_date_status != "Running":
|
||||||
@@ -579,17 +575,18 @@ def process_individual_date(docname: str, date, report_type, parentfield):
|
|||||||
# save results
|
# save results
|
||||||
frappe.db.set_value(
|
frappe.db.set_value(
|
||||||
"Process Period Closing Voucher Detail",
|
"Process Period Closing Voucher Detail",
|
||||||
{"processing_date": date, "parent": docname, "report_type": report_type, "parentfield": parentfield},
|
row_name,
|
||||||
"closing_balance",
|
"closing_balance",
|
||||||
frappe.json.dumps(res),
|
frappe.json.dumps(res),
|
||||||
)
|
)
|
||||||
|
|
||||||
frappe.db.set_value(
|
frappe.db.set_value(
|
||||||
"Process Period Closing Voucher Detail",
|
"Process Period Closing Voucher Detail",
|
||||||
{"processing_date": date, "parent": docname, "report_type": report_type, "parentfield": parentfield},
|
row_name,
|
||||||
"status",
|
"status",
|
||||||
"Completed",
|
"Completed",
|
||||||
)
|
)
|
||||||
|
frappe.db.commit()
|
||||||
|
|
||||||
# chain call
|
# chain call
|
||||||
schedule_next_date(docname)
|
schedule_next_date(docname)
|
||||||
|
|||||||
Reference in New Issue
Block a user