fix: 加强对账归属查询一致性

This commit is contained in:
souplearn
2026-07-25 05:16:59 +08:00
parent 2de4b9009a
commit 9674554b98
2 changed files with 216 additions and 2 deletions
+8 -2
View File
@@ -1,7 +1,7 @@
from datetime import date
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy import extract, func, select
from sqlalchemy import and_, extract, func, select
from sqlalchemy.orm import Session
from app.database import get_db
@@ -101,7 +101,13 @@ def _reported_good_quantities(
func.sum(ProductionReportAllocation.good_qty).label("good_qty"),
)
.select_from(ProductionReportAllocation)
.join(ProductionReportItem, ProductionReportItem.id == ProductionReportAllocation.report_item_id)
.join(
ProductionReportItem,
and_(
ProductionReportItem.id == ProductionReportAllocation.report_item_id,
ProductionReportItem.report_id == ProductionReportAllocation.report_id,
),
)
.join(ProductionReport, ProductionReport.id == ProductionReportAllocation.report_id)
.where(
ProductionReport.status == ReportStatus.approved,