- ID
- d1756c44-9896-465c-abf7-ae5605efad68
BE-6945 Create Django management command to assess pairing product stock status by origin
- source :: https://hungryroot.atlassian.net/browse/BE-6945
- tags :: Hungryroot API Project
- epic :: EP-411 Eng Parking Lot
- sprint :: HR BE Sprint 102
- status :: Status - Complete
Tasks
DONE Ask Cursor to make a first pass on a pairing product stock management command
- ID
- 061f6d74-ac9c-50a3-d874-bcd27f01847b
DONE Kick the tires and test stock status command locally
- ID
- d30789aa-f8ea-21ff-b4a7-00710146115e
DONE Update command to take just pairing-id or product-id
- ID
- ccae8668-628f-2eff-32d9-da19abc19903
DONE Verify output of product stock comamnd is correct
- ID
- cfdd68b2-1701-2251-80a9-b2d51ecd7395
DONE Address PR review comments
- ID
- 7b1b38ed-85d6-8f05-4da8-af5946ffe26d
DONE Fix failing tests
- ID
- ad8ae2ee-40dc-73df-c7c0-be3466441386
Description
Create a Django management command to check stock status for pairings or
products given an origin ID and inventory date(s). For pairings, report which
ingredients are in/out of stock. For products, report in/out of stock. Support
checking multiple upcoming inventory dates when only an origin is provided.
Requirements
Core Functionality
Accept inputs:
--pairing-id (optional): Pairing ID to check
--product-id (optional): Product ID to check
--origin-id (required): Origin ID (fulfillment center)
--inventory-date (optional): Specific inventory date (YYYY-MM-DD). If omitted
and only origin is provided, check current and upcoming inventory dates (3-4
dates)
Stock status logic:
Product: customizable_units = swappable - sold. In stock if customizable_units >
0, otherwise out of stock.
Pairing: Check all ingredients (via PairingIngredient). Pairing is in stock only
if all ingredients have customizable_units > 0. Report per-ingredient status.
Output format:
JSON or human-readable table
Include:
Entity ID (pairing/product)
Entity name
Origin ID and name
Inventory date(s)
Stock status (in stock/out of stock)
For pairings: breakdown of ingredient statuses
Additional metrics: swappable, sold, available, customizable_units
Extended Functionality (Origin-only mode)
When only --origin-id is provided (no pairing/product ID, no inventory date):
Calculate current and upcoming inventory dates (3-4 dates) using
get_algolia_sync_inventory_dates() or similar
Return stock status for all dates
Optionally filter to active products/pairings only
Command Usage Examples
# Check specific pairing for specific date
python manage.py check_stock_status --pairing-id 123 --origin-id 1
--inventory-date 2024-01-15
# Check specific product for specific date
python manage.py check_stock_status --product-id 456 --origin-id 1
--inventory-date 2024-01-15
# Check pairing for multiple upcoming dates (origin-only mode)
python manage.py check_stock_status --pairing-id 123 --origin-id 1
# Check all upcoming dates for an origin (origin-only mode)
python manage.py check_stock_status --origin-id 1
cceptance Criteria
[ ] Command accepts --pairing-id, --product-id, --origin-id, and
--inventory-date arguments
[ ] Command correctly calculates stock status using customizable_units =
swappable - sold
[ ] For pairings, command reports status for all ingredients
[ ] When only origin is provided, command checks 3-4 upcoming inventory dates
[ ] Command outputs clear, structured results (JSON or table format)
[ ] Command handles edge cases: missing inventory records, inactive
products/pairings, invalid IDs
[ ] Command includes appropriate error handling and validation
[ ] Command follows existing management command patterns (see
app/management/commands/nightly.py)
[ ] Command is well-documented with docstrings
Notes
Consider adding --verbose flag for detailed output
Consider adding --format flag to choose between JSON and table output
Consider caching inventory queries if performance becomes an issue
This command will be useful for operations teams to quickly assess stock
availability for troubleshooting and planning