Repository navigation
fix(billing): zero-balance settlement, zero-total split siblings, refunded sibling completion - #812
Conversation
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (1)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including ⚙️ Run configurationConfiguration used: Repository: FreeOpenSourcePOS/FloCafe/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 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⚙️ Run configurationConfiguration used: Repository: FreeOpenSourcePOS/FloCafe/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughBill settlement now handles zero balances, refunded states, and partial payments. Split-bill synchronization, order completion, cancellation, restoration, and payment validation use the updated status rules. An Electron integration test covers these workflows. ChangesBilling and Order Settlement
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~30 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to Billing now supports legitimate zero-balance settlement while rejecting refunded payments and unsafe restoration after positive partial payment. No unresolved merge-blocking risk remains. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description explains the problem, root cause, fix, test coverage, and verification results. However, it omits several required template sections, including Scope, Compatibility & data safety, Cross-cutting surfaces, and the Contributor checklist. Resolution Add the missing template sections. Document the intentional scope, database and migration impact, user-visible and offline/network impact, affected cross-cutting surfaces, screenshots status if not applicable, and completed contributor checklist items. Include the related issue or state that none exists. ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 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 |
|
SummaryCoverage spans core order and billing workflows, including split bills, payments, refunds, discounts, cancellations, restoration, table availability, and concurrent settlement. It exercises both normal customer flows and edge-case protections around paid, refunded, zero-value, and partially paid orders, with overall behavior healthy except for a payment-state protection gap. Not safe to merge yet — a high-severity business-logic defect allows order contents and balances to change after a partial payment, creating incorrect amounts that may require manual correction. No unrelated findings alter this merge-blocking assessment. Tests run by ItoTip Reply with @itoqa to send us feedback on this test run. |
|
Diff SummaryCoverage focuses on order-item restoration and payment protection, including successful restoration for zero-balance cases, rejection of restores for paid or partially paid orders, retry safety, preservation of related order and bill state, and isolation between separate orders. These are primarily business-logic happy paths and edge or adversarial cases around payments and repeated actions. Safe to merge — the exercised payment and restoration behaviors are passing, including the previously failing paid-order protection, with no PR-attributable regressions or unresolved failures. Broader previously passing scenarios were not exercised in this run, but they are a coverage caveat rather than a merge blocker. Tests run by Ito
Tip Reply with @itoqa to send us feedback on this test run. |
…siblings, exclude refunded siblings
- Allow settle when remaining balance is 0 regardless of paid_amount - Exclude zero-closed bills from cancel-item paid-order guard - Treat partially_refunded siblings as settled for order completion - Include zero-closed bills in unpaid-bill re-sync so restore flips them back
The restore guard checked `payment_status = 'paid'` but a partially paid
bill has `payment_status = 'partial'` with `paid_amount > 0`, so the guard
was silently skipped and the cancelled item was restored while a payment
was already recorded against the bill.
Expanded the query to `payment_status IN ('paid', 'partial')` so any
positive-payment state blocks the restore.
Added focused regression test: cancel item → partial pay → restore must
return 400.
3706624 to
fe79e7d
Compare
Commit: SummaryCoverage focuses on payment and billing business rules across normal completion flows, zero-balance and refund edge cases, split-bill changes, item cancellation and restoration, and concurrent operations. It also checks that invalid or conflicting actions are rejected while valid orders still complete and tables become available. Safe to merge — the exercised behaviors are healthy, with no regressions, new failures, or previously reported PR-attributable failures. The reviewed concurrency and cancellation findings are documented intended behavior rather than merge blockers. Tests run by Ito
Tip Reply with @itoqa to send us feedback on this test run. |


Problem
Three settlement edge cases leave bills stuck unpaid (or leave the parent order stuck incomplete) after a legitimate discount or split-check mutation. In every case the data is correct on the bill row, but the settle path or the order-completion path treats the row as already finished (or still outstanding) and refuses to move forward.
applyDiscount, and item discount can each reducebalanceto0whilepayment_statusis stillunpaid/partial. The follow-up settle then hitspreparePaymentBatch'sremainingCents <= 0branch and throws 400 "Bill is already fully paid", even though the bill was never markedpaid. The order never completes and the table never frees.split-checkcan zero one guest check. That sibling haspayment_status = 'paid'withpaid_amount = 0(or stays unpayable), so:syncUnpaidBillsForOrderrejects further modifications with 409 ("split check is paid").payment_status != 'paid', so when the remaining sibling is paid the parent order still looks incomplete and never flips tocompleted.paid,paid_amount = 0) while the order was still open, restoring an item hits the early return insyncUnpaidBillsForOrderand leaves the zero-closed bills stuck.payment_status. Refunds never reducepaid_amount, so a fully paid then fully refunded bill still hasremainingCents = 0. The empty-batch settle path then letsapplyPaymentBatchoverwriterefundedback topaid.Root cause
preparePaymentBatchremainingCents <= 0always threwalready fully paidwhenpaid_amountwas 0, with no path for "discount zeroed the rest with no money in"; no guard forrefunded/partially_refundedbefore the empty-batch returnsyncUnpaidBillsForOrderpayment_status !== 'unpaid' || paid_amount > 0split bill as paid, so zero-closed siblings locked modifications; also never auto-closed a total-0 sibling; early-returned when all bills werepaideven if they were zero-closedpaidwithpaid_amount = 0) blocked legitimate mutationspayment_status != 'paid'includesrefundedandpartially_refunded, so those siblings permanently blocked completionFix (surgical)
remainingCents <= 0, return an empty prepared batch (instead of throwing) soapplyPaymentBatchcan mark the billpaidand complete the order. Applies whether or not any money was previously paid.total <= 0 && balance <= 0is markedpaid(withpaid_at). A previously zero-closed bill whose total returns is reversed tounpaid. The split-modify guard, restore's paid-order check, and the cancel-item paid-order check all ignore zero-closed bills (paid_amount = 0). Zero-closed bills are included in the unpaid-bill filter so restore re-syncs them.payment_status NOT IN ('paid', 'refunded', 'partially_refunded')so a refunded or partially refunded guest check no longer blocks completing the order when the remaining check is paid.preparePaymentBatchrejectsrefunded/partially_refundedbills with 400 "Bill has been refunded" before the empty-batch path, so a settle attempt can no longer overwrite the refund status.Test evidence (post-fix)
Scenarios covered:
paid+ ordercompleted+ table freed).paid_amount = 0) settles and completes the order.paid; paying the remaining sibling completes the order and frees the table.unpaidwith a positive total when an item is restored on an open order.payment_status = 'refunded'.Focused suites (all green): refunds 59/59, refund-completed-orders 18/18, integration-payments 33/33, discount-system 37/37, issue-24-cancel-item-checkout 25/25.
Quality gates:
npm run lint:backend→ 0 errors (1000/1000 budget),npm run build→ green,node scripts/ci/validate-test-script-coverage.cjs→ 172 reachable / 6 excluded.Notes / residual risks
already paidand break the proven repro path.test:issue-zero-balance-settlementand appended to the roottestchain.Base:
f7cc3f32(origin/main).Summary by CodeRabbit