From 3f62af430fa0ab59653b229364a54ee361999739 Mon Sep 17 00:00:00 2001 From: wuzilong <704541015@qq.com> Date: Wed, 18 Nov 2026 13:50:41 +0800 Subject: [PATCH] =?UTF-8?q?fix(pl):=20=E5=90=8C=E5=B8=82=E4=B8=8E=E5=BC=82?= =?UTF-8?q?=E5=9C=B0=E6=B7=B7=E8=B7=91=E6=97=B6=E7=BB=93=E8=BD=AC=E5=8F=AA?= =?UTF-8?q?=E8=A6=81=E6=B1=82=E6=9C=AC=E7=BB=84=E6=9D=A5=E6=BA=90=E6=9C=89?= =?UTF-8?q?=E5=AE=9E=E8=BF=90=E9=87=8F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 运输证分组只有部分来源时,忽略实际量里多出来的来源,不再整单报缺实际量。 Co-authored-by: Cursor --- backend/app/services/pl_quota_allocation.py | 4 +++- backend/tests/test_pl_quota_allocation.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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