fix: 加强使用统计归属查询一致性

This commit is contained in:
souplearn
2026-07-25 05:38:14 +08:00
parent 37f2b2dcb2
commit 1dc6372956
2 changed files with 176 additions and 4 deletions
+12 -3
View File
@@ -2,7 +2,7 @@ from datetime import date
from math import ceil
from fastapi import APIRouter, Depends, HTTPException, Query, Response, status
from sqlalchemy import select
from sqlalchemy import and_, select
from sqlalchemy.orm import Session, selectinload
from app.database import get_db
@@ -12,6 +12,7 @@ from app.models import (
Personnel,
ProductionReport,
ProductionReportAllocation,
ProductionReportItem,
ReportStatus,
Role,
)
@@ -61,8 +62,14 @@ def _approved_allocations_query(
):
query = (
select(ProductionReportAllocation)
.join(ProductionReportAllocation.report)
.join(ProductionReportAllocation.item)
.join(ProductionReport, ProductionReport.id == ProductionReportAllocation.report_id)
.join(
ProductionReportItem,
and_(
ProductionReportItem.id == ProductionReportAllocation.report_item_id,
ProductionReportItem.report_id == ProductionReportAllocation.report_id,
),
)
.options(
selectinload(ProductionReportAllocation.report).selectinload(ProductionReport.employee),
selectinload(ProductionReportAllocation.item),
@@ -71,6 +78,8 @@ def _approved_allocations_query(
ProductionReport.status == ReportStatus.approved,
ProductionReport.is_voided.is_(False),
ProductionReport.attendance_point_name.in_(point_names),
ProductionReportAllocation.attendance_point_name.in_(point_names),
ProductionReportItem.attendance_point_name.in_(point_names),
)
)
if start_date: