Add nested inventory package tracking
This commit is contained in:
+3
-1
@@ -30,7 +30,7 @@ Collection responses use `count`, `limit`, `offset`, and `results`. The default
|
||||
|
||||
JSON decimal values are strings to preserve precision. For food creation, send `meal`, positive decimal `amount`, and `unit` (`g` or `ml`). With `product_id`, nutrition and name snapshots are calculated from that owned product using the same service as the web UI, and the unit must match its basis. Without a product, send `product_name` and optional `brand`, `barcode`, `portion_label`, and nutrition totals (`calories_kcal`, `carbohydrates_g`, `protein_g`, `fat_g`, `fibre_g`, `sugars_g`, `salt_g`). Manual entries are snapshot-only, so repeat estimates do not create duplicate products. `date` defaults to the user's saved local time zone date; an explicit ISO date and optional time can be supplied. API entries have `created_via: api`, separate from their nutrition `source`.
|
||||
|
||||
Inventory creation requires an owned product UUID, positive integer `quantity`, and a location name. Optional fields are `category`, `notes`, `opened`, and `best_before`. Location and category names reuse the application's owned lookup records. There is no invented inventory unit: the existing model counts whole items. DELETE removes the item, matching the API operation; the web inventory still has its separate archive behavior.
|
||||
Inventory creation requires an owned product UUID, positive integer `quantity` (outer package count), and a location name. Optional fields include `category`, `notes`, `opened`, and `best_before`. Flat packages may supply `original_amount` and `unit`, `pieces_per_package`, `remaining_pieces`, and explicit `piece_amount`. For one nested layer, supply `inner_packs_per_package`, `pieces_per_inner_pack`, `inner_pack_label`, `piece_label`, and (for measured stock) `inner_pack_amount`; `original_amount` is derived as inner-pack amount × inner-pack count. Total pieces are derived from the two counts. For example, 6 inner packs × 3 biscuits with 44 g per inner pack creates one 264 g package with 18 pieces. Per-biscuit weight is an estimate derived from the measured inner-pack amount. With no measured amount, nested piece contents use `pieces` as the stock unit. Location and category names reuse the application's owned lookup records. DELETE removes the item, matching the API operation; the web inventory still has its separate archive behavior.
|
||||
|
||||
For attachment upload, send multipart `image` and optional `caption`. JPEG, PNG, and WebP are accepted after decoding and format/MIME checks. The file limit is 5 MiB and the pixel limit is 25 million. Images are stored under `main/private_media/`, which has no public media URL; download requires `food:read` and ownership of the parent entry. Filenames on disk are random. The original filename is metadata only.
|
||||
|
||||
@@ -42,6 +42,8 @@ Food Diary entries saved in millilitres can count toward hydration automatically
|
||||
|
||||
For a packaged inventory item, `PATCH /kitchen/items/{id}/` may set `remaining_amount` to an absolute value from zero through its current remaining amount. A reduction uses the existing inventory consumption service; zero archives that package from active inventory. `opened`, `notes`, and other metadata can be sent in the same request. Increasing stock or exceeding the package capacity is rejected. Quantity validation errors return `error.details.field` and `error.details.reason`.
|
||||
|
||||
For piece-aware stock, `PATCH` may instead set absolute `remaining_pieces`; a reduction consumes the difference atomically and updates measured stock and opened state. Do not send both remaining fields in one request. Flat piece-to-mass or piece-to-volume conversion requires an explicit `piece_amount`. Nested packages derive piece estimates from the explicit `inner_pack_amount`; measured deductions must correspond to whole pieces, and the final piece consumes the exact remaining residual. Consumption accepts `inner_packs` for configured nested packages. Inventory responses include the inner-pack counts, labels, and derived opened-inner-pack remainder. A count-only legacy row can be converted in place by supplying `quantity` explicitly with package contents and, when needed, measured amount and unit. Historical food logs are untouched.
|
||||
|
||||
## Example requests
|
||||
|
||||
```sh
|
||||
|
||||
Reference in New Issue
Block a user