fix: 修正共享报工段工时归属拆分
This commit is contained in:
+17
-3
@@ -35,6 +35,7 @@ class ItemTimeRange:
|
||||
item: ReportItemLike
|
||||
start_at: datetime
|
||||
end_at: datetime
|
||||
allocation_weight: float = 1.0
|
||||
|
||||
|
||||
SHIFT_BUCKETS = ("day", "overtime", "night")
|
||||
@@ -419,8 +420,17 @@ def _device_item_time_ranges(
|
||||
item_end = segment_end
|
||||
if index + 1 < len(ordered_starts):
|
||||
item_end = ordered_starts[index + 1]
|
||||
for item in grouped_items[item_start]:
|
||||
ranges.append(ItemTimeRange(item=item, start_at=item_start, end_at=item_end))
|
||||
items_at_start = grouped_items[item_start]
|
||||
allocation_weight = 1 / len(items_at_start)
|
||||
for item in items_at_start:
|
||||
ranges.append(
|
||||
ItemTimeRange(
|
||||
item=item,
|
||||
start_at=item_start,
|
||||
end_at=item_end,
|
||||
allocation_weight=allocation_weight,
|
||||
)
|
||||
)
|
||||
return ranges
|
||||
|
||||
|
||||
@@ -435,7 +445,11 @@ def item_time_ranges(
|
||||
|
||||
segment_ranges = _device_segment_ranges(start_at, end_at, devices)
|
||||
if not segment_ranges:
|
||||
return [ItemTimeRange(item=item, start_at=start_at, end_at=end_at) for item in items]
|
||||
allocation_weight = 1 / len(items)
|
||||
return [
|
||||
ItemTimeRange(item=item, start_at=start_at, end_at=end_at, allocation_weight=allocation_weight)
|
||||
for item in items
|
||||
]
|
||||
|
||||
items_by_device: dict[str, list[ReportItemLike]] = defaultdict(list)
|
||||
for item in items:
|
||||
|
||||
@@ -188,7 +188,9 @@ def build_report_allocation_drafts(report, schedule: WorkScheduleConfig | None =
|
||||
target = minutes_by_item.setdefault(item_key, defaultdict(lambda: {key: 0.0 for key in SHIFT_BUCKETS}))
|
||||
for allocation_date, minutes in _range_allocation_minutes(item_range.start_at, item_range.end_at, schedule).items():
|
||||
for key in SHIFT_BUCKETS:
|
||||
target[allocation_date][key] += minutes.get(key, 0.0)
|
||||
target[allocation_date][key] += minutes.get(key, 0.0) * as_float(
|
||||
getattr(item_range, "allocation_weight", 1.0)
|
||||
)
|
||||
|
||||
rows: list[ReportAllocationDraft] = []
|
||||
for item in items:
|
||||
|
||||
Reference in New Issue
Block a user