fix(pl): 用合同与来源主体信息替代用量追踪表中的技术标识。
This commit is contained in:
1 parent
72cf0d9c3d
commit
da56a1e319
5 files changed
+118
-6
No files matched your search
@@ -117,12 +117,16 @@ def _details(db, user, keys, contract_ids=None):
|
||||
group['products'].append(value)
|
||||
value['reservedQty'] += item.reserved_qty
|
||||
value['usedQty'] += item.used_qty
|
||||
source_stop = next((stop for stop in (item.source_snapshot or {}).get('stops', [])
|
||||
if stop.get('id') == item.source_stop_id), {})
|
||||
party_name = source_stop.get('supplier_name' if item.source_stop_type == 'load' else 'customer_name')
|
||||
usage_items.append({'id': item.id, 'usageId': usage.id, 'certType': usage.cert_type,
|
||||
'certId': usage.cert_id, 'planId': plan.id, 'planNo': plan.plan_no,
|
||||
'stopType': item.source_stop_type, 'stopId': item.source_stop_id,
|
||||
'stopProductId': item.source_stop_product_id, 'planProductId': item.plan_product_id,
|
||||
'contractId': item.contract_id, 'contractProductId': item.contract_product_id,
|
||||
'productName': product.product_name, 'quantityUnit': usage.quantity_unit,
|
||||
'partyName': party_name or '—', 'address': source_stop.get('address') or '—',
|
||||
'reservedQty': item.reserved_qty, 'usedQty': item.used_qty, 'itemStatus': item.item_status})
|
||||
return groups, usage_items
|
||||
|
||||
|
||||
@@ -216,3 +216,22 @@ def test_all_statistics_reads_emit_no_mutations_or_commit(case, monkeypatch):
|
||||
finally:
|
||||
event.remove(case.db.bind, 'before_cursor_execute', capture)
|
||||
assert all(sql.lstrip().upper().startswith('SELECT') for sql in statements)
|
||||
|
||||
@pytest.mark.parametrize('source_type,source_stop,expected', [
|
||||
('delivery', {'id': 'source', 'customer_name': '本段客户', 'address': '本段送货地址'}, ('本段客户', '本段送货地址')),
|
||||
('load', {'id': 'source', 'supplier_name': '本段供应商', 'address': '本段装货地址'}, ('本段供应商', '本段装货地址')),
|
||||
('delivery', {'id': 'source'}, ('—', '—')),
|
||||
('delivery', {'id': 'missing', 'customer_name': '其他客户', 'address': '其他地址'}, ('—', '—')),
|
||||
])
|
||||
def test_usage_party_is_taken_only_from_exact_source_stop_snapshot(case, source_type, source_stop, expected):
|
||||
add_usage(case, 'a', 'source', 20)
|
||||
item = case.db.query(m.PlPlanCertUsageItem).filter_by(id='source').one()
|
||||
item.source_stop_type = source_type
|
||||
item.source_snapshot = {'stops': [
|
||||
{'id': 'related', 'customer_name': '关联段客户', 'supplier_name': '关联段供应商', 'address': '关联段地址'},
|
||||
source_stop,
|
||||
]}
|
||||
case.db.commit()
|
||||
row = service().certificate_statistics(case.db, case.user, 'purchase', 'same')['usageItems'][0]
|
||||
assert (row['partyName'], row['address']) == expected
|
||||
assert item.source_snapshot['stops'][0]['address'] == '关联段地址'
|
||||
@@ -289,3 +289,74 @@ test('contract type tags translate all server values and legacy framework', () =
|
||||
assert.equal(renderLabel({ contractType }, ...Object.values(statisticsLabels)), label)
|
||||
}
|
||||
})
|
||||
|
||||
test('usage trace renders business columns and resolves contract/product by their exact identity', () => {
|
||||
const sfc = parse(
|
||||
readFileSync(
|
||||
new URL('../src/views/pl/quota-statistics/StatisticsDetail.vue', import.meta.url),
|
||||
'utf8'
|
||||
)
|
||||
).descriptor
|
||||
const source = ts.createSourceFile(
|
||||
'detail.ts',
|
||||
sfc.scriptSetup!.content,
|
||||
ts.ScriptTarget.Latest,
|
||||
true
|
||||
)
|
||||
const code = ts.transpile(
|
||||
source.statements
|
||||
.filter((s) => !ts.isImportDeclaration(s))
|
||||
.map((s) => s.getText(source))
|
||||
.join('\n'),
|
||||
{ target: ts.ScriptTarget.ESNext }
|
||||
)
|
||||
const detail = {
|
||||
contracts: [
|
||||
{
|
||||
id: 'other-contract',
|
||||
contractNo: '不匹配合同',
|
||||
products: [{ contractProductId: 'product-id', model: '不匹配规格' }]
|
||||
},
|
||||
{
|
||||
id: 'contract-id',
|
||||
contractNo: 'HT-2026-01',
|
||||
products: [{ contractProductId: 'product-id', model: '98%' }]
|
||||
}
|
||||
],
|
||||
usageItems: [
|
||||
{
|
||||
id: 'usage-id',
|
||||
contractId: 'contract-id',
|
||||
contractProductId: 'product-id',
|
||||
stopId: 'stop-id',
|
||||
stopProductId: 'stop-product-id',
|
||||
planNo: 'PL-001',
|
||||
stopType: 'delivery',
|
||||
productName: '硫酸',
|
||||
partyName: '本段客户',
|
||||
address: '本段地址'
|
||||
},
|
||||
{ id: 'missing', contractId: 'missing', contractProductId: 'product-id', stopType: 'load' }
|
||||
]
|
||||
}
|
||||
const rows = new Function(
|
||||
'defineProps',
|
||||
'computed',
|
||||
`${code}; return typeof usageRows === 'undefined' ? undefined : usageRows.value`
|
||||
)(() => ({ mode: 'certificate', detail }), vue.computed)
|
||||
assert.ok(rows, '追踪表应提供可读的业务列')
|
||||
assert.deepEqual(
|
||||
rows.map((r: any) => [r.contractNo, r.productModel, r.partyName, r.address]),
|
||||
[
|
||||
['HT-2026-01', '98%', '本段客户', '本段地址'],
|
||||
['—', '—', '—', '—']
|
||||
]
|
||||
)
|
||||
const table = sfc.template!.content.match(/<el-table :data="usageRows"[\s\S]*?<\/el-table>/)![0]
|
||||
const props = [...table.matchAll(/<el-table-column prop="([^"]+)"/g)].map((m) => m[1])
|
||||
assert.ok(['contractNo', 'productModel', 'partyName', 'address'].every((p) => props.includes(p)))
|
||||
assert.ok(!props.some((p) => /Id$/.test(p)))
|
||||
assert.ok(!table.includes('row.stopId'))
|
||||
const stopExpression = table.match(/<el-tag size="small">\s*\{\{([\s\S]*?)\}\}/)![1]
|
||||
assert.equal(new Function('row', `return (${stopExpression})`)(rows[0]), '送货')
|
||||
})
|
||||
@@ -331,6 +331,8 @@ export interface ContractStatistics extends ContractOption {
|
||||
certificates: (CertificateStatisticsSummary & StatisticsBinding & { productNames: string[] })[]
|
||||
}
|
||||
export interface StatisticsUsageItem {
|
||||
partyName?: string | null
|
||||
address?: string | null
|
||||
id: string
|
||||
usageId: string
|
||||
certType: CertType
|
||||
|
||||
@@ -62,17 +62,18 @@
|
||||
<StatisticsProducts :products="item.products" :quantity-unit="certificate.quantityUnit" />
|
||||
</section>
|
||||
<h3>计划段产品用量追踪</h3>
|
||||
<el-table :data="certificate.usageItems" stripe class="list-table" row-key="id">
|
||||
<el-table :data="usageRows" stripe class="list-table" row-key="id">
|
||||
<el-table-column prop="planNo" label="计划编号" min-width="180" />
|
||||
<el-table-column label="段次" min-width="150"
|
||||
><template #default="{ row }"
|
||||
><el-tag size="small">{{ row.stopType === 'load' ? '装货' : '卸货' }}</el-tag>
|
||||
{{ row.stopId }}</template
|
||||
></el-table-column
|
||||
><el-tag size="small">{{ row.stopType === 'load' ? '装货' : '送货' }}</el-tag>
|
||||
</template></el-table-column
|
||||
>
|
||||
<el-table-column prop="productName" label="产品" min-width="160" />
|
||||
<el-table-column prop="stopProductId" label="段产品标识" min-width="180" />
|
||||
<el-table-column prop="contractProductId" label="合同产品标识" min-width="180" />
|
||||
<el-table-column prop="contractNo" label="合同编号" min-width="180" />
|
||||
<el-table-column prop="productModel" label="规格" min-width="140" />
|
||||
<el-table-column prop="partyName" label="装货 / 送货主体" min-width="180" />
|
||||
<el-table-column prop="address" label="装货 / 送货地址" min-width="200" />
|
||||
<el-table-column prop="quantityUnit" label="单位" min-width="90" />
|
||||
<el-table-column prop="reservedQty" label="预占" min-width="120" />
|
||||
<el-table-column prop="usedQty" label="已用" min-width="120" />
|
||||
@@ -99,4 +100,19 @@
|
||||
const certificate = computed(() =>
|
||||
props.mode === 'certificate' ? (props.detail as CertificateStatistics) : undefined
|
||||
)
|
||||
const usageRows = computed(() =>
|
||||
(certificate.value?.usageItems || []).map((item) => {
|
||||
const contract = certificate.value?.contracts.find((row) => row.id === item.contractId)
|
||||
const product = contract?.products.find(
|
||||
(row) => row.contractProductId === item.contractProductId
|
||||
)
|
||||
return {
|
||||
...item,
|
||||
contractNo: contract?.contractNo || '—',
|
||||
productModel: product?.model || '—',
|
||||
partyName: item.partyName || '—',
|
||||
address: item.address || '—'
|
||||
}
|
||||
})
|
||||
)
|
||||
</script>
|
||||
Reference in new issue
Block a user