fix(pl): 未安排计划按生效时间走新规则选证。
安排预检不再把空版本当成 legacy 去查合同绑证,与证书齐备待完善判定一致。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
e9f3602459
commit
8ac835fa96
3 files changed
+175
-11
No files matched your search
@@ -1373,3 +1373,150 @@ def test_build_usage_request_passes_saved_manuals_to_customer_select(monkeypatch
|
||||
assert captured['manual_allocations'][0].permit_id == 'buy1'
|
||||
assert config.purchase_cert_ids == ['buy1']
|
||||
assert request.manual_allocations[0].permit_quantity == Decimal('2.5')
|
||||
|
||||
|
||||
def test_unarranged_plan_build_usage_uses_customer_rule_by_effective_at(monkeypatch):
|
||||
"""尚未安排且版本为空时,按生效时间走新规则自动选证,不查合同绑证。"""
|
||||
from app.services import pl_quota_planning as planning
|
||||
from app.schemas.pl.quota_planning import PlanQuotaOperation
|
||||
from app.schemas.pl.quota_usage import UsageSource
|
||||
|
||||
source = UsageSource(
|
||||
source_stop_type='delivery',
|
||||
source_stop_id='d1',
|
||||
source_stop_product_id='sp1',
|
||||
plan_product_id='pp1',
|
||||
contract_id='c1',
|
||||
contract_product_id='cp1',
|
||||
product_id='prod1',
|
||||
quantity=Decimal('33'),
|
||||
unit='dun',
|
||||
fingerprint='f' * 64,
|
||||
snapshot={'customerId': 'cust1'},
|
||||
requires_transport=True,
|
||||
)
|
||||
plan = SimpleNamespace(
|
||||
id='p1',
|
||||
plan_date=date(2026, 11, 14),
|
||||
license_plate='皖R48299',
|
||||
transport_status='pending',
|
||||
archive_status='unarchived',
|
||||
cert_quota_rule_version=None,
|
||||
cert_quota_arranged_at=None,
|
||||
cert_configuration={'measurementVersion': 'per_stop_v2'},
|
||||
tenant_no='t',
|
||||
)
|
||||
called = {'customer_select': 0, 'contract_bind': 0}
|
||||
|
||||
def fake_select(*args, **kwargs):
|
||||
called['customer_select'] += 1
|
||||
return ['buy1'], ['move1'], []
|
||||
|
||||
def fake_contract_bind(*args, **kwargs):
|
||||
called['contract_bind'] += 1
|
||||
raise AssertionError('未安排计划不应再走合同绑证')
|
||||
|
||||
monkeypatch.setattr(planning, '_plan', lambda *a, **k: plan)
|
||||
monkeypatch.setattr(planning, 'extract_sources', lambda *a, **k: ([source], {}))
|
||||
monkeypatch.setattr(planning, 'resolve_measurement_version', lambda *a, **k: 'per_stop_v2')
|
||||
monkeypatch.setattr(planning, 'plan_execution_lock_reason', lambda *a, **k: None)
|
||||
monkeypatch.setattr(
|
||||
'app.services.pl_cert_quota_rule_config_service.get_effective_at',
|
||||
lambda *a, **k: datetime(2026, 11, 15, 20, 0, 0),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.pl_quota_customer_select.select_whole_cover_certs',
|
||||
fake_select,
|
||||
)
|
||||
monkeypatch.setattr(planning, 'resolve_contract_bound_certs', fake_contract_bind)
|
||||
monkeypatch.setattr(
|
||||
planning,
|
||||
'_get_row',
|
||||
lambda *a, **k: SimpleNamespace(id='x', revision=1),
|
||||
)
|
||||
|
||||
request, config = planning.build_usage_request(
|
||||
MagicMock(),
|
||||
SimpleNamespace(id='u', tenant_no='t', dept_id=''),
|
||||
'p1',
|
||||
PlanQuotaOperation(operationId='arrange-check'),
|
||||
'reserve',
|
||||
check_conditions=False,
|
||||
)
|
||||
assert called['customer_select'] == 1
|
||||
assert called['contract_bind'] == 0
|
||||
assert config.purchase_cert_ids == ['buy1']
|
||||
assert config.transport_cert_ids == ['move1']
|
||||
assert request.purchase_cert_ids == ['buy1']
|
||||
|
||||
|
||||
def test_arranged_legacy_plan_build_usage_keeps_contract_bind(monkeypatch):
|
||||
"""已首次安排并打成 legacy 的计划,安排/改派预占仍走合同绑证。"""
|
||||
from app.services import pl_quota_planning as planning
|
||||
from app.schemas.pl.quota_planning import PlanQuotaOperation
|
||||
from app.schemas.pl.quota_usage import UsageSource
|
||||
|
||||
source = UsageSource(
|
||||
source_stop_type='delivery',
|
||||
source_stop_id='d1',
|
||||
source_stop_product_id='sp1',
|
||||
plan_product_id='pp1',
|
||||
contract_id='c1',
|
||||
contract_product_id='cp1',
|
||||
product_id='prod1',
|
||||
quantity=Decimal('33'),
|
||||
unit='dun',
|
||||
fingerprint='f' * 64,
|
||||
snapshot={'customerId': 'cust1'},
|
||||
requires_transport=True,
|
||||
)
|
||||
plan = SimpleNamespace(
|
||||
id='p1',
|
||||
plan_date=date(2026, 11, 14),
|
||||
license_plate='皖R48299',
|
||||
transport_status='arranged',
|
||||
archive_status='unarchived',
|
||||
cert_quota_rule_version='legacy',
|
||||
cert_quota_arranged_at=datetime(2026, 11, 14, 10, 0, 0),
|
||||
cert_configuration={'measurementVersion': 'per_stop_v2'},
|
||||
tenant_no='t',
|
||||
)
|
||||
called = {'customer_select': 0, 'contract_bind': 0}
|
||||
|
||||
def fake_select(*args, **kwargs):
|
||||
called['customer_select'] += 1
|
||||
return ['buy1'], ['move1'], []
|
||||
|
||||
def fake_contract_bind(*args, **kwargs):
|
||||
called['contract_bind'] += 1
|
||||
return ['buy1'], ['move1']
|
||||
|
||||
monkeypatch.setattr(planning, '_plan', lambda *a, **k: plan)
|
||||
monkeypatch.setattr(planning, 'extract_sources', lambda *a, **k: ([source], {}))
|
||||
monkeypatch.setattr(planning, 'resolve_measurement_version', lambda *a, **k: 'per_stop_v2')
|
||||
monkeypatch.setattr(planning, 'plan_execution_lock_reason', lambda *a, **k: None)
|
||||
monkeypatch.setattr(
|
||||
'app.services.pl_cert_quota_rule_config_service.get_effective_at',
|
||||
lambda *a, **k: datetime(2026, 11, 15, 20, 0, 0),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
'app.services.pl_quota_customer_select.select_whole_cover_certs',
|
||||
fake_select,
|
||||
)
|
||||
monkeypatch.setattr(planning, 'resolve_contract_bound_certs', fake_contract_bind)
|
||||
monkeypatch.setattr(
|
||||
planning,
|
||||
'_get_row',
|
||||
lambda *a, **k: SimpleNamespace(id='x', revision=1),
|
||||
)
|
||||
|
||||
planning.build_usage_request(
|
||||
MagicMock(),
|
||||
SimpleNamespace(id='u', tenant_no='t', dept_id=''),
|
||||
'p1',
|
||||
PlanQuotaOperation(operationId='arrange-check'),
|
||||
'resize',
|
||||
check_conditions=False,
|
||||
)
|
||||
assert called['contract_bind'] == 1
|
||||
assert called['customer_select'] == 0
|
||||
Reference in new issue
Block a user