fix(履约): 重挂备货/采购/库存抵扣时清掉配送直供标记
修复盘点/删除库存触发的 order_item_fulfillment_one_source 约束冲突:旧行 direct_delivery_cover=true 与新来源并存。
This commit is contained in:
@@ -24,13 +24,14 @@ export async function linkOrderItemToPreparation(
|
||||
const cover = Math.max(0, Number(input.inventoryCoverQty) || 0);
|
||||
await db.query(
|
||||
`INSERT INTO order_item_fulfillments (
|
||||
order_item_id, order_code, supplier_preparation_id, purchase_code, inventory_cover_qty, updated_at
|
||||
) VALUES ($1::uuid, $2, $3::uuid, NULL, $4, NOW())
|
||||
order_item_id, order_code, supplier_preparation_id, purchase_code, inventory_cover_qty, direct_delivery_cover, updated_at
|
||||
) VALUES ($1::uuid, $2, $3::uuid, NULL, $4, false, NOW())
|
||||
ON CONFLICT (order_item_id) DO UPDATE SET
|
||||
order_code = EXCLUDED.order_code,
|
||||
supplier_preparation_id = EXCLUDED.supplier_preparation_id,
|
||||
purchase_code = NULL,
|
||||
inventory_cover_qty = EXCLUDED.inventory_cover_qty,
|
||||
direct_delivery_cover = false,
|
||||
updated_at = NOW()`,
|
||||
[input.orderItemId, input.orderCode, input.preparationId, cover]
|
||||
);
|
||||
@@ -48,13 +49,14 @@ export async function linkOrderItemToPurchase(
|
||||
const cover = Math.max(0, Number(input.inventoryCoverQty) || 0);
|
||||
await db.query(
|
||||
`INSERT INTO order_item_fulfillments (
|
||||
order_item_id, order_code, supplier_preparation_id, purchase_code, inventory_cover_qty, updated_at
|
||||
) VALUES ($1::uuid, $2, NULL, $3, $4, NOW())
|
||||
order_item_id, order_code, supplier_preparation_id, purchase_code, inventory_cover_qty, direct_delivery_cover, updated_at
|
||||
) VALUES ($1::uuid, $2, NULL, $3, $4, false, NOW())
|
||||
ON CONFLICT (order_item_id) DO UPDATE SET
|
||||
order_code = EXCLUDED.order_code,
|
||||
supplier_preparation_id = NULL,
|
||||
purchase_code = EXCLUDED.purchase_code,
|
||||
inventory_cover_qty = EXCLUDED.inventory_cover_qty,
|
||||
direct_delivery_cover = false,
|
||||
updated_at = NOW()`,
|
||||
[input.orderItemId, input.orderCode, input.purchaseCode, cover]
|
||||
);
|
||||
@@ -71,13 +73,14 @@ export async function linkOrderItemToInventoryCover(
|
||||
}
|
||||
await db.query(
|
||||
`INSERT INTO order_item_fulfillments (
|
||||
order_item_id, order_code, supplier_preparation_id, purchase_code, inventory_cover_qty, updated_at
|
||||
) VALUES ($1::uuid, $2, NULL, NULL, $3, NOW())
|
||||
order_item_id, order_code, supplier_preparation_id, purchase_code, inventory_cover_qty, direct_delivery_cover, updated_at
|
||||
) VALUES ($1::uuid, $2, NULL, NULL, $3, false, NOW())
|
||||
ON CONFLICT (order_item_id) DO UPDATE SET
|
||||
order_code = EXCLUDED.order_code,
|
||||
supplier_preparation_id = NULL,
|
||||
purchase_code = NULL,
|
||||
inventory_cover_qty = EXCLUDED.inventory_cover_qty,
|
||||
direct_delivery_cover = false,
|
||||
updated_at = NOW()`,
|
||||
[input.orderItemId, input.orderCode, cover]
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user