fix: POS Closing Entry, reload invoices when changing dates#54106
fix: POS Closing Entry, reload invoices when changing dates#54106devdiogenes wants to merge 1 commit intofrappe:developfrom
Conversation
📝 WalkthroughWalkthroughThe Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js (1)
59-72:⚠️ Potential issue | 🟠 MajorGuard
reload_invoicesagainst concurrent execution and promise rejection.The current implementation has two reliability issues:
- Rapid changes to
period_start_date,period_end_date, orusercan trigger overlapping reloads, causingreset_valuesand append operations to interleave and produce stale or duplicated totals.- If
set_opening_amountsorget_invoicesfails, the promise chain breaks andfrappe.dom.unfreeze()never runs, leaving the UI frozen.Add an overlap guard and attach
.finally()to ensure cleanup runs regardless of success or failure:Proposed fix
reload_invoices: function (frm) { if ( frm.doc.pos_opening_entry && frm.doc.period_start_date && frm.doc.period_end_date && frm.doc.user ) { + if (frm.__reloading_invoices) { + frm.__reload_invoices_pending = true; + return; + } + + frm.__reloading_invoices = true; reset_values(frm); - frappe.run_serially([ + return frappe + .run_serially([ () => frappe.dom.freeze(__("Loading Invoices! Please Wait...")), () => frm.trigger("set_opening_amounts"), () => frm.trigger("get_invoices"), - () => frappe.dom.unfreeze(), - ]); + ]) + .finally(() => { + frappe.dom.unfreeze(); + frm.__reloading_invoices = false; + if (frm.__reload_invoices_pending) { + frm.__reload_invoices_pending = false; + frm.trigger("reload_invoices"); + } + }); } },🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js` around lines 59 - 72, The reload_invoices function can run concurrently and leave the UI frozen on error; add an overlap guard (e.g., a boolean like this._reloadingInvoices) at the start of reload_invoices to return early if a reload is already in progress, set it true before starting and false when finished, and run the serial tasks inside a Promise chain that always calls frappe.dom.unfreeze() in a .finally() block so unfreeze runs even if frm.trigger("set_opening_amounts") or frm.trigger("get_invoices") rejects; ensure reset_values remains before the guard exit and clear the guard in the finally along with unfreeze.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js`:
- Around line 59-72: The reload_invoices function can run concurrently and leave
the UI frozen on error; add an overlap guard (e.g., a boolean like
this._reloadingInvoices) at the start of reload_invoices to return early if a
reload is already in progress, set it true before starting and false when
finished, and run the serial tasks inside a Promise chain that always calls
frappe.dom.unfreeze() in a .finally() block so unfreeze runs even if
frm.trigger("set_opening_amounts") or frm.trigger("get_invoices") rejects;
ensure reset_values remains before the guard exit and clear the guard in the
finally along with unfreeze.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 03e64bc4-ae5d-462a-b29f-a1661d150254
📒 Files selected for processing (1)
erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.js
What is the use case of changing the Period End Date? |
Users shouldn’t be limited to doing only one closing per day. For example, they might want to do one in the morning and another in the afternoon. Also, if ERPNext allows users to edit this end date, I believe it should work correctly when it is changed. |
For simulate, I have:
The problem is: If the POS Invoices is already loaded in POS Closing Entry but we want to change the period_end_date to some time between the two invoices, they don't reload the invoices, and we still seeing the two invoices.
Before my changes:
2026-04-07.09-31-15.mp4
After my changes:
2026-04-07.09-31-46.mp4