feat: 输出报工归属摘要

This commit is contained in:
souplearn
2026-07-25 04:29:02 +08:00
parent ebb490590f
commit b0cb217ce3
5 changed files with 168 additions and 2 deletions
+128
View File
@@ -1,4 +1,5 @@
from datetime import date, datetime
from decimal import Decimal
from types import SimpleNamespace
from sqlalchemy import BigInteger, create_engine, select
@@ -9,6 +10,7 @@ from app.database import Base
from app.models import (
AttendancePoint,
Equipment,
Personnel,
Product,
ProductionReport,
ProductionReportAllocation,
@@ -38,6 +40,7 @@ from app.services.report_allocations import (
build_report_allocation_drafts,
refresh_report_allocations,
)
from app.services.serializers import report_out
from app.services.work_schedule import WorkScheduleConfig
@@ -453,6 +456,131 @@ def test_allocation_summary_text_groups_dates_and_shift_kinds():
assert allocation_summary_text(rows) == "2026-07-24 夜班5.83小时;2026-07-25 白班3小时、加班2小时"
def test_report_out_exposes_allocation_summary_and_item_allocations():
report = ProductionReport(
id=1,
session_id=1,
attendance_point_name="总厂",
employee_phone="13800000000",
report_date=date(2026, 7, 25),
start_at=datetime(2026, 7, 25, 8, 0),
end_at=datetime(2026, 7, 25, 18, 30),
break_minutes=60,
status=ReportStatus.pending,
submitted_at=datetime(2026, 7, 25, 18, 31),
)
report.employee = Personnel(phone="13800000000", name="张三")
report.session = WorkSession(
id=1,
employee_phone="13800000000",
attendance_point_name="总厂",
start_at=datetime(2026, 7, 25, 8, 0),
status=SessionStatus.submitted,
)
report.session.devices = []
item = ProductionReportItem(
id=1,
report_id=1,
attendance_point_name="总厂",
device_no="23#",
project_no="P1",
product_name="23#",
process_name="冲压",
process_unit_price_yuan=Decimal("2.50"),
good_qty=Decimal("100.50"),
defect_qty=Decimal("2.25"),
scrap_qty=Decimal("1.25"),
changeover_count=Decimal("1.50"),
standard_beat=Decimal("3.00"),
standard_workload=Decimal("0.00"),
)
allocation = ProductionReportAllocation(
id=1,
report_id=1,
report_item_id=1,
attendance_point_name="总厂",
employee_phone="13800000000",
allocation_date=date(2026, 7, 25),
day_minutes=Decimal("120.50"),
overtime_minutes=Decimal("30.25"),
night_minutes=Decimal("0.00"),
effective_minutes=Decimal("150.75"),
good_qty=Decimal("100.50"),
defect_qty=Decimal("2.25"),
scrap_qty=Decimal("1.25"),
changeover_count=Decimal("1.50"),
reference_wage=Decimal("251.25"),
)
item.allocations = [allocation]
report.items = [item]
report.allocations = [allocation]
report.audit_logs = []
output = report_out(report)
assert output.allocation_summary_text == "2026-07-25 白班2.01小时、加班0.5小时"
assert len(output.items[0].allocations) == 1
item_allocation = output.items[0].allocations[0]
assert item_allocation.allocation_date == date(2026, 7, 25)
assert item_allocation.day_minutes == 120.5
assert item_allocation.overtime_minutes == 30.25
assert item_allocation.effective_minutes == 150.75
assert item_allocation.good_qty == 100.5
assert item_allocation.defect_qty == 2.25
assert item_allocation.scrap_qty == 1.25
assert item_allocation.changeover_count == 1.5
assert item_allocation.reference_wage == 251.25
def test_report_out_handles_empty_allocations():
report = ProductionReport(
id=1,
session_id=1,
attendance_point_name="总厂",
employee_phone="13800000000",
report_date=date(2026, 7, 25),
start_at=datetime(2026, 7, 25, 8, 0),
end_at=datetime(2026, 7, 25, 9, 0),
break_minutes=0,
status=ReportStatus.pending,
submitted_at=datetime(2026, 7, 25, 9, 1),
)
report.employee = Personnel(phone="13800000000", name="张三")
report.session = WorkSession(
id=1,
employee_phone="13800000000",
attendance_point_name="总厂",
start_at=datetime(2026, 7, 25, 8, 0),
status=SessionStatus.submitted,
)
report.session.devices = []
item = ProductionReportItem(
id=1,
report_id=1,
attendance_point_name="总厂",
device_no="23#",
project_no="P1",
product_name="23#",
process_name="冲压",
process_unit_price_yuan=0,
good_qty=0,
defect_qty=0,
scrap_qty=0,
changeover_count=0,
standard_beat=1,
standard_workload=0,
)
item.allocations = []
report.items = [item]
report.allocations = []
report.audit_logs = []
output = report_out(report)
assert output.allocation_summary_text == ""
assert output.items[0].allocations == []
def test_refresh_report_allocations_replaces_existing_rows_and_flushes():
engine = create_engine("sqlite+pysqlite:///:memory:", future=True)
Base.metadata.create_all(engine)