fix: add bin_location to inventory fixtures and service
- Add warehouse and bin_location fields to test fixtures - Update InventoryService to include warehouse/bin_location when creating entries - Fix all Inventory model instantiations in tests to include required fields - All 119 inventory tests now pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -84,7 +84,9 @@ class InventoryService:
|
||||
new_inventory = Inventory(
|
||||
product_id=inventory_data.product_id,
|
||||
vendor_id=vendor_id,
|
||||
location=location,
|
||||
warehouse="strassen", # Default warehouse
|
||||
bin_location=location, # Use location as bin location
|
||||
location=location, # Keep for backward compatibility
|
||||
quantity=inventory_data.quantity,
|
||||
gtin=product.marketplace_product.gtin, # Optional reference
|
||||
)
|
||||
@@ -148,7 +150,9 @@ class InventoryService:
|
||||
new_inventory = Inventory(
|
||||
product_id=inventory_data.product_id,
|
||||
vendor_id=vendor_id,
|
||||
location=location,
|
||||
warehouse="strassen", # Default warehouse
|
||||
bin_location=location, # Use location as bin location
|
||||
location=location, # Keep for backward compatibility
|
||||
quantity=inventory_data.quantity,
|
||||
gtin=product.marketplace_product.gtin,
|
||||
)
|
||||
|
||||
5
tests/fixtures/vendor_fixtures.py
vendored
5
tests/fixtures/vendor_fixtures.py
vendored
@@ -191,6 +191,8 @@ def test_inventory(db, test_product):
|
||||
inventory = Inventory(
|
||||
product_id=test_product.id,
|
||||
vendor_id=test_product.vendor_id,
|
||||
warehouse="strassen",
|
||||
bin_location=f"SA-10-{unique_id[:2]}",
|
||||
location=f"WAREHOUSE_A_{unique_id}",
|
||||
quantity=100,
|
||||
reserved_quantity=10,
|
||||
@@ -208,7 +210,10 @@ def multiple_inventory_entries(db, multiple_products, test_vendor):
|
||||
inventory_entries = []
|
||||
for i, product in enumerate(multiple_products):
|
||||
inventory = Inventory(
|
||||
product_id=product.id,
|
||||
gtin=product.gtin,
|
||||
warehouse="strassen",
|
||||
bin_location=f"SA-{i:02d}-01",
|
||||
location=f"LOC_{i}",
|
||||
quantity=10 + (i * 5),
|
||||
reserved_quantity=i,
|
||||
|
||||
@@ -452,6 +452,8 @@ class TestAdminInventoryAPI:
|
||||
new_inventory = Inventory(
|
||||
product_id=test_product.id,
|
||||
vendor_id=test_vendor.id,
|
||||
warehouse="strassen",
|
||||
bin_location="DEL-01-01",
|
||||
location="TO_DELETE_WAREHOUSE",
|
||||
quantity=50,
|
||||
)
|
||||
|
||||
@@ -17,6 +17,8 @@ class TestInventoryModel:
|
||||
inventory = Inventory(
|
||||
product_id=test_product.id,
|
||||
vendor_id=test_vendor.id,
|
||||
warehouse="strassen",
|
||||
bin_location="SA-10-01",
|
||||
location="WAREHOUSE_A",
|
||||
quantity=150,
|
||||
reserved_quantity=10,
|
||||
@@ -31,26 +33,31 @@ class TestInventoryModel:
|
||||
assert inventory.product_id == test_product.id
|
||||
assert inventory.vendor_id == test_vendor.id
|
||||
assert inventory.location == "WAREHOUSE_A"
|
||||
assert inventory.bin_location == "SA-10-01"
|
||||
assert inventory.quantity == 150
|
||||
assert inventory.reserved_quantity == 10
|
||||
assert inventory.available_quantity == 140 # 150 - 10
|
||||
|
||||
def test_inventory_unique_product_location(self, db, test_vendor, test_product):
|
||||
"""Test unique constraint on product_id + location."""
|
||||
"""Test unique constraint on product_id + warehouse + bin_location."""
|
||||
inventory1 = Inventory(
|
||||
product_id=test_product.id,
|
||||
vendor_id=test_vendor.id,
|
||||
warehouse="strassen",
|
||||
bin_location="SA-10-01",
|
||||
location="WAREHOUSE_A",
|
||||
quantity=100,
|
||||
)
|
||||
db.add(inventory1)
|
||||
db.commit()
|
||||
|
||||
# Same product + location should fail
|
||||
# Same product + warehouse + bin_location should fail
|
||||
with pytest.raises(IntegrityError):
|
||||
inventory2 = Inventory(
|
||||
product_id=test_product.id,
|
||||
vendor_id=test_vendor.id,
|
||||
warehouse="strassen",
|
||||
bin_location="SA-10-01",
|
||||
location="WAREHOUSE_A",
|
||||
quantity=50,
|
||||
)
|
||||
@@ -64,16 +71,20 @@ class TestInventoryModel:
|
||||
inventory1 = Inventory(
|
||||
product_id=test_product.id,
|
||||
vendor_id=test_vendor.id,
|
||||
warehouse="strassen",
|
||||
bin_location="SA-10-01",
|
||||
location="WAREHOUSE_A",
|
||||
quantity=100,
|
||||
)
|
||||
db.add(inventory1)
|
||||
db.commit()
|
||||
|
||||
# Same product in different location should succeed
|
||||
# Same product in different bin_location should succeed
|
||||
inventory2 = Inventory(
|
||||
product_id=test_product.id,
|
||||
vendor_id=test_vendor.id,
|
||||
warehouse="strassen",
|
||||
bin_location="SA-10-02",
|
||||
location="WAREHOUSE_B",
|
||||
quantity=50,
|
||||
)
|
||||
@@ -82,13 +93,15 @@ class TestInventoryModel:
|
||||
db.refresh(inventory2)
|
||||
|
||||
assert inventory2.id is not None
|
||||
assert inventory2.location == "WAREHOUSE_B"
|
||||
assert inventory2.bin_location == "SA-10-02"
|
||||
|
||||
def test_inventory_default_values(self, db, test_vendor, test_product):
|
||||
"""Test Inventory model default values."""
|
||||
inventory = Inventory(
|
||||
product_id=test_product.id,
|
||||
vendor_id=test_vendor.id,
|
||||
warehouse="strassen",
|
||||
bin_location="DEF-01-01",
|
||||
location="DEFAULT_LOC",
|
||||
quantity=100,
|
||||
)
|
||||
@@ -104,6 +117,8 @@ class TestInventoryModel:
|
||||
inventory = Inventory(
|
||||
product_id=test_product.id,
|
||||
vendor_id=test_vendor.id,
|
||||
warehouse="strassen",
|
||||
bin_location="PROP-01-01",
|
||||
location="PROP_TEST",
|
||||
quantity=200,
|
||||
reserved_quantity=50,
|
||||
@@ -119,6 +134,8 @@ class TestInventoryModel:
|
||||
inventory = Inventory(
|
||||
product_id=test_product.id,
|
||||
vendor_id=test_vendor.id,
|
||||
warehouse="strassen",
|
||||
bin_location="REL-01-01",
|
||||
location="REL_TEST",
|
||||
quantity=100,
|
||||
)
|
||||
@@ -136,6 +153,8 @@ class TestInventoryModel:
|
||||
inventory = Inventory(
|
||||
product_id=test_product.id,
|
||||
vendor_id=test_vendor.id,
|
||||
warehouse="strassen",
|
||||
bin_location="NOGTIN-01-01",
|
||||
location="NO_GTIN",
|
||||
quantity=100,
|
||||
)
|
||||
|
||||
@@ -251,6 +251,8 @@ class TestProductInventoryProperties:
|
||||
inv1 = Inventory(
|
||||
product_id=product.id,
|
||||
vendor_id=test_vendor.id,
|
||||
warehouse="strassen",
|
||||
bin_location="SA-01-01",
|
||||
location="WAREHOUSE_A",
|
||||
quantity=100,
|
||||
reserved_quantity=10,
|
||||
@@ -258,6 +260,8 @@ class TestProductInventoryProperties:
|
||||
inv2 = Inventory(
|
||||
product_id=product.id,
|
||||
vendor_id=test_vendor.id,
|
||||
warehouse="strassen",
|
||||
bin_location="SA-01-02",
|
||||
location="WAREHOUSE_B",
|
||||
quantity=50,
|
||||
reserved_quantity=5,
|
||||
@@ -311,6 +315,8 @@ class TestProductInventoryProperties:
|
||||
inv = Inventory(
|
||||
product_id=product.id,
|
||||
vendor_id=test_vendor.id,
|
||||
warehouse="strassen",
|
||||
bin_location="DIG-01-01",
|
||||
location="DIGITAL_LICENSES",
|
||||
quantity=10,
|
||||
reserved_quantity=2,
|
||||
|
||||
@@ -533,6 +533,8 @@ class TestStatsService:
|
||||
unique_id = str(uuid.uuid4())[:8]
|
||||
additional_inventory = Inventory(
|
||||
gtin=f"123456789{unique_id[:4]}",
|
||||
warehouse="strassen",
|
||||
bin_location=f"ST-{unique_id[:2]}-01",
|
||||
location=f"LOCATION2_{unique_id}",
|
||||
quantity=25,
|
||||
reserved_quantity=5,
|
||||
|
||||
Reference in New Issue
Block a user