Skip to content

URS-016 · Auto-decrement Inventory After Order Submission

Status: FAIL  ·  Duration: 1m 13s  ·  Run Date: April 21, 2026


SKIP

Step 1: Initial inventory

Step 1: Initial inventory


SKIP

Step 2: First order

Step 2: First order

Step 2: First order

Step 2: First order

Step 2: First order


SKIP

Step 3: Verify first decrement


FAIL PASS

Both test inventory items (SpeedPatch and FiberLocker) should exist at TRUNK-36

SELECT ii.id, ii.di, ii.lot, ii.quantity_ready, ii.quantity_backordered, ii.quantity_in_transit
FROM inventory_items ii
WHERE ii.real_world_location_id = $1
AND ii.lot IN ($2, $3)
ORDER BY ii.lot
iddilotquantity_readyquantity_backorderedquantity_in_transit
baf7086a-9bf8-4647-948a-6a1d97108e3307649988202247URS016-FL-0011300
cdc2b050-ed32-454d-b123-24feb9fa425407649988202230URS016-SP-0011700

PASS

Both inventory items should have quantity_ready less than their initial values

SELECT ii.lot, ii.quantity_ready,
CASE
WHEN ii.lot = $2 THEN 20
WHEN ii.lot = $3 THEN 15
END as initial_quantity,
CASE
WHEN ii.lot = $2 THEN 20 - ii.quantity_ready
WHEN ii.lot = $3 THEN 15 - ii.quantity_ready
END as total_decremented
FROM inventory_items ii
WHERE ii.real_world_location_id = $1
AND ii.lot IN ($2, $3)
ORDER BY ii.lot
lotquantity_readyinitial_quantitytotal_decremented
URS016-FL-00113152
URS016-SP-00117203

PASS

At least one billing order should have been created by Bob Kauffman in the last 30 minutes

SELECT bo.id, bo.order_number, bo.status, bo.procedure_date,
bo.created_at, bo.created_by_user_id
FROM billing_orders bo
WHERE bo.created_by_user_id = $1
AND bo.created_at > NOW() - INTERVAL '30 minutes'
ORDER BY bo.created_at DESC
LIMIT 5
idorder_numberstatusprocedure_datecreated_atcreated_by_user_id
019dade6-83cd-772f-8d65-2a3312027e9aBO-1submitted2026-04-20T05:00:00.000Z2026-04-21T02:37:38.620Z17b8c9d0-e1f2-3456-1234-567890123456

Billing order items reference correct products

Section titled “Billing order items reference correct products”
PASS

Billing order items should reference SpeedPatch and/or FiberLocker products

SELECT boi.id, boi.billing_order_id, op.title as product_name,
boi.lot_number, boi.serial_number, boi.location_id,
boi.inventory_discrepancy
FROM billing_order_items boi
JOIN org_products op ON boi.product_id = op.id
JOIN billing_orders bo ON boi.billing_order_id = bo.id
WHERE bo.created_by_user_id = $1
AND bo.created_at > NOW() - INTERVAL '30 minutes'
ORDER BY bo.created_at DESC, op.title
idbilling_order_idproduct_namelot_numberserial_numberlocation_idinventory_discrepancy
019dade6-83ca-7215-ba15-cee0b01a5b19019dade6-83cd-772f-8d65-2a3312027e9aFiberLocker® Instrument SNURS016-FL-001a6e7f8a9-b0c1-2345-0123-456789012345false
019dade6-83ca-7215-ba15-cee1a24c7aa7019dade6-83cd-772f-8d65-2a3312027e9aFiberLocker® Instrument SNURS016-FL-001a6e7f8a9-b0c1-2345-0123-456789012345false
019dade6-83ca-7215-ba15-cee2651b1461019dade6-83cd-772f-8d65-2a3312027e9aSpeedPatch® PETURS016-SP-001a6e7f8a9-b0c1-2345-0123-456789012345false
019dade6-83ca-7215-ba15-cee33600bfc7019dade6-83cd-772f-8d65-2a3312027e9aSpeedPatch® PETURS016-SP-001a6e7f8a9-b0c1-2345-0123-456789012345false
019dade6-83ca-7215-ba15-cee4c99ed511019dade6-83cd-772f-8d65-2a3312027e9aSpeedPatch® PETURS016-SP-001a6e7f8a9-b0c1-2345-0123-456789012345false

Inventory history records bill_only_order removals

Section titled “Inventory history records bill_only_order removals”
PASS

Inventory history should contain records with action=removed and reason=bill_only_order

SELECT ih.id, ih.item_id, ih.quantity, ih.status, ih.info,
ih.created_at, ih.inventory_id
FROM inventory_history ih
WHERE ih.item_id IN (
SELECT id FROM inventory_items
WHERE real_world_location_id = $1
AND lot IN ($2, $3)
)
AND ih.created_at > NOW() - INTERVAL '30 minutes'
AND ih.info->>'action' = 'removed'
AND ih.info->>'reason' = 'bill_only_order'
ORDER BY ih.created_at DESC
LIMIT 20
iditem_idquantitystatusinfocreated_atinventory_id
019dade6-83d3-7441-b6ec-88404d3172f9baf7086a-9bf8-4647-948a-6a1d97108e332ready[object Object]2026-04-21T02:37:38.620Z019dade5-e978-7ffd-ae76-88b746f288c3
019dade6-83d3-7441-b6ec-8841d5d603d3cdc2b050-ed32-454d-b123-24feb9fa42543ready[object Object]2026-04-21T02:37:38.620Z019dade5-e978-7ffd-ae76-88b746f288c3

PASS

Inventory transactions should exist with source_type = bill_only_order

SELECT it.id, it.source_type, it.source_id, it.created_at,
it.distributor_organization_id, it.manufacturer_organization_id
FROM inventory_transactions it
WHERE it.source_type = 'bill_only_order'
AND it.created_at > NOW() - INTERVAL '30 minutes'
AND (it.distributor_organization_id = $1 OR it.manufacturer_organization_id = $1)
ORDER BY it.created_at DESC
LIMIT 10
idsource_typesource_idcreated_atdistributor_organization_idmanufacturer_organization_id
019dade6-83d1-7e4d-819c-61d4b420b53bbill_only_order019dade6-83cd-772f-8d65-2a3312027e9a2026-04-21T02:37:38.620Zb2c3d4e5-f6a7-8901-bcde-f12345678901

PASS

Inventory quantities should never go below zero (CHECK constraint enforced)

SELECT ii.id, ii.lot, ii.quantity_ready
FROM inventory_items ii
WHERE ii.real_world_location_id = $1
AND ii.lot IN ($2, $3)
AND ii.quantity_ready < 0

No rows returned.