fix: 审核未修正时保留超额提交快照
This commit is contained in:
@@ -813,6 +813,85 @@ def test_approve_report_refreshes_over_limit_snapshot_after_correction(monkeypat
|
||||
db.close()
|
||||
|
||||
|
||||
def test_approve_report_without_over_limit_input_changes_preserves_submit_snapshot(monkeypatch):
|
||||
db = _sqlite_db()
|
||||
try:
|
||||
user = SimpleNamespace(phone="13900000000", role=Role.admin)
|
||||
session = _numeric_session(status=SessionStatus.submitted)
|
||||
report = ProductionReport(
|
||||
attendance_point_name="总厂",
|
||||
session=session,
|
||||
employee_phone="13800000000",
|
||||
report_date=date(2026, 7, 25),
|
||||
start_at=session.start_at,
|
||||
end_at=session.end_at,
|
||||
duration_minutes=120,
|
||||
effective_minutes=120,
|
||||
total_good_qty=60,
|
||||
total_output_qty=60,
|
||||
actual_beat=120,
|
||||
standard_beat=1,
|
||||
expected_workload=0,
|
||||
pace_rate=0,
|
||||
workload_rate=0,
|
||||
status=ReportStatus.pending,
|
||||
submitted_at=session.end_at,
|
||||
has_over_limit=True,
|
||||
over_limit_summary="1项超额",
|
||||
items=[
|
||||
ProductionReportItem(
|
||||
attendance_point_name="总厂",
|
||||
device_no="E1",
|
||||
project_no="P1",
|
||||
product_name="产品A",
|
||||
raw_material_batch_no="LOT-1",
|
||||
process_name="1",
|
||||
standard_beat=1,
|
||||
standard_workload=0,
|
||||
good_qty=60,
|
||||
defect_qty=0,
|
||||
scrap_qty=0,
|
||||
over_limit_status=OVER_LIMIT_STATUS_EXCEEDED,
|
||||
over_limit_type="first_process_material",
|
||||
over_limit_reason="提交时已超额",
|
||||
over_limit_checked_at=datetime(2026, 7, 25, 10),
|
||||
over_limit_check_source="submit",
|
||||
over_limit_batch_no="LOT-1",
|
||||
over_limit_product_gross_weight_kg=Decimal("2.0000"),
|
||||
over_limit_issued_weight_kg=Decimal("100.000000"),
|
||||
over_limit_max_reportable_qty=Decimal("50.00"),
|
||||
over_limit_current_cumulative_qty=Decimal("60.00"),
|
||||
over_limit_current_report_qty=Decimal("60.00"),
|
||||
)
|
||||
],
|
||||
)
|
||||
db.add_all([_press_equipment(), _numeric_product(), report])
|
||||
db.commit()
|
||||
monkeypatch.setattr(reviews_router, "accessible_point_names", lambda _db, _user: ["总厂"])
|
||||
monkeypatch.setattr(reviews_router, "report_out", lambda report, schedule=None: report)
|
||||
monkeypatch.setattr(
|
||||
"app.services.report_over_limit.read_batch_issued_weight_kg",
|
||||
lambda db, batch_no, project_no, product_name: Decimal("200"),
|
||||
)
|
||||
|
||||
saved = reviews_router.approve_report(
|
||||
report.id,
|
||||
ApproveReportRequest(),
|
||||
user=user,
|
||||
db=db,
|
||||
)
|
||||
|
||||
assert saved.has_over_limit is True
|
||||
assert saved.over_limit_summary == "1项超额"
|
||||
assert saved.items[0].over_limit_status == OVER_LIMIT_STATUS_EXCEEDED
|
||||
assert saved.items[0].over_limit_check_source == "submit"
|
||||
assert saved.items[0].over_limit_reason == "提交时已超额"
|
||||
assert saved.items[0].over_limit_issued_weight_kg == Decimal("100.000000")
|
||||
assert saved.items[0].over_limit_max_reportable_qty == Decimal("50.00")
|
||||
finally:
|
||||
db.close()
|
||||
|
||||
|
||||
def test_report_out_exposes_over_limit_snapshot_fields():
|
||||
report = ProductionReport(
|
||||
id=1,
|
||||
|
||||
Reference in New Issue
Block a user