fix: 修正归属工时舍入残差

This commit is contained in:
souplearn
2026-07-25 03:54:00 +08:00
parent 72acc16a09
commit 2084f834e3
2 changed files with 78 additions and 0 deletions
+21
View File
@@ -154,6 +154,27 @@ def test_no_device_shared_full_report_splits_effective_minutes_between_items():
]
def test_short_shared_report_rounding_residual_keeps_aggregate_night_total():
start_at = datetime(2026, 5, 3, 1, 4, 50)
end_at = datetime(2026, 5, 3, 1, 4, 53)
first_item = _item(id=1, good_qty=1)
second_item = _item(id=2, good_qty=1)
report = _report(start_at, end_at, [first_item, second_item])
metrics = calculate_report_metrics(start_at, end_at, [first_item, second_item])
rows = build_report_allocation_drafts(report)
assert metrics["effective_minutes"] == 0.05
assert metrics["shift_night_minutes"] == 0.05
assert [row.allocation_date for row in rows] == [date(2026, 5, 2), date(2026, 5, 2)]
assert [row.effective_minutes for row in rows] == [0.03, 0.02]
assert round(sum(row.effective_minutes for row in rows), 2) == 0.05
assert round(sum(row.night_minutes for row in rows), 2) == 0.05
assert round(sum(row.day_minutes for row in rows), 2) == 0
assert round(sum(row.overtime_minutes for row in rows), 2) == 0
assert all(row.effective_minutes == round(row.day_minutes + row.overtime_minutes + row.night_minutes, 2) for row in rows)
def test_items_sharing_same_started_at_split_the_segment_minutes():
started_at = datetime(2026, 7, 25, 8, 0)
first_item = _item(id=1, good_qty=10, started_at=started_at)