fix(库存): 已绑定批次报告的批次禁止真实删除
避免删除本地批次后断掉供应商订单报告展示/重推关联;报告需先解绑或归档。
This commit is contained in:
@@ -101,11 +101,20 @@ export async function hardDeleteInventoryBatch(input: {
|
||||
available_qty: available,
|
||||
};
|
||||
|
||||
// 报告关联删除;报告文件本身保留。
|
||||
await client.query(
|
||||
`DELETE FROM inventory_batch_report_matches WHERE inventory_id = $1::uuid`,
|
||||
// 2026-10-31:已绑定批次报告的批次禁止真实删除。
|
||||
// 主系统已有报告副本不受影响,但删除本地 inventory 会断掉供应商自己的订单报告展示/
|
||||
// 后续重推关联,因此这里选择“先解绑/归档,再删批次”。
|
||||
const reportRef = await client.query(
|
||||
`SELECT 1 FROM inventory_batch_report_matches WHERE inventory_id = $1::uuid LIMIT 1`,
|
||||
[inventoryId]
|
||||
);
|
||||
if (reportRef.rowCount) {
|
||||
throw bad(
|
||||
'该批次已绑定批次报告,不能真实删除;请先解除报告关联或改为归档',
|
||||
'batch_has_report',
|
||||
409
|
||||
);
|
||||
}
|
||||
// 保留业务单据历史,仅解除对已删除批次行的引用。
|
||||
await client.query(
|
||||
`UPDATE self_purchase_stock_inbounds SET inventory_id = NULL WHERE inventory_id = $1::uuid`,
|
||||
|
||||
@@ -23,6 +23,7 @@ describe('库存批次真实删除(方案 A)', () => {
|
||||
|
||||
it('保留流水/报告,业务单据只置空 inventory_id', () => {
|
||||
expect(svc).toContain('inventory_batch_report_matches');
|
||||
expect(svc).toContain('batch_has_report');
|
||||
expect(svc).toContain('self_purchase_stock_inbounds SET inventory_id = NULL');
|
||||
expect(svc).toContain('processing_task_outputs SET inventory_id = NULL');
|
||||
expect(svc).not.toContain('DELETE FROM inventory_logs');
|
||||
|
||||
Reference in New Issue
Block a user