diff --git a/app/services/inventory_service.py b/app/services/inventory_service.py index f34cfbd9..b09abdba 100644 --- a/app/services/inventory_service.py +++ b/app/services/inventory_service.py @@ -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, ) diff --git a/tests/fixtures/vendor_fixtures.py b/tests/fixtures/vendor_fixtures.py index 1e91acfa..ba63c6e5 100644 --- a/tests/fixtures/vendor_fixtures.py +++ b/tests/fixtures/vendor_fixtures.py @@ -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, diff --git a/tests/integration/api/v1/admin/test_inventory.py b/tests/integration/api/v1/admin/test_inventory.py index 4a43a266..2aede5b2 100644 --- a/tests/integration/api/v1/admin/test_inventory.py +++ b/tests/integration/api/v1/admin/test_inventory.py @@ -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, ) diff --git a/tests/unit/models/database/test_inventory.py b/tests/unit/models/database/test_inventory.py index c2909a07..ce158f42 100644 --- a/tests/unit/models/database/test_inventory.py +++ b/tests/unit/models/database/test_inventory.py @@ -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, ) diff --git a/tests/unit/models/database/test_product.py b/tests/unit/models/database/test_product.py index 01faf420..9f07b4c4 100644 --- a/tests/unit/models/database/test_product.py +++ b/tests/unit/models/database/test_product.py @@ -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, diff --git a/tests/unit/services/test_stats_service.py b/tests/unit/services/test_stats_service.py index 30d01bc4..1b96da5a 100644 --- a/tests/unit/services/test_stats_service.py +++ b/tests/unit/services/test_stats_service.py @@ -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,