Repository navigation
fix(main): harden WhatsApp offline abort, split-bill deduplication, loyalty rounding, and auto-settlement automation - #1323
Merged
Conversation
…and trigger auto-settlement automation
Contributor
|
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:
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 |
This was referenced Oct 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Verify and fix the WhatsApp offline/concurrency regressions and the exact-balance auto-settlement paid-bill automation regression from the merged-PR release audit, plus fix 3-decimal and 0-decimal loyalty rounding in
main/services/whatsapp.ts:main/services/whatsapp.ts: Version requests (resolveWaWebVersion) continue, and Baileys fallback requests (fetchLatestWaWebVersion) can start, after enabling Offline mode (suspendForOfflineMode).main/services/whatsapp.ts: Concurrent split payments (triggerBillPaidAutomation) can send duplicatenth_visitmessages for one visit while the first call is still awaitingonWhatsApp.main/routes/bills.ts: Exact-balance auto-settlement (completeExactBalanceSettlement) when syncing an unpaid order bill (syncUnpaidOrderBills) or generating a bill (POST /api/bills/generate) marks the billpaidand awards loyalty points, but skips configured paid-bill automation (triggerBillPaidAutomation).regional.currencyFractionDigits) inroundLoyaltyAmountinsidemain/services/whatsapp.tsso 3-decimal (KWD) and 0-decimal (JPY) currencies are rounded accurately instead of hardcoded 2-decimal rounding.What Changed
resolveWaWebVersion,startSocketImpl,connectWithQr,connectWithPairingCode) when Offline mode is enabled (suspendForOfflineMode), preventing fallback Baileys version fetches from starting while offline.nth_visitmilestone sends across concurrent and sequential split-bill settlements per order and customer (inFlightNthVisitKeysandhasNthVisitMessageForOrder), and round loyalty amounts inroundLoyaltyAmountandbuildWhatsAppTemplateContextusing the tenant currency'scurrencyFractionDigits(supporting 0-decimal and 3-decimal currencies).whatsapp.triggerBillPaidAutomationafter committed exact-balance auto-settlements (completeExactBalanceSettlementinmain/routes/bills.ts), updatedocs/architecture/cloud-integrations.md, and add regression tests intests/whatsapp-service.test.tsandtests/issue-exact-balance-settlement.test.ts.Risk Assessment
✅ Low: The changes are tightly scoped to the four requested WhatsApp offline/concurrency/rounding fixes and exact-balance auto-settlement automation dispatch, with transaction-safe post-commit flushing and behavioral regression tests.
Testing
Ran the focused WhatsApp service, exact-balance settlement, offline-mode, and script-coverage suites, then stood up an isolated FloCafe Express API and SQLite instance to drive all six scenarios (including two adversarial boundary checks) live over HTTP and capture API response and database evidence; no UI surface was modified by this backend-only change, and all checks passed.
Evidence: Live scenario API responses and persisted SQLite state
Evidence: Live scenario execution transcript
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:whatsapp-servicenpm run test:issue-exact-balance-settlementnpm run test:offline-modenpm run test:script-coverageLive end-to-end HTTP + SQLite scenario run against isolated Express server (POST /api/whatsapp/enable,POST /api/whatsapp/connect,PUT /api/settings/offline-mode,GET /api/whatsapp/status,PUT /api/whatsapp/automation,POST /api/orders,POST /api/bills/generate,POST /api/bills/:id/split-check,POST /api/bills/:id/payment,PATCH /api/orders/:id/items/:itemId/edit,POST /api/bills/:id/applyDiscount,GET /api/whatsapp/messages)✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.