功能:实现空托盘首次入库

This commit is contained in:
焦龙言
2026-07-26 15:19:25 +08:00
parent 317a0fbf68
commit 6f22cf0282
5 changed files with 2106 additions and 10 deletions
@@ -1,7 +1,7 @@
from datetime import datetime, time, timedelta
from typing import Any
from sqlalchemy import ColumnElement, Select, delete, select, update
from sqlalchemy import ColumnElement, Select, delete, false, select, update
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm.attributes import InstrumentedAttribute
@@ -186,12 +186,28 @@ class OperationDao:
db: AsyncSession,
inbound_id: int,
) -> BizInboundOrder | None:
return await cls._get_for_update(
inbound = await cls._get_for_update(
db,
BizInboundOrder,
BizInboundOrder.inbound_id,
inbound_id,
)
if inbound is None:
return None
# 父单锁定后用 locking read 获取最新明细,避免 MySQL RR 继续读取确认前的旧快照。
item_result = await db.execute(
select(BizInboundItem)
.where(BizInboundItem.inbound_id == inbound_id)
.order_by(BizInboundItem.pallet_id, BizInboundItem.inbound_item_id)
.with_for_update()
.execution_options(populate_existing=True)
)
inbound.items = sorted(
item_result.scalars().all(),
key=lambda item: (item.pallet_id, item.inbound_item_id),
)
return inbound
@classmethod
async def get_shipment_for_update(
@@ -318,8 +334,14 @@ class OperationDao:
db: AsyncSession,
query_object: InboundPageQueryModel,
is_page: bool = True,
warehouse_ids: list[int] | None = None,
) -> PageModel | list[dict[str, Any]]:
conditions = []
if warehouse_ids is not None:
scoped_warehouse_ids = sorted(set(warehouse_ids))
conditions.append(
BizInboundOrder.warehouse_id.in_(scoped_warehouse_ids) if scoped_warehouse_ids else false()
)
if query_object.inbound_no:
conditions.append(BizInboundOrder.inbound_no.like(f'%{query_object.inbound_no}%'))
if query_object.warehouse_id: