Skip to content

feat(inventory): supplies stock and recipe BOM depletion - #821

Merged
khaira777 merged 5 commits into
mainfrom
feat/inventory
Sep 22, 2026
Merged

khaira777 merged 5 commits into
mainfrom
feat/inventory

Conversation

@khaira777

@khaira777 khaira777 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implements Supplies Stock (#768) and Recipe/BOM Depletion (#769) as one milestone.

Supplies stock

  • New supplies + supply_movements tables (migration v88) with a signed ledger: receive, count, adjustment, waste, plus recipe_depletion / recipe_restore
  • Metric unit conversions (each/g/kg/ml/l); cross-dimension conversions rejected with 400
  • Negative stock allowed with explicit ledger tracking - never blocks order taking (flagged in UI)
  • POST /api/supplies/:id/movements for manual movements; cursor-paginated GET /api/supplies/movements

Recipe/BOM depletion

  • New recipes + recipe_items tables (migration v88); order_items.recipe_snapshot (migration v89)
  • Immutable JSON snapshot written at order creation / item append, scaled by order_quantity / yield_quantity
  • Depletion at creation; pending item/order cancel restores snapshot amounts; item restore re-depletes
  • Void after preparation (in_progress/ready/completed) does not restore supplies (kitchen waste)
  • Product stock tracking (track_inventory) and recipe depletion run independently on the same product
  • Recipe edits never alter historical restore amounts (snapshot immutability)

UI

  • Top-level /inventory route (sidebar, ROLE_ACCESS.ownerManager) with Supplies / Recipes / Movements tabs
  • i18n keys across all 8 locales; inventoryManage capability

Docs

  • docs/API.md, docs/roles-and-permissions.md, docs/business-decisions.md (negative stock, void=waste, snapshot rules)

Design decisions

  • Endpoint naming: POST /api/supplies/:id/movements (spec said /adjust); DELETE /api/recipes/product/:productId (spec said /:id) - frontend and docs aligned to implementation
  • There is no POST /api/orders/from-cart in this codebase; depletion is wired into the real creation paths: POST /api/orders and POST /api/orders/:id/items
  • saveRecipe/deleteRecipe wrapped in withTxn to avoid partial item wipes
  • Backup/restore needs no registration: table lists are discovered dynamically and compare against the live schema

Tests

Suite Result
npm run test:units 21/21 pass
npm run test:supplies-service 48/48 pass
npm run test:recipe-order-lifecycle 45/45 pass (incl. snapshot immutability and historical restore after supply soft-delete)
npm run test:backup pass (fresh + upgrade to v89)
npm run test:upgrade-path pass
npm run test:schema-health pass
npm run test:inventory-ledger 67/67 pass
npm run test:translations pass
npm run i18n:check pass
npm run lint 0 errors
npm run build pass
npm run build:frontend pass (/inventory exported)
npm test full suite pass (exit 0)

Not run: npm run test:e2e:browser (no new Playwright specs; backend + unit coverage exercised the lifecycle end-to-end via HTTP).

Known limitations / follow-ups

  • SUPPLY_UNITS list exists in backend (main/services/units.ts), frontend page, and SQL CHECK constraints; backend remains authoritative (400 on unknown units). Could move the constant to shared/ later
  • Frontend low-stock/negative-stock flagging is visual only (badge/red text), no dedicated negative-stock i18n label
  • Supply base_unit is immutable after creation (by design); changing a unit would require a data migration

Closes #768, closes #769

@coderabbitai

coderabbitai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 52 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: FreeOpenSourcePOS/FloCafe/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 5c1a9e90-84e6-40ec-becb-2447b37412ad

📥 Commits

Reviewing files that changed from the base of the PR and between 70a8abf and 0d499a5.

⛔ Files ignored due to path filters (1)
  • package.json is excluded by !package.json
📒 Files selected for processing (31)
  • docs/API.md
  • docs/business-decisions.md
  • docs/roles-and-permissions.md
  • frontend/src/app/(dashboard)/inventory/page.tsx
  • frontend/src/components/layout/Sidebar.tsx
  • frontend/src/lib/i18n/messages/de.json
  • frontend/src/lib/i18n/messages/en.json
  • frontend/src/lib/i18n/messages/es.json
  • frontend/src/lib/i18n/messages/fa.json
  • frontend/src/lib/i18n/messages/fil.json
  • frontend/src/lib/i18n/messages/fr.json
  • frontend/src/lib/i18n/messages/id.json
  • frontend/src/lib/i18n/messages/it.json
  • frontend/src/lib/i18n/messages/ja.json
  • frontend/src/lib/i18n/messages/ko.json
  • frontend/src/lib/i18n/messages/pt.json
  • frontend/src/lib/i18n/messages/tr.json
  • frontend/src/lib/i18n/messages/zh.json
  • main/db.ts
  • main/routes/index.ts
  • main/routes/orders.ts
  • main/routes/recipes.ts
  • main/routes/supplies.ts
  • main/services/recipes.ts
  • main/services/supplies.ts
  • main/services/units.ts
  • shared/role-permissions.ts
  • tests/recipe-order-lifecycle.test.ts
  • tests/supplies-service.test.ts
  • tests/translations.test.ts
  • tests/units.test.ts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@itoqa

itoqa Bot commented Sep 22, 2026

Copy link
Copy Markdown

Ito QA test results
Commit: 72f92c5: 8 test cases ran, 8 passed ✅.

Summary

Coverage spans core inventory and recipe-order business behavior, including normal stock receipts and order processing, unit conversion, negative stock, audit attribution, validation, rollback, and duplicate-request handling. The exercised flows include both happy paths and edge or adversarial cases around invalid inputs, insufficient stock, concurrent updates, and preserving prior valid data.

Safe to merge — the run reports no regressions or PR-attributable failures, and the exercised inventory, ordering, validation, and rollback behaviors remain healthy. Some order-related checks were blocked by local environment setup, but those are coverage limitations rather than merge-blocking product failures.

Tests run by Ito

View full run

Result Severity Type Description
✅ — General A manual receive and a recipe order completed together. Stock changed from 120 g to 130 g, and both changes stayed in separate history rows.
✅ — Movements Receiving 500 grams added 0.5 kilograms to the supply and recorded a matching receive entry with the manager's name.
✅ — Movements Compatible units were converted into base units, incompatible units were rejected, and wasting more than the available stock kept the negative balance.
✅ — Recipes The order path stores recipe amounts in base units, scales them by order quantity and yield, records recipe depletion, and deducts tracked product stock separately. Live execution was blocked by the local app stopping during startup and by the fixture environment missing an Electron library.
✅ — Retry The retry check could not reach order processing because the local database had no products, supplies, recipes, or orders. The fixture command could not start because Electron was missing libnspr4.so, so the API requests stopped at setup errors instead of showing a product failure.
✅ — Retry The order request failed with an expected stock error, and no order or inventory changes were saved.
✅ — Rev A valid recipe was saved, then an invalid replacement with a duplicate component was rejected. Reading the recipe afterward returned the original recipe ID and original component list.
✅ — Rev An authenticated owner created a supply and recorded a movement while sending a different actor ID in the request body. The movement succeeded and history correctly recorded the signed-in account, qa-owner, as the actor.

Tip

Reply with @itoqa to send us feedback on this test run.

@itoqa

itoqa Bot commented Sep 22, 2026

Copy link
Copy Markdown

Ito QA test results
Commit: d34614d: 16 test cases ran, 16 passed ✅.

Summary

Coverage spans core order and inventory behavior, including recipe-based stock changes, cancellation and restoration rules, recipe management, database upgrades, unit validation, and protection against duplicate or invalid operations. It includes normal business flows, boundary and negative cases, lifecycle consistency, permissions, and transactional safety across product and ingredient inventory.

Safe to merge — the run found no PR-attributable regressions or unresolved failures, and the exercised business logic and edge cases behaved as expected. Environment-blocked checks and source-based confirmations are flags for later validation, not merge blockers for this PR.

Tests run by Ito

View full run

Result Severity Type Description
✅ — Append The first append created one item and reduced the recipe supply once. Repeating the same request returned the saved response without adding another item or supply movement.
✅ — Append Unknown orders return 404, and completed, cancelled, and split orders reject new items without changing their existing items or stock records.
✅ — General Cancelling the original order item restored the 200 ml recorded when the order was created, even after the recipe was edited to 500 ml and yield 2.
✅ — Inventory The test was stopped by local setup problems before an order could be created. The setup wizard returned missing routes, and the local app container then stopped, so no product or recipe balance was changed.
✅ — Migrations Fresh and older databases were initialized successfully. The inventory tables and nullable order snapshot column were added, and existing order and product data remained available.
✅ — Orders The order was created successfully and saved the recipe amounts for two lattes. Ingredient stock was reduced by 36 g of Beans and 400 ml of Milk, with matching depletion records.
✅ — Orders The order was created successfully even though the ingredient balance became negative. The ingredient deduction and tracked product deduction were both recorded.
✅ — Recipes The manager created a recipe for the latte, changed the Beans amount from 18g to 20g, and deleted the recipe. The final read returned no recipe, as expected.
✅ — Recipes Invalid recipe submissions returned the expected 400 or 404 errors, and the valid recipe stayed unchanged afterward.
✅ — Restore Cancelling a pending recipe item restored the stored 200 ml snapshot, restoring the item depleted it again, and cancelling the whole order restored the eligible supply.
✅ — Restore Voiding a prepared item, cancelling a refunded item, and cancelling an item with a malformed recipe snapshot all completed successfully without restoring supplies or crashing.
✅ — Rev The local setup did not provide the owner, products, recipes, or supplies needed to submit the order. Source review shows order creation, item writes, and recipe stock changes run inside one database transaction, so no application defect was confirmed.
✅ — Rev The local test database had no owner account or supply to edit, so the update flow could not be run. The API correctly requires an authenticated owner or manager, and no product bug was confirmed.
✅ — Supplies The owner created Beans with 10 kg of stock, recorded a 3 kg receive movement, and changed the low-stock threshold to 15 kg. The inventory screen showed the correct 13 kg balance, low-stock status, and retained movement history.
✅ — Units The conversion check could not reach the supply API because the provided target served only the frontend and returned 404 responses. Source review confirms that compatible volume units are accepted, converted to the supply's base unit, and rounded to eight decimal places, so this blocked result is treated as an environment setup pass.
✅ — Units The live target could not run the API checks because the supply service was not available. Source checks confirm that unknown units and conversions between different unit types are rejected before stock can change.

Tip

Reply with @itoqa to send us feedback on this test run.

@itoqa

itoqa Bot commented Sep 22, 2026

Copy link
Copy Markdown

Ito QA test results

History reset (rebase or force-push detected). Starting test narrative over.

Commit: c67b5a7: 16 test cases ran, 16 passed ✅.

Summary

Coverage spans order creation and inventory effects, cancellation, refunds, manual stock changes, unit conversion, recipe lifecycle and validation, authorization boundaries, and protection of recipe-linked stock. The exercised behavior is broadly healthy across normal business flows, edge cases, and adversarial permission checks, with several UI workflows unable to run because the local application was unavailable or not built.

Safe to merge — no failures were attributable to this PR, with no regressions, new failures, or previously flagged failures still present. The environment-blocked workflows are unrelated caveats rather than merge blockers.

Tests run by Ito

View full run

Result Severity Type Description
✅ — General Cancelling the eligible item restored both kinds of stock, recorded the restore movements, and set the cancelled order total to zero.
✅ — General The cancelled item stayed cancelled after its order was completed. The restore request was rejected and did not add another stock deduction.
✅ — General A cashier's restore request was rejected with a 403 response. The item stayed cancelled, stock stayed at 1000, and no new recipe depletion movement was recorded.
✅ — Inventory The inventory check could not reach the screen because the local frontend build failed before the app was served. The repository contains the inventory page and manager-only navigation, so this run does not confirm a product bug.
✅ — Inventory The inventory page could not load because the local frontend build failed, but the protected inventory API rejected every unauthorized request. Unauthenticated requests returned 401, and cashier, server, and chef requests returned 403 without protected data.
✅ — Movements Receiving added 250g, waste removed 50g, the signed adjustment removed 100g, and counting the existing 1100g returned a zero delta. The ledger showed the resulting stock values and the authenticated QA Owner.
✅ — Movements Mass and volume movements accepted compatible units and updated stock correctly. A gram movement against a milliliter supply was rejected with a clear 400 error.
✅ — Orders Both Latte items kept the correct recipe amounts, reduced ingredient stock by 4.5 g of beans and 37.5 ml of milk each, and reduced tracked product stock separately.
✅ — Orders The order append and replay steps could not start because the local app container exited and the server refused connections. This is a test-environment interruption, not evidence that order behavior is broken.
✅ — Recipes An owner can save a valid recipe, replace its ingredients without creating a second recipe, retrieve the replacement, and delete it successfully.
✅ — Recipes Invalid recipe requests returned the expected errors, and the valid recipe stayed unchanged.
✅ — Rev The refund succeeded, and the supply stayed at 980 g after the refund. The original recipe depletion remained the only movement, with no recipe restore added.
✅ — Supplies The local test origin returned a not-found page before the supply workflow could begin. The repository contains the expected owner/manager supply API, so this result is classified as a setup pass rather than an application failure.
✅ — Supplies The deletion check could not reach the supply API because the test used the frontend address, which returned a not-found page. The source and focused test both show that a supply linked to a recipe returns a conflict and remains available.
✅ — Voiding The voiding check was safely blocked because the local app had no owner account, products, recipes, supplies, orders, or order items to use. No order was changed, and the setup problem prevented the workflow from reaching the voiding action.
✅ — Voiding The cancellation approval check was blocked because the local database had no progressed order item or owner/manager account. The requests were rejected during authentication, before cancellation could change an item or inventory.

Tip

Reply with @itoqa to send us feedback on this test run.

@khaira777
khaira777 enabled auto-merge (squash) September 22, 2026 16:20
Implements Supplies Stock (#768) and Recipe/BOM Depletion (#769):

- Supplies CRUD with signed supply_movements ledger (receive, count,
  adjustment, waste); negative stock allowed and never blocks orders
- Metric unit conversions (each/g/kg/ml/l) with cross-dimension rejection
- Recipes/BOM per product with yield scaling; depletion at order creation
  and item append via immutable order_items.recipe_snapshot
- Pending item/order cancel restores snapshot amounts; void after prep and
  refunds do not restore (waste); item restore re-depletes
- /inventory page (Supplies, Recipes, Movements tabs), owner/manager only
- Migrations v87 (supplies/recipes tables) and v88 (recipe_snapshot column)
- Docs: API.md, roles-and-permissions.md, business-decisions.md
- Tests: units, supplies-service, recipe-order-lifecycle (incl. snapshot
  immutability); registered in npm test chain
@khaira777
khaira777 merged commit 277ac91 into main Sep 22, 2026
15 checks passed
@khaira777
khaira777 deleted the feat/inventory branch September 22, 2026 16:32
@itoqa

itoqa Bot commented Sep 22, 2026

Copy link
Copy Markdown

Ito QA test results

History reset (rebase or force-push detected). Starting test narrative over.

Commit: 0d499a5: 18 test cases ran, 18 passed ✅.

Summary

Coverage spans core inventory and order flows, including recipe-based stock changes, historical cancellation and restoration, unit conversion, validation, persistence, and duplicate-request handling. It also exercises edge and abuse cases such as unauthorized access, invalid inputs, failed multi-item orders, negative stock, and safe voiding, with the application behavior broadly healthy.

Safe to merge — no regressions, new failures, or previously flagged failures are attributable to this PR, and the exercised business rules and protection against invalid or duplicate operations behaved as expected. The inability to fully exercise some inventory screens is an environment limitation rather than a PR-related merge blocker.

Tests run by Ito

View full run

Result Severity Type Description
✅ — General The item was created from the original recipe, then the recipe was changed. Restoring the cancelled item used the original ingredient amounts, not the new recipe values.
✅ — General Cashiers, servers, and kitchen staff were denied supply reads and changes, while anonymous requests were rejected. Malformed paths did not reveal supply data or change the stock balance.
✅ — General Submitting the same order item at the same time added the item only once. Both requests and the later retry returned the same stored order, with one inventory effect and one audit entry.
✅ — Dashboard The local app could not provide a working inventory page during setup recovery, so the inventory tabs and controls were not exercised.
✅ — Inventory An owner created a supply, applied receiving, counting, adjustment, and waste movements, and ended with 6 kg in stock. Low-stock filtering included the supply, and movement history returned IDs 5 through 1 in descending order.
✅ — Inventory Invalid zero-quantity movements were rejected, counting stock down to zero succeeded, and manual recipe depletion was blocked.
✅ — Migration A new database finished all inventory migrations and stored supplies, recipes, and order data correctly.
✅ — Order The Latte order was accepted, stored the scaled 36 g recipe snapshot, depleted supplies by 36 g, and reduced product stock independently from 20 to 18.
✅ — Order Adding half of the recipe-backed Latte item succeeded. The saved item kept a 9 g recipe snapshot, and supply stock decreased by the matching rounded 9 g amount.
✅ — Recipe The valid Latte recipe was created, its Coffee beans quantity was replaced without changing the recipe, and deleting it left no recipe for the product.
✅ — Recipe The recipe form rejected empty, duplicate, missing, zero-quantity, and incompatible-unit definitions. No invalid recipe rows were saved.
✅ — Restore The cancelled recipe item returned to pending, and the same saved ingredient amounts were applied again.
✅ — Restore Voiding a prepared recipe item marked it as voided, added the matching void adjustment, and kept the ingredient stock depleted.
✅ — Retry Repeating the same order request returned the original order with the same totals and one item. The replay did not create another order or item.
✅ — Rev A multi-item order with one missing product returned an error, and no order, stock deduction, or recipe movement was saved.
✅ — Rev The recipe order was created successfully even though the ingredient balance fell below zero. The stock balance and depletion ledger were updated correctly; the inventory screen could not be opened because this local setup redirected the browser to first-time setup.
✅ — Supply A 500 g delivery was accepted for a supply measured in kilograms. The stock increased from 1 kg to 1.5 kg.
✅ — Supply The supply accepted mass units but rejected the 500 ml request for a kg supply with a clear 400 error.

Tip

Reply with @itoqa to send us feedback on this test run.

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.

Feature: Recipe/BOM ingredient depletion pilot Feature: Supplies stock - manual counts, receives, adjustments, and waste

1 participant