diff --git a/backend/app/services/pl_quota_allocation.py b/backend/app/services/pl_quota_allocation.py index fa3f0c26d..5f87551cd 100644 --- a/backend/app/services/pl_quota_allocation.py +++ b/backend/app/services/pl_quota_allocation.py @@ -339,6 +339,8 @@ def settle_allocations(reserved: Sequence[Allocation], actual_by_source: Mapping 超来源量或超任一证件预占量均要求先补充分配。 同市等仅购买证场景下,调用方仍可能对本函数传入空的运输证分组与全量实运量; 无预占行时直接空结转,不把「缺实际量」套到另一类证件上。 + 同市装货 + 异地卸货混跑时,运输证分组往往只有卸货来源,而 actual 含全部来源; + 只要求本组预占来源都有实运量,多出来源忽略。 """ if not reserved: return () @@ -357,7 +359,7 @@ def settle_allocations(reserved: Sequence[Allocation], actual_by_source: Mapping keys.add(key) seqs.add(seq) grouped.setdefault(row.source_id, []).append(row) - if set(actual_by_source) != set(grouped): + if not set(grouped) <= set(actual_by_source): raise AllocationInputError('必须明确提交每个来源的实际量') manual = {} for row in manual_actuals: diff --git a/backend/tests/test_pl_quota_allocation.py b/backend/tests/test_pl_quota_allocation.py index e7703847e..7ae5ba116 100644 --- a/backend/tests/test_pl_quota_allocation.py +++ b/backend/tests/test_pl_quota_allocation.py @@ -254,6 +254,22 @@ def test_empty_transport_kind_settle_ignores_source_actuals(): assert settle_allocations([], {'city': D(10)}) == () +def test_partial_transport_settle_ignores_sources_without_reservation(): + """同市装货无运输预占、异地卸货有运输预占时,运输结转不得因多出来源实运量报缺实际量。""" + from app.services.pl_quota_allocation import Allocation + + transport_rows = [ + Allocation('transport', 'delivery:sp', 't1', D(33), D(33), 'dun', 'dun', 1), + ] + actuals = {'load:sp': D(33), 'delivery:sp': D(33)} + settled = settle_allocations(transport_rows, actuals) + assert len(settled) == 1 + assert settled[0].actual_source_quantity == D(33) + + with pytest.raises(AllocationInputError, match='实际量'): + settle_allocations(transport_rows, {'load:sp': D(33)}) + + @pytest.mark.parametrize('manual_values', [(8,10,0),(18,0,0)]) def test_zero_capacity_foreign_row_cannot_unlock_manual_reordering(manual_values): from app.services.pl_quota_allocation import Allocation