Skip to content

fix(pos): store offline invoices as plain data - #147

Draft
phronesis wants to merge 1 commit into
kodlyft:developfrom
VigesimalTech:fix/offline-invoice-plain-data
Draft

phronesis wants to merge 1 commit into
kodlyft:developfrom
VigesimalTech:fix/offline-invoice-plain-data

Conversation

@phronesis

Copy link
Copy Markdown

What

Stores offline invoices and purchases as plain data, so a sale completed offline is actually saved instead of failing with "Failed to save invoice offline".

Why

cartStore.getInvoiceData() passes payments and pos_change_legs as live Vue arrays (reactive proxies). dbBridge.addPendingInvoice writes the record straight to IndexedDB (or sends it over Electron IPC), and both copy with the structured clone algorithm, which throws DataCloneError on a Proxy. The payment dialog then reports "Failed to save invoice offline", and the offline sale is lost. addPendingPurchase has the same problem. idbService already runs everything else through sanitizeForIdb; these two paths skipped it.

To reproduce: open a shift on a POS Profile with offline mode on, go offline (DevTools → Network → Offline), and complete a cash sale.

Changes

  • frontend/src/services/dbBridge.ts: runs addPendingInvoice and addPendingPurchase records through sanitizeForIdb before they're stored, for both IndexedDB and Electron.
  • Refactor: sanitizeForIdb moved unchanged from idbService.ts to a new frontend/src/services/idbSanitize.ts, so dbBridge can use it without importing Dexie. idbService.ts imports and re-exports it.
  • Tests, in frontend/tests/dbBridge.spec.ts (3 tests): reactive arrays are stored as structured-clone-safe plain data, for invoices in browser and Electron mode and for purchases. All three fail without the fix.

The cart passes its payments and change legs as live Vue arrays.
dbBridge.addPendingInvoice and addPendingPurchase wrote them to IndexedDB
(or sent them over IPC) as-is, and structured clone throws DataCloneError
on a Proxy, so a cash sale made offline failed with "Failed to save
invoice offline".

Run both records through sanitizeForIdb first, which idbService already
used for everything else. It moves to its own module so dbBridge can use
it without pulling in Dexie.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant