fix: 按指标结果校准归属工时

This commit is contained in:
souplearn
2026-07-25 03:41:54 +08:00
parent 891c10ddea
commit 1a8871d3b4
2 changed files with 65 additions and 0 deletions
+36
View File
@@ -297,6 +297,42 @@ def test_matched_meal_split_and_unmatched_device_range_follow_metrics_order():
assert round(sum(row.effective_minutes for row in rows), 2) == metrics["effective_minutes"]
def test_item_totals_anchor_to_metrics_when_unmatched_remaining_buckets_exceed_item_target():
start_at = datetime(2026, 7, 25, 8, 0)
second_started_at = datetime(2026, 7, 25, 12, 0)
switch_at = datetime(2026, 7, 25, 18, 0)
end_at = datetime(2026, 7, 25, 20, 0)
devices = [
_device(start_at, device_no="23#", sort_order=0),
_device(switch_at, device_no="77#", sort_order=1),
]
first_item = _item(id=1, good_qty=240, device_no="23#", started_at=start_at)
second_item = _item(id=2, good_qty=360, device_no="23#", started_at=second_started_at)
unmatched_item = _item(id=3, good_qty=60, device_no="99#")
items = [first_item, second_item, unmatched_item]
report = _report(start_at, end_at, items, devices=devices)
metrics = calculate_report_metrics(start_at, end_at, items, devices=devices)
rows = build_report_allocation_drafts(report)
assert metrics["effective_minutes"] == 660
assert {item.id: item.allocated_minutes for item in items} == {
1: 240,
2: 360,
3: 60,
}
assert {
item_id: round(sum(row.effective_minutes for row in rows if row.report_item_id == item_id), 2)
for item_id in [1, 2, 3]
} == {
1: 240,
2: 360,
3: 60,
}
assert round(sum(row.effective_minutes for row in rows), 2) == 660
assert all(row.effective_minutes == row.day_minutes + row.overtime_minutes + row.night_minutes for row in rows)
def test_zero_effective_minutes_falls_back_to_original_report_date():
item = _item(good_qty=5, defect_qty=1, scrap_qty=0.5, changeover_count=2, process_unit_price_yuan=3)
report = _report(