Add nested inventory package tracking

This commit is contained in:
Joren de Graaf
2026-10-26 00:25:00 +01:00
parent 4d76a2bc9c
commit 5217c7f30c
19 changed files with 838 additions and 44 deletions
+2
View File
@@ -108,6 +108,8 @@ The corresponding HTTP routes are listed in `GET /api/v1/schema/`. Recipe meal d
`inventory_update` accepts an absolute `remaining_amount` for one owned package. Reductions use the same consumption service as `inventory_consume`; zero archives the package. It can update `opened` and `notes` in the same request. A rejected quantity returns `success: false` with `error.details.field` and `error.details.reason`.
Inventory `quantity` is outer-package count. Flat packages use `pieces_per_package`, `remaining_pieces`, and optional explicit `piece_amount`. Nested packages add `inner_packs_per_package`, `pieces_per_inner_pack`, labels, and (for measured stock) `inner_pack_amount`. The outer amount and total piece count are derived from that metadata; per-piece weight is estimated from the measured inner-pack amount. `inventory_get_stock` exposes both piece and measured totals plus the nested breakdown. Preview and consume accept `pieces`, `inner_packs`, or matching g/ml amounts where the metadata supports conversion; measured deductions must map to whole pieces, with the final piece taking the exact remaining residual. `inventory_update` can reduce absolute `remaining_pieces` through the same atomic ledger. Converting a count-only legacy row requires explicitly setting package count so an old mistaken count is not multiplied into stock.
### Bulk inventory housekeeping
`inventory_bulk_update` accepts 1–50 `{item_id, changes}` entries. `changes` uses the same fields and stock rules as `inventory_update`; omitted fields stay unchanged. Optional `expected_updated_at` rejects an item that changed since it was read. `dry_run` defaults to true and returns per-item before/after snapshots without saving. Set `dry_run: false` and provide an `idempotency_key` to apply. The default allows valid entries to succeed when others fail; `atomic: true` rolls back the whole batch on any failure. Duplicate IDs and oversized batches are rejected before writes.