fix: 审核未修正时保留超额提交快照
This commit is contained in:
+23
-4
@@ -116,6 +116,14 @@ def _validate_normal_report_devices(db: Session, report: ProductionReport) -> No
|
||||
raise HTTPException(status_code=400, detail=f"设备 {device_no} 不是该考勤点的冲压设备")
|
||||
|
||||
|
||||
def _missing_over_limit_snapshot(report: ProductionReport) -> bool:
|
||||
return any(
|
||||
item.over_limit_checked_at is None and not item.over_limit_check_source
|
||||
for item in report.items
|
||||
if not is_cleaning_item(item)
|
||||
)
|
||||
|
||||
|
||||
def _report_query():
|
||||
return select(ProductionReport).options(
|
||||
selectinload(ProductionReport.allocations),
|
||||
@@ -398,6 +406,7 @@ def approve_report(
|
||||
schedule = get_work_schedule_config(db, report.attendance_point_name)
|
||||
item_map = {item.id: item for item in report.items}
|
||||
has_correction = False
|
||||
over_limit_input_changed = False
|
||||
|
||||
next_start_at = _effective_review_time(payload.start_at, report.start_at)
|
||||
next_end_at = _effective_review_time(payload.end_at, report.end_at)
|
||||
@@ -443,11 +452,14 @@ def approve_report(
|
||||
if correction.raw_material_batch_no is not None
|
||||
else item.raw_material_batch_no
|
||||
)
|
||||
if (
|
||||
next_device_no != item.device_no
|
||||
or next_project_no != item.project_no
|
||||
product_identity_changed = (
|
||||
next_project_no != item.project_no
|
||||
or next_product_name != item.product_name
|
||||
or next_process_name != item.process_name
|
||||
)
|
||||
if (
|
||||
next_device_no != item.device_no
|
||||
or product_identity_changed
|
||||
):
|
||||
product = db.scalar(
|
||||
select(Product).where(
|
||||
@@ -481,10 +493,13 @@ def approve_report(
|
||||
item.standard_beat = as_float(product.standard_beat)
|
||||
item.standard_workload = 0
|
||||
has_correction = True
|
||||
if product_identity_changed:
|
||||
over_limit_input_changed = True
|
||||
|
||||
if next_raw_material_batch_no != item.raw_material_batch_no:
|
||||
item.raw_material_batch_no = next_raw_material_batch_no
|
||||
has_correction = True
|
||||
over_limit_input_changed = True
|
||||
|
||||
if correction.changeover_count is not None:
|
||||
next_changeover_count = as_float(correction.changeover_count)
|
||||
@@ -499,12 +514,15 @@ def approve_report(
|
||||
if correction.good_qty is not None and as_float(correction.good_qty) != as_float(item.good_qty):
|
||||
item.good_qty = correction.good_qty
|
||||
has_correction = True
|
||||
over_limit_input_changed = True
|
||||
if correction.defect_qty is not None and as_float(correction.defect_qty) != as_float(item.defect_qty):
|
||||
item.defect_qty = correction.defect_qty
|
||||
has_correction = True
|
||||
over_limit_input_changed = True
|
||||
if correction.scrap_qty is not None and as_float(correction.scrap_qty) != as_float(item.scrap_qty):
|
||||
item.scrap_qty = correction.scrap_qty
|
||||
has_correction = True
|
||||
over_limit_input_changed = True
|
||||
if item_is_misc and correction.remark is not None:
|
||||
next_remark = str(correction.remark or "").strip() or None
|
||||
if next_remark != item.remark:
|
||||
@@ -533,7 +551,8 @@ def approve_report(
|
||||
_apply_metrics(report, schedule)
|
||||
refresh_report_allocations(db, report, schedule=schedule, commit=False)
|
||||
reviewed_at = now()
|
||||
refresh_report_over_limit_snapshot(db, report, source=CHECK_SOURCE_REVIEW, checked_at=reviewed_at)
|
||||
if not is_cleaning and (over_limit_input_changed or _missing_over_limit_snapshot(report)):
|
||||
refresh_report_over_limit_snapshot(db, report, source=CHECK_SOURCE_REVIEW, checked_at=reviewed_at)
|
||||
was_pending = report.status == ReportStatus.pending
|
||||
report.status = ReportStatus.approved
|
||||
report.reviewer_phone = user.phone
|
||||
|
||||
Reference in New Issue
Block a user