fix: 保留未填报设备段归属工时
This commit is contained in:
@@ -184,6 +184,25 @@ def _item_bucket_totals(minutes_by_item: dict[int, dict[date, dict[str, float]]]
|
||||
return totals
|
||||
|
||||
|
||||
def _allocate_unassigned_minutes_to_existing_items(
|
||||
minutes_by_item: dict[int, dict[date, dict[str, float]]],
|
||||
unassigned_minutes: dict[date, dict[str, float]],
|
||||
) -> None:
|
||||
unassigned_total = _minutes_total(unassigned_minutes)
|
||||
if unassigned_total <= 0 or not minutes_by_item:
|
||||
return
|
||||
|
||||
raw_item_totals = {
|
||||
item_id: _minutes_total(rows_by_date)
|
||||
for item_id, rows_by_date in minutes_by_item.items()
|
||||
}
|
||||
raw_total = sum(raw_item_totals.values())
|
||||
item_count = len(minutes_by_item)
|
||||
for item_id, rows_by_date in minutes_by_item.items():
|
||||
weight = raw_item_totals[item_id] / raw_total if raw_total > 0 else 1 / item_count
|
||||
_add_date_bucket_minutes(rows_by_date, unassigned_minutes, scale=weight)
|
||||
|
||||
|
||||
def _scale_item_minutes_to_bucket_targets(
|
||||
minutes_by_item: dict[int, dict[date, dict[str, float]]],
|
||||
target_buckets: dict[str, float],
|
||||
@@ -352,6 +371,7 @@ def _device_minutes_by_item(report, items: list, schedule: WorkScheduleConfig |
|
||||
row[key] += minutes.get(key, 0.0) * (remaining / raw_unassigned) / len(unmatched_items)
|
||||
return minutes_by_item
|
||||
|
||||
_allocate_unassigned_minutes_to_existing_items(minutes_by_item, unassigned_minutes)
|
||||
_scale_item_minutes_to_bucket_targets(minutes_by_item, _bucket_totals(target_minutes))
|
||||
return minutes_by_item
|
||||
|
||||
@@ -468,6 +488,7 @@ def refresh_report_allocations(
|
||||
*,
|
||||
commit: bool = False,
|
||||
) -> list[ProductionReportAllocation]:
|
||||
"""Rebuild allocation rows with metrics semantics, updating item allocation-derived fields."""
|
||||
db.execute(delete(ProductionReportAllocation).where(ProductionReportAllocation.report_id == getattr(report, "id")))
|
||||
rows = [
|
||||
ProductionReportAllocation(
|
||||
|
||||
Reference in New Issue
Block a user