feat: scan product barcodes to stock up after shopping #5

Merged
tomas merged 1 commit from feat/barcode-scanning into master 2026-11-11 17:41:31 +00:00
Owner

Summary

A barcode scanner for stocking up after shopping (Zásoby → Skenovat).

  • Camera: the browser's BarcodeDetector where it reads product codes (Chrome on Android), otherwise the ZXing WebAssembly polyfill (barcode-detector), served from our origin. The CSP's script-src gains 'wasm-unsafe-eval'. Reads EAN-13, EAN-8, UPC-A/E and ITF; codes can also be typed.
  • Batch scanning: the camera stays on; a code counts once while in sight and again after it was out of sight for 2.5 s. Every counted scan is in a log with Vrátit.
  • Learning codes: an unknown code waits in a queue and is assigned to a stock item (or a new one) with its package size; from then on the household's app knows it. No product database lookup: they know few Czech private labels.
  • No double counting with lists: the server decides what a known code does. An item waiting on an open list is checked off there (finishing the list stocks it), one already in the basket changes nothing, anything else adds one package to the stock.

API

  • New table stock_item_barcodes (household, stock item, code, package size; unique code per household, several codes per item, deleted with the item).
  • GET|POST /households/{household}/barcodes, DELETE /households/{household}/barcodes/{barcode}, POST /households/{household}/scans (404 for an unknown code). All in the household group; openapi.json and schema.d.ts regenerated.

Testing

  • make ci passed: backend, frontend (lint, svelte-check, Vitest, Playwright, build) and commits.
  • Pest: assigning and moving codes, validation, all three scan results, rows added by name before the stock item existed, deleting with the item, and another household's codes, items and lists out of reach.
  • Vitest for the code filter and messages; Playwright e2e through typed codes (known code with undo, learning an unknown code, invalid input).
  • The camera path on the production frontend image (nginx with the real CSP): Chromium with a fake camera playing an EAN-13 video read the code through the WASM polyfill and counted it once. Screenshots checked at 390 px and 820 px.
  • Not tried on a real phone yet.
## Summary A barcode scanner for stocking up after shopping (**Zásoby → Skenovat**). - **Camera:** the browser's `BarcodeDetector` where it reads product codes (Chrome on Android), otherwise the ZXing WebAssembly polyfill (`barcode-detector`), served from our origin. The CSP's `script-src` gains `'wasm-unsafe-eval'`. Reads EAN-13, EAN-8, UPC-A/E and ITF; codes can also be typed. - **Batch scanning:** the camera stays on; a code counts once while in sight and again after it was out of sight for 2.5 s. Every counted scan is in a log with **Vrátit**. - **Learning codes:** an unknown code waits in a queue and is assigned to a stock item (or a new one) with its package size; from then on the household's app knows it. No product database lookup: they know few Czech private labels. - **No double counting with lists:** the server decides what a known code does. An item waiting on an open list is checked off there (finishing the list stocks it), one already in the basket changes nothing, anything else adds one package to the stock. ### API - New table `stock_item_barcodes` (household, stock item, code, package size; unique code per household, several codes per item, deleted with the item). - `GET|POST /households/{household}/barcodes`, `DELETE /households/{household}/barcodes/{barcode}`, `POST /households/{household}/scans` (404 for an unknown code). All in the household group; `openapi.json` and `schema.d.ts` regenerated. ## Testing - `make ci` passed: backend, frontend (lint, svelte-check, Vitest, Playwright, build) and commits. - Pest: assigning and moving codes, validation, all three scan results, rows added by name before the stock item existed, deleting with the item, and another household's codes, items and lists out of reach. - Vitest for the code filter and messages; Playwright e2e through typed codes (known code with undo, learning an unknown code, invalid input). - The camera path on the production frontend image (nginx with the real CSP): Chromium with a fake camera playing an EAN-13 video read the code through the WASM polyfill and counted it once. Screenshots checked at 390 px and 820 px. - Not tried on a real phone yet.
feat: scan product barcodes to stock up after shopping
All checks were successful
CI / backend (pull_request) Successful in 1m37s
CI / commits (pull_request) Successful in 41s
CI / frontend (pull_request) Successful in 3m11s
CI / release (pull_request) Has been skipped
CI / images (pull_request) Has been skipped
CI / backend (push) Successful in 1m34s
CI / commits (push) Successful in 38s
CI / frontend (push) Successful in 3m5s
CI / release (push) Successful in 38s
CI / images (push) Successful in 1m39s
0599696d28
Unpacking a shopping trip item by item is slow, so the stock gets a
scanner that reads product barcodes with the phone's camera. It uses the
browser's BarcodeDetector where it reads product codes, otherwise the
ZXing WebAssembly polyfill, served from our origin; the CSP allows
'wasm-unsafe-eval' for it. The camera stays on, so a whole purchase can
be scanned in a row, and every counted scan can be taken back.

A household teaches the app its codes (new stock_item_barcodes table,
several codes per stock item): an unknown code waits in a queue and is
assigned to a stock item, or a new one, with its package size. Product
databases know few Czech private labels, so there is no lookup.

A known code is counted by the server: an item waiting on an open list
is checked off there, because finishing the list stocks it; one already
in the basket changes nothing; anything else adds one package to the
stock. Buying by a list and scanning therefore never count twice.
tomas merged commit 0599696d28 into master 2026-11-11 17:41:31 +00:00
tomas deleted branch feat/barcode-scanning 2026-11-11 17:41:31 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
tomas/household!5
No description provided.