Repository navigation
fix: preserve concurrent charge waivers during item void async PIN check - #1258
Conversation
Read charge resolution and sync parameters from currentOrder instead of stale pre-await order snapshot during item cancel. Fixes #1253.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughOrder item cancellation now uses the transaction’s current order record to resolve charges and recalculate unpaid bill totals. The expanded tests cover concurrent charge updates during manager-PIN verification and cancellation, restore, authorization, inventory, audit, and transaction behavior. ChangesOrder item cancellation
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to
|
|
@greptileai review this at apex |
[Medium impact] The PR appears safe to merge; no actionable issues were found.
|
Fixes #1253
Intent
Fix finding N1 (GitHub issue #1253) in FreeOpenSourcePOS/FloCafe: when voiding an in-progress (
preparingorready) order item viaPATCH /api/orders/:orderId/items/:itemId/cancel, preserve any charge waivers or delivery charge updates that were applied concurrently while the route was awaiting asynchronous manager PIN verification (withPinVerificationLock/verifyPinAsync). Inside thewithTxntransaction inmain/routes/orders.ts, charge resolution (resolveEngineCharges), fallback charge columns (service_charge,packaging_charge,charges_breakdown), and unpaid bill synchronization (syncUnpaidBillsForOrderdeliveryCharge) must read from the fresh transaction-localcurrentOrdersnapshot rather than the stale pre-awaitordersnapshot, and regression tests must verify that concurrent waivers ofservice_chargeandpackaging_chargeduring async item-void PIN verification remain waived on bothordersand unpaidbills.What Changed
PATCH /api/orders/:orderId/items/:itemId/cancelinmain/routes/orders.tsto source charge engine resolution (resolveEngineCharges), fallback charge fields (service_charge,packaging_charge,charges_breakdown), and unpaid bill synchronization (deliveryCharge) from the transaction-localcurrentOrdersnapshot instead of the pre-awaitordersnapshot.tests/order-item-cancel-restore.test.tsverifying that concurrent service charge, packaging charge, and delivery charge modifications during asynchronous PIN verification persist after item cancellation.Risk Assessment
✅ Low: The change is a surgical and well-tested 5-token correction replacing stale pre-await order snapshots with the fresh transaction-local currentOrder snapshot inside withTxn during item voids.
Testing
Executed full reproduction of finding N1 on base commit 0818717 (failing on stale order snapshot), followed by live validation against the running product with target commit 3a35742 across 5 live scenarios covering concurrent service charge waiver, packaging charge waiver, delivery charge sync on order cancellation, invalid manager PIN guard, and non-void pending item cancellation; all passed and captured to evidence files.
Evidence: Live Scenario Execution Log
=== FLO-CAFE LIVE VALIDATION: ISSUE #1253 (N1) CONCURRENT CHARGE WAIVERS ON ITEM VOID Execution timestamp: 2026-10-21T05:51:27.364Z === Server running live on http://127.0.0.1:62663 >>> SCENARIO 1: Concurrent Service Charge Waiver during In-Progress Item Void <<< Order ID: 1, Bill ID: 1, Initial bill service_charge: 20 [Action] Cashier voids preparing item with manager PIN 1234 [Event Loop] Manager concurrently waives service_charge while PIN verification is awaiting bcrypt... [Verification] Order subtotal: 100, service_charge: 0 [Verification] Order charges_breakdown service_charge: waived=true, amount=0 [Verification] Bill subtotal: 100, service_charge: 0 [Verification] Bill charges_breakdown service_charge: waived=true, amount=0 ✓ SCENARIO 1 PASSED: Service charge waiver preserved across orders and bills >>> SCENARIO 2: Concurrent Packaging Charge Waiver during In-Progress Item Void <<< Order ID: 2, Bill ID: 2, Initial bill packaging_charge: 10 [Action] Cashier voids preparing item with manager PIN 1234 [Event Loop] Manager concurrently waives packaging_charge while PIN verification is awaiting bcrypt... [Verification] Order subtotal: 100, packaging_charge: 0 [Verification] Order charges_breakdown packaging_charge: waived=true, amount=0 [Verification] Bill subtotal: 100, packaging_charge: 0 [Verification] Bill charges_breakdown packaging_charge: waived=true, amount=0 ✓ SCENARIO 2 PASSED: Packaging charge waiver preserved across orders and bills >>> SCENARIO 3: Concurrent Delivery Charge Update & Charge Waiver on Last Active Item Void <<< [Action] Voiding last active item with manager PIN 1234 [Event Loop] Concurrently waiving packaging charge and updating delivery_charge to 15... [Verification] Order status: cancelled, subtotal: 0, delivery_charge: 15 [Verification] Bill subtotal: 0, delivery_charge: 15 ✓ SCENARIO 3 PASSED: Order cancellation zeroes charges and syncs delivery charge from fresh transaction snapshot >>> SCENARIO 4: Adversarial Guard - Invalid Manager PIN on In-Progress Item Void <<< [Action] Cashier attempts void with incorrect PIN 9999 ✓ SCENARIO 4 PASSED: Invalid manager PIN safely rejected without state mutation >>> SCENARIO 5: Non-Void Item Cancel - Pending Item Cancelled by Manager <<< [Action] Manager cancels pending item without override PIN ✓ SCENARIO 5 PASSED: Pending item cancellation correctly restores stock and cancels order === ALL 5 SCENARIOS COMPLETED AND PASSED WITH VERIFIED PERSISTED STATE ===Evidence: Concurrent Void Charges Verification Report
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
npm run test:order-item-cancel-restorenode tests/run-electron-node-test.cjs /tmp/n1-live-scenarios-driver.tsReproduction check on base commit 08187174bfa47f08154e2b9b64cdb17b0ef2c459 (reproduced failure: order service_charge remains 0 (waived) - expected 0, got 10)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
Summary by CodeRabbit