feat(pl): 展示各装送段用证配置与独立占用明细并保留历史计量口径。

This commit is contained in:
wuzilong committed 2026-11-01 22:54:51 +08:00
1 parent 706260ff7a
commit b764eb02a7
10 files changed
+497 -40

No files matched your search

+40 -1
View File
@@ -194,10 +194,11 @@ def test_server_version_cannot_be_overridden_by_client(case, history):
def test_options_include_stop_contract_and_party_without_foreign_contract_leak(case):
from app.models.crm_models import CrmContract
from app.models.pl_quota_models import PlContractCertLink, PlContractCertProduct
from app.models.pl_quota_models import PlPlanCertUsage, PlPlanCertUsageItem
from app.services.pl_quota_planning import get_plan_quota
c = case
for model in (CrmContract, PlPlanCertUsage, PlPlanCertUsageItem): model.__table__.create(c.db.bind)
for model in (CrmContract, PlPlanCertUsage, PlPlanCertUsageItem, PlContractCertLink, PlContractCertProduct): model.__table__.create(c.db.bind)
c.db.add(CrmContract(id='purchase', contract_no='PUR-1', contract_name='购买合同', customer_id='customer', contract_type='purchase', tenant_no='t'))
c.db.add(CrmContract(id='sale', contract_no='SECRET', contract_name='其他租户', customer_id='customer', contract_type='sale', tenant_no='other'))
c.db.get(c.m.PlPlanLoad, 'load').customer_name = '装货方'
@@ -207,3 +208,41 @@ def test_options_include_stop_contract_and_party_without_foreign_contract_leak(c
assert options['load']['partyName'] == '装货方'
assert options['load']['stopId'] == 'load' and options['load']['stopOrder'] == 1
assert options['delivery']['contractNo'] is None
def test_readonly_stop_products_include_explosive_without_changing_sources(case):
from app.models.crm_models import CrmContract
from app.models.pl_quota_models import PlContractCertLink, PlContractCertProduct
from app.models.pl_quota_models import PlPlanCertUsage, PlPlanCertUsageItem
from app.services.pl_quota_planning import get_plan_quota
c = case
for model in (CrmContract, PlPlanCertUsage, PlPlanCertUsageItem, PlContractCertLink, PlContractCertProduct): model.__table__.create(c.db.bind)
product = c.db.get(c.m.PlPlanProduct, 'pp')
product.is_toxic = 0
product.is_explosive = 1
c.db.flush()
result = get_plan_quota(c.db, c.user, 'plan')
assert result['sourceOptions'] == []
assert len(result['stopProducts']) == 2
assert all(row['isExplosive'] and not row['isToxic'] for row in result['stopProducts'])
assert {row['contractId'] for row in result['stopProducts']} == {'purchase', 'sale'}
def test_stop_products_bindings_are_product_specific_and_hidden_contract_is_explicit(case):
from app.models.crm_models import CrmContract
from app.models.pl_quota_models import (PlPlanCertUsage, PlPlanCertUsageItem,
PlContractCertLink, PlContractCertProduct, PlPurchaseCert)
from app.services.pl_quota_planning import get_plan_quota
c = case
for model in (CrmContract, PlPlanCertUsage, PlPlanCertUsageItem, PlContractCertLink, PlContractCertProduct, PlPurchaseCert): model.__table__.create(c.db.bind)
c.db.add(CrmContract(id='purchase', contract_no='PUR', contract_name='采购', customer_id='customer', contract_type='purchase', tenant_no='t'))
c.db.add(PlPurchaseCert(id='cert', cert_no='BUY', product_name_on_cert='硫酸', valid_use_text='多次有效', buyer_name='买方', seller_name='卖方', total_qty=100, quantity_unit='吨', tenant_no='t'))
c.db.add(PlContractCertLink(id='link',contract_id='purchase',contract_no_snapshot='PUR',cert_type='purchase',cert_id='cert',link_status='active',tenant_no='t'))
c.db.add(PlContractCertProduct(id='scope',contract_cert_link_id='link',contract_product_id='cp',scope_status='active',tenant_no='t'))
c.db.flush()
rows = get_plan_quota(c.db,c.user,'plan')['stopProducts']
assert rows[0]['certificates'][0]['certNo'] == 'BUY'
assert rows[1]['bindingsReadable'] is False
assert rows[1]['certificates'] == []
c.db.get(PlContractCertProduct,'scope').scope_status='inactive'; c.db.flush()
assert get_plan_quota(c.db,c.user,'plan')['stopProducts'][0]['certificates'] == []