fix(库存抵扣): 未开拣分拣行不再锁死库存抵扣
早期任务下单即建 picking_items;仅实际已拣/已核货/已出库才锁定 cover,未开拣允许重算。
This commit is contained in:
@@ -493,7 +493,15 @@ async function loadLockedStockCoverIfInboundOrPicking(
|
||||
const result = await db.query(
|
||||
`SELECT COALESCE(oi.stock_cover_qty, 0)::float AS stock_cover_qty,
|
||||
EXISTS (
|
||||
SELECT 1 FROM picking_items pi WHERE pi.order_item_id = oi.id
|
||||
SELECT 1 FROM picking_items pi
|
||||
LEFT JOIN picking_tasks pt ON pt.pick_code = pi.pick_code
|
||||
WHERE pi.order_item_id = oi.id
|
||||
AND (
|
||||
COALESCE(pi.picked_qty, 0) > 0
|
||||
OR COALESCE(pi.loaded_qty, 0) > 0
|
||||
OR COALESCE(pi.review_status, 0) >= 20
|
||||
OR COALESCE(pt.pick_status, 10) >= 30
|
||||
)
|
||||
) AS has_picking,
|
||||
EXISTS (
|
||||
SELECT 1 FROM inspections i
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
const src = readFileSync(
|
||||
new URL('../src/services/inventoryStockCoverService.ts', import.meta.url),
|
||||
'utf8'
|
||||
);
|
||||
|
||||
describe('库存抵扣锁定仅在真实拣货/核货/出库后生效', () => {
|
||||
it('未开拣的空 picking_items 不再锁死抵扣', () => {
|
||||
const start = src.indexOf('async function loadLockedStockCoverIfInboundOrPicking');
|
||||
const end = src.indexOf('export async function applyStockCoverForOrderItem', start);
|
||||
const fn = src.slice(start, end);
|
||||
expect(fn).toContain('COALESCE(pi.picked_qty, 0) > 0');
|
||||
expect(fn).toContain('COALESCE(pi.loaded_qty, 0) > 0');
|
||||
expect(fn).toContain('COALESCE(pi.review_status, 0) >= 20');
|
||||
expect(fn).toContain('COALESCE(pt.pick_status, 10) >= 30');
|
||||
expect(fn).not.toContain('EXISTS (\n SELECT 1 FROM picking_items pi WHERE pi.order_item_id = oi.id\n )');
|
||||
});
|
||||
|
||||
it('已入库锁定保留', () => {
|
||||
expect(src).toContain('AS has_inbound');
|
||||
expect(src).toContain("NULLIF(TRIM(i.inbound_batch_no), '') IS NOT NULL");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user