fix(pl): 客户品类规则预占不再依赖合同绑证 scope。
新规则自动选证后账本仍按合同绑证判定适用,导致预占报人工分配不适用;改为客户品类路径跳过 scope,明细合同绑证字段可空,并统一关联购买证文案。
This commit is contained in:
1 parent
a6fc0aa0f3
commit
9f855423d8
13 files changed
+158
-20
No files matched your search
@@ -381,3 +381,85 @@ def test_same_city_source_skips_transport_requirement():
|
||||
assert purchase_ids == ['buy1']
|
||||
assert transport_ids == []
|
||||
assert manuals[0].permit_id == 'buy1'
|
||||
|
||||
|
||||
def test_candidate_context_customer_rule_skips_contract_scope(monkeypatch):
|
||||
"""新规则账本候选不以合同绑证 scope 判定适用,否则预占会误报人工分配不适用。"""
|
||||
from datetime import date
|
||||
from decimal import Decimal
|
||||
from types import SimpleNamespace
|
||||
from app.services import pl_quota_usage_service as usage
|
||||
from app.schemas.pl.quota_usage import UsageSource
|
||||
|
||||
plan = SimpleNamespace(id='plan', cert_quota_rule_version='customer_category', plan_no='P1')
|
||||
source = UsageSource(
|
||||
source_stop_type='delivery',
|
||||
source_stop_id='s1',
|
||||
source_stop_product_id='sp1',
|
||||
plan_product_id='pp1',
|
||||
contract_id='c1',
|
||||
contract_product_id='cp1',
|
||||
product_id='prod1',
|
||||
quantity=Decimal('50'),
|
||||
unit='dun',
|
||||
fingerprint='f' * 64,
|
||||
snapshot={'customerId': 'cust1'},
|
||||
requires_transport=True,
|
||||
)
|
||||
request = SimpleNamespace(
|
||||
sources=[source],
|
||||
on_date=date(2026, 11, 15),
|
||||
vehicle_no='皖A9TEST1',
|
||||
manual_allocations=[],
|
||||
)
|
||||
cert = SimpleNamespace(
|
||||
id='buy1', status='active', verified_time=date(2026, 11, 1), verified_by='u',
|
||||
valid_from=date(2026, 11, 1), valid_to=date(2027, 1, 1), valid_use_text='多次有效',
|
||||
total_qty=Decimal('100'), used_qty=Decimal('0'), reserved_qty=Decimal('0'),
|
||||
quantity_unit='dun', vehicle_numbers_json=['皖A9TEST1'], opening_single_use_consumed=0,
|
||||
revision=1, cert_no='G1',
|
||||
)
|
||||
|
||||
class Q:
|
||||
def __init__(self, row=None, rows=None):
|
||||
self._row = row
|
||||
self._rows = rows or ([] if row is None else [row])
|
||||
|
||||
def first(self):
|
||||
return self._row
|
||||
|
||||
def all(self):
|
||||
return self._rows
|
||||
|
||||
def fake_query(db, user, model, lock=False, **filters):
|
||||
name = getattr(model, '__name__', '')
|
||||
if name == 'PlCertQtyLog':
|
||||
return Q(SimpleNamespace(id='opening'))
|
||||
if name == 'PlTransportCertPurchaseRef':
|
||||
return Q(rows=[])
|
||||
if name in ('PlContractCertLink', 'PlContractCertProduct'):
|
||||
raise AssertionError('customer_category 不应查询合同绑证 scope')
|
||||
return Q()
|
||||
|
||||
monkeypatch.setattr(usage, '_query', fake_query)
|
||||
monkeypatch.setattr(usage, '_contract', lambda *a, **k: SimpleNamespace(status='executing', contract_type='sale'))
|
||||
monkeypatch.setattr(
|
||||
'app.services.pl_cert_quota_rule_config_service.plan_uses_customer_category',
|
||||
lambda p: True,
|
||||
)
|
||||
# product ownership check uses _query for CrmContractProduct
|
||||
def fake_query2(db, user, model, lock=False, **filters):
|
||||
name = getattr(model, '__name__', '')
|
||||
if name == 'CrmContractProduct':
|
||||
return Q(SimpleNamespace(product_id='prod1'))
|
||||
return fake_query(db, user, model, lock=lock, **filters)
|
||||
|
||||
monkeypatch.setattr(usage, '_query', fake_query2)
|
||||
|
||||
sources, scopes, candidates = usage._candidate_context(
|
||||
MagicMock(), SimpleNamespace(tenant_no='t', id='u'), request, plan,
|
||||
{('purchase', 'buy1'): cert}, {}, {}, {('purchase', 'buy1')},
|
||||
)
|
||||
assert 'delivery:sp1' in sources
|
||||
assert scopes[(('purchase', 'buy1'), 'delivery:sp1')] == (None, None)
|
||||
assert candidates['purchase'][0].product_ids == frozenset({'delivery:sp1'})
|
||||
@@ -97,7 +97,7 @@ def test_plan_overview_accepts_web_funnel_aliases_and_validates_dates(api, monke
|
||||
assert filters == {'plan_no': '001', 'license_plate': '皖A',
|
||||
'plan_date_from': date(2026, 11, 1), 'plan_date_to': date(2026, 11, 3),
|
||||
'quota_status_in': 'reserved,settled', 'supplier_name': None, 'customer_name': None,
|
||||
'product_name': None, 'follow_status_in': None}
|
||||
'product_name': None, 'follow_status_in': None, 'conversion_only': False}
|
||||
assert client.get('/api/transport/quota-certs/plans', params={'planDateFrom': 'wrong'}).status_code == 422
|
||||
assert received == []
|
||||
|
||||
|
||||
@@ -251,6 +251,11 @@ def approval_case(business, monkeypatch):
|
||||
c.db.commit()
|
||||
c.user.to_tenant_user_dict=lambda:{}
|
||||
monkeypatch.setattr(api,'get_tenant_no',lambda *a:'t')
|
||||
# 安排入口要求已配置客户品类额度生效时间;本套用例聚焦共享运输/钉版本,不测切点本身
|
||||
monkeypatch.setattr(
|
||||
'app.services.pl_cert_quota_rule_config_service.assert_cert_quota_rule_configured',
|
||||
lambda *a, **k: None,
|
||||
)
|
||||
c.api=api
|
||||
return c
|
||||
|
||||
|
||||
@@ -314,11 +314,11 @@ def test_unlinked_reference_can_bind_purchase_archive_after_opening(ctx):
|
||||
assert saved['purchaseRefs'][0]['purchaseCertId']==purchase_row['id']
|
||||
assert saved['purchaseRefs'][0]['referenceNo']=='G35260264950502'
|
||||
linked=saved['purchaseRefs'][0]
|
||||
with pytest.raises(HTTPException, match='不能改变证面引用身份'):
|
||||
with pytest.raises(HTTPException, match='不能改变关联购买证身份'):
|
||||
s.save_cert(db,u,'transport',{'purchaseRefs':[{'id':linked['id'],'referenceType':'unknown','referenceNo':purchase_row['certNo'],'purchaseCertId':purchase_row['id']}]},row['id'])
|
||||
with pytest.raises(HTTPException, match='不能移除'):
|
||||
s.save_cert(db,u,'transport',{'purchaseRefs':[]},row['id'])
|
||||
with pytest.raises(HTTPException, match='不能改变证面引用身份'):
|
||||
with pytest.raises(HTTPException, match='不能改变关联购买证身份'):
|
||||
s.save_cert(db,u,'transport',{'purchaseRefs':[
|
||||
{k:linked[k] for k in ('id','referenceType','referenceNo','purchaseCertId')},
|
||||
{'referenceType':'unknown','referenceNo':'NEW'},
|
||||
|
||||
Reference in new issue
Block a user