修复:收紧托盘业务权限与数据契约

This commit is contained in:
焦龙言
2026-07-27 17:40:24 +08:00
parent 9b1a807098
commit 4a321098f8
16 changed files with 823 additions and 59 deletions
@@ -552,10 +552,11 @@ class ShipmentReadServiceTest(unittest.IsolatedAsyncioTestCase):
query = ShipmentScanQueryModel(sourceWarehouseId=7, targetSiteId=9)
pallet = make_pallet(2)
inventory = make_inventory(2, remaining_packages=8)
filling = make_filling(2)
filling = make_filling(2, warehouse_id=3)
lock_inventory = AsyncMock()
lock_pallets = AsyncMock()
lock_filling = AsyncMock()
get_filling = AsyncMock(return_value=filling)
with (
patch.object(AccessService, 'assert_warehouse_access', new=AsyncMock()),
patch.object(AccessService, 'assert_site_access', new=AsyncMock()),
@@ -586,7 +587,7 @@ class ShipmentReadServiceTest(unittest.IsolatedAsyncioTestCase):
),
patch.object(InventoryDao, 'get_pallet_by_qr_token', new=AsyncMock(return_value=pallet)),
patch.object(MasterDao, 'get_pallet_inventory', new=AsyncMock(return_value=inventory)),
patch.object(OperationDao, 'get_filling_by_id', new=AsyncMock(return_value=filling)),
patch.object(OperationDao, 'get_filling_by_id', new=get_filling),
patch.object(InventoryDao, 'get_inventories_for_update', new=lock_inventory),
patch.object(InventoryDao, 'get_pallets_by_ids', new=lock_pallets),
patch.object(OperationDao, 'get_active_filling_for_update', new=lock_filling),
@@ -605,6 +606,7 @@ class ShipmentReadServiceTest(unittest.IsolatedAsyncioTestCase):
self.assertEqual(PalletFlowState.FILLED_IN_WAREHOUSE, result.flow_state)
self.assertEqual(8, result.remaining_packages)
self.assertEqual(['shipment'], result.allowed_actions)
get_filling.assert_awaited_once_with(self.db, inventory.active_filling_id)
lock_inventory.assert_not_awaited()
lock_pallets.assert_not_awaited()
lock_filling.assert_not_awaited()
@@ -723,6 +725,34 @@ class ShipmentDraftServiceTest(unittest.IsolatedAsyncioTestCase):
self.user = make_user()
self.fixed_time = datetime(2026, 7, 26, 16, 30)
async def test_residual_return_can_be_re_shipped_from_current_inventory_warehouse(self) -> None:
inventory = make_inventory(2, warehouse_id=7, remaining_packages=6)
pallet = make_pallet(2)
origin_filling = make_filling(2, warehouse_id=3)
with (
patch.object(
InventoryDao,
'get_inventories_for_update',
new=AsyncMock(return_value=[inventory]),
),
patch.object(InventoryDao, 'get_pallets_by_ids', new=AsyncMock(return_value=[pallet])),
patch.object(
OperationDao,
'get_active_filling_for_update',
new=AsyncMock(return_value=origin_filling),
),
):
inventories, pallets, fillings = await ShipmentService._lock_and_validate_pallets(
self.db,
[2],
7,
)
self.assertEqual([inventory], inventories)
self.assertEqual([pallet], pallets)
self.assertEqual([origin_filling], fillings)
async def test_add_only_persists_pallet_ids_with_null_snapshots(self) -> None: # noqa: PLR0915
page = ShipmentCreateModel(sourceWarehouseId=7, targetSiteId=9, palletIds=[5, 2])
inventories = [make_inventory(2), make_inventory(5)]