This commit is contained in:
zlwu committed 2026-07-20 10:50:26 +08:00
1 parent 6d9354a194
commit aff71d296b
2759 files changed
+860425 -13211

No files matched your search

+52
View File
@@ -1049,6 +1049,55 @@ def transport_has_locked_freight_settlement(
)
def sync_archive_qty_from_io_order(
db: Session,
*,
tenant_no: str,
plan: PlPlan,
items: list[PlanArchiveProductItem],
) -> list[PlanArchiveProductItem]:
"""若存在入库/出库单,用明细 actual_qty 覆盖归档提交中的实际数量(权威来源)。"""
from app.models.pl_models import PlInboundOrder, PlInboundOrderItem, PlOutboundOrder, PlOutboundOrderItem
if plan.plan_type not in ("inbound", "outbound"):
return items
header_m = PlInboundOrder if plan.plan_type == "inbound" else PlOutboundOrder
item_m = PlInboundOrderItem if plan.plan_type == "inbound" else PlOutboundOrderItem
header = (
db.query(header_m)
.filter(
header_m.tenant_no == tenant_no,
header_m.plan_id == plan.id,
header_m.status != "voided",
header_m.del_flag == 0,
)
.order_by(header_m.create_time.desc())
.first()
)
if not header:
return items
io_items = (
db.query(item_m)
.filter(item_m.order_id == header.id, item_m.del_flag == 0)
.all()
)
qty_by_plan_product = {
row.plan_product_id: Decimal(str(row.actual_qty))
for row in io_items
if row.actual_qty is not None
}
if not qty_by_plan_product:
return items
out: list[PlanArchiveProductItem] = []
for item in items:
qty = qty_by_plan_product.get(item.id)
if qty is not None:
out.append(PlanArchiveProductItem(id=item.id, actual_qty=qty))
else:
out.append(item)
return out
def apply_archive_product_quantities(
db: Session,
*,
@@ -1056,7 +1105,10 @@ def apply_archive_product_quantities(
plan: PlPlan,
items: list[PlanArchiveProductItem],
user_id: str,
sync_from_io_order: bool = True,
) -> None:
if sync_from_io_order:
items = sync_archive_qty_from_io_order(db, tenant_no=tenant_no, plan=plan, items=items)
product_map = {
row.id: row
for row in db.query(PlPlanProduct).filter(