fix: 加强使用统计归属查询一致性
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user