来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
63 lines
2.9 KiB
TypeScript
63 lines
2.9 KiB
TypeScript
/**
|
|
* 方案 C 守卫:`purchase_orders.actual_qty`(自采实收)只能由验收写入。
|
|
*
|
|
* 背景:自采侧预填实收会让 inspectionComplianceService 的「实收量归谁写」守卫早退,
|
|
* 单据永久停在 purchase_status=20。见
|
|
* docs/design/20260920-self-purchase-actual-qty-single-writer.md
|
|
*/
|
|
import { readFileSync, readdirSync, statSync } from 'node:fs';
|
|
import path from 'node:path';
|
|
import { describe, expect, it } from 'vitest';
|
|
|
|
const SRC = path.join(__dirname, '../src');
|
|
const read = (rel: string) => readFileSync(path.join(SRC, rel), 'utf8');
|
|
|
|
function walk(dir: string, out: string[] = []): string[] {
|
|
for (const entry of readdirSync(dir)) {
|
|
const full = path.join(dir, entry);
|
|
if (statSync(full).isDirectory()) walk(full, out);
|
|
else if (entry.endsWith('.ts') && !entry.endsWith('.test.ts')) out.push(full);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
describe('方案 C:自采实收单一写入方', () => {
|
|
it('完成自采忽略客户端实收,仅直送/免入库保留豁免;30/40 边不动实收', () => {
|
|
const src = read('services/purchaseOperationService.ts');
|
|
expect(src).toContain('if (status === 20 && !autoActualForDelivery) actualQty = null;');
|
|
// 非 20 的状态边(含作废 40)必须保留原有 COALESCE 语义,避免误清实收与金额
|
|
expect(src).toContain('const preserveStoredActual = status !== 20 || autoActualForDelivery;');
|
|
// 非直送时把实收清空、金额交回金额回退链
|
|
expect(src).toContain(
|
|
'actual_qty = CASE WHEN $6::boolean THEN COALESCE($2, actual_qty) ELSE NULL END'
|
|
);
|
|
});
|
|
|
|
it('自采入口不透传实收数量,「改实收」只改价格/单位/备注', () => {
|
|
const route = read('modules/workflow/routes/purchaseRoutes.ts');
|
|
expect(route).toContain('preserveActualQty: true');
|
|
expect(route).not.toContain('actualQty: req.body?.actual_qty');
|
|
|
|
const src = read('services/purchaseAmendService.ts');
|
|
// 服务端可信调用方(订单明细编辑)仍可设置实收:不受该标记影响
|
|
expect(src).toContain('const preserveActualQty = input.preserveActualQty === true;');
|
|
// 一旦有人把「无条件写数量」写回,这条会先红
|
|
expect(src).not.toContain('SET actual_qty = $2,');
|
|
expect(src).toContain('SET actual_qty = CASE WHEN $2::numeric > 0 THEN $2::numeric ELSE actual_qty END,');
|
|
});
|
|
|
|
it('加工成品自采行不再预填实收', () => {
|
|
const src = read('services/orderAllocationService.ts');
|
|
expect(src).not.toContain('SET purchase_qty = sub.qty, actual_qty = sub.qty');
|
|
});
|
|
|
|
it('全仓只有验收合规服务能把 purchase_status 写成 30', () => {
|
|
const offenders = walk(SRC)
|
|
.filter((file) => /purchase_status\s*=\s*30/.test(readFileSync(file, 'utf8')))
|
|
.map((file) => path.relative(SRC, file).split(path.sep).join('/'))
|
|
.filter((rel) => rel !== 'services/inspectionComplianceService.ts');
|
|
|
|
expect(offenders).toEqual([]);
|
|
});
|
|
});
|