feat: 输出报工归属摘要
This commit is contained in:
@@ -74,7 +74,8 @@ def _cleaning_device_nos(item: CleaningReportSubmitItem) -> list[str]:
|
||||
|
||||
def _report_query():
|
||||
return select(ProductionReport).options(
|
||||
selectinload(ProductionReport.items),
|
||||
selectinload(ProductionReport.allocations),
|
||||
selectinload(ProductionReport.items).selectinload(ProductionReportItem.allocations),
|
||||
selectinload(ProductionReport.audit_logs),
|
||||
selectinload(ProductionReport.employee),
|
||||
selectinload(ProductionReport.reviewer),
|
||||
|
||||
@@ -117,7 +117,8 @@ def _validate_normal_report_devices(db: Session, report: ProductionReport) -> No
|
||||
|
||||
def _report_query():
|
||||
return select(ProductionReport).options(
|
||||
selectinload(ProductionReport.items),
|
||||
selectinload(ProductionReport.allocations),
|
||||
selectinload(ProductionReport.items).selectinload(ProductionReportItem.allocations),
|
||||
selectinload(ProductionReport.audit_logs),
|
||||
selectinload(ProductionReport.employee),
|
||||
selectinload(ProductionReport.reviewer),
|
||||
|
||||
@@ -453,6 +453,19 @@ class ReportMetrics(BaseModel):
|
||||
workload_rate: float
|
||||
|
||||
|
||||
class ReportAllocationOut(BaseModel):
|
||||
allocation_date: date
|
||||
day_minutes: float = 0
|
||||
overtime_minutes: float = 0
|
||||
night_minutes: float = 0
|
||||
effective_minutes: float = 0
|
||||
good_qty: float = 0
|
||||
defect_qty: float = 0
|
||||
scrap_qty: float = 0
|
||||
changeover_count: float = 0
|
||||
reference_wage: float = 0
|
||||
|
||||
|
||||
class ReportItemOut(BaseModel):
|
||||
id: int | None = None
|
||||
attendance_point_name: str = ""
|
||||
@@ -478,6 +491,7 @@ class ReportItemOut(BaseModel):
|
||||
is_continuous_die: bool = False
|
||||
is_multi_person: bool = False
|
||||
remark: str | None = None
|
||||
allocations: list[ReportAllocationOut] = Field(default_factory=list)
|
||||
corrections: dict[str, Any] = Field(default_factory=dict)
|
||||
|
||||
|
||||
@@ -531,6 +545,7 @@ class ReportOut(BaseModel):
|
||||
items: list[ReportItemOut]
|
||||
metrics: ReportMetrics
|
||||
result_text: str
|
||||
allocation_summary_text: str = ""
|
||||
corrections: dict[str, Any] = Field(default_factory=dict)
|
||||
|
||||
|
||||
@@ -587,6 +602,8 @@ class DashboardRow(BaseModel):
|
||||
id: str
|
||||
attendance_point_name: str = ""
|
||||
report_date: date
|
||||
source_report_date: date | None = None
|
||||
source_report_dates: list[date] = Field(default_factory=list)
|
||||
employee_phone: str
|
||||
employee_name: str
|
||||
project_no: str
|
||||
|
||||
@@ -23,6 +23,7 @@ from app.schemas import (
|
||||
PersonnelOut,
|
||||
ProductOption,
|
||||
ProductOut,
|
||||
ReportAllocationOut,
|
||||
ReportDeviceSegmentOut,
|
||||
ReportItemOut,
|
||||
ReportMetrics,
|
||||
@@ -36,6 +37,7 @@ from app.services.metrics import build_result_text, calculate_report_metrics
|
||||
from app.services.misc_work import is_misc_item, is_misc_product
|
||||
from app.services.multi_person import is_multi_person_item, is_multi_person_product
|
||||
from app.services.process_names import export_process_name
|
||||
from app.services.report_allocations import allocation_summary_text
|
||||
from app.services.report_lifecycle import can_edit_report, can_unvoid_report
|
||||
from app.services.work_schedule import WorkScheduleConfig
|
||||
from app.timezone import now
|
||||
@@ -341,6 +343,21 @@ def report_device_segment_out(
|
||||
)
|
||||
|
||||
|
||||
def report_allocation_out(row) -> ReportAllocationOut:
|
||||
return ReportAllocationOut(
|
||||
allocation_date=row.allocation_date,
|
||||
day_minutes=as_float(row.day_minutes),
|
||||
overtime_minutes=as_float(row.overtime_minutes),
|
||||
night_minutes=as_float(row.night_minutes),
|
||||
effective_minutes=as_float(row.effective_minutes),
|
||||
good_qty=as_float(row.good_qty),
|
||||
defect_qty=as_float(row.defect_qty),
|
||||
scrap_qty=as_float(row.scrap_qty),
|
||||
changeover_count=as_float(row.changeover_count),
|
||||
reference_wage=as_float(row.reference_wage),
|
||||
)
|
||||
|
||||
|
||||
def report_item_out(item: ProductionReportItem, corrections: dict | None = None) -> ReportItemOut:
|
||||
return ReportItemOut(
|
||||
id=item.id,
|
||||
@@ -367,6 +384,7 @@ def report_item_out(item: ProductionReportItem, corrections: dict | None = None)
|
||||
is_continuous_die=is_continuous_die_item(item),
|
||||
is_multi_person=is_multi_person_item(item),
|
||||
remark=item.remark,
|
||||
allocations=[report_allocation_out(row) for row in getattr(item, "allocations", []) or []],
|
||||
corrections=corrections or {},
|
||||
)
|
||||
|
||||
@@ -486,5 +504,6 @@ def report_out(report: ProductionReport, schedule: WorkScheduleConfig | None = N
|
||||
if is_cleaning_report
|
||||
else ("处理杂活已提交,等待管理员审核" if _report_is_misc_only(report) else build_result_text(metrics))
|
||||
),
|
||||
allocation_summary_text=allocation_summary_text(list(getattr(report, "allocations", []) or [])),
|
||||
corrections=report_corrections,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user