fix(库存抵扣): 修复改批次成本重算 SQL 括号/参数类型报错
UPDATE cover_qty 子查询多一个右括号;补记账本 INSERT 的 / 显式 text 转换,避免 inconsistent types deduced。已在本地同事务重放通过。
This commit is contained in:
@@ -361,9 +361,9 @@ export async function recalcCoverLedgerForBatchCostChange(
|
||||
SET amount = $3::numeric, allocated_amount = $3::numeric,
|
||||
cover_qty = (
|
||||
SELECT COALESCE(SUM(COALESCE(stock_cover_qty, 0)), 0)
|
||||
FROM order_items WHERE order_code = $1 AND sku_code = $2
|
||||
))
|
||||
WHERE order_code = $1 AND sku_code = $2 AND cost_source = 'inventory_cover'`,
|
||||
FROM order_items WHERE order_code = $1::text AND sku_code = $2::text
|
||||
)
|
||||
WHERE order_code = $1::text AND sku_code = $2::text AND cost_source = 'inventory_cover'`,
|
||||
[row.order_code, row.sku_code, row.after_amount]
|
||||
);
|
||||
if ((updated.rowCount || 0) === 0 && Number(row.after_amount) > 0) {
|
||||
@@ -377,8 +377,8 @@ export async function recalcCoverLedgerForBatchCostChange(
|
||||
`INSERT INTO cost_details (
|
||||
cycle_code, order_code, cost_type, cost_subtype, amount, allocated_amount, status,
|
||||
branch_code, sku_code, cost_source, remark, cover_qty
|
||||
) VALUES ($1, $2, 'purchase', 'stock_cover', $3, $3, 20, $4, $5, 'inventory_cover', 'stock_cover',
|
||||
(SELECT COALESCE(SUM(COALESCE(stock_cover_qty, 0)), 0) FROM order_items WHERE order_code = $2 AND sku_code = $5))`,
|
||||
) VALUES ($1, $2::text, 'purchase', 'stock_cover', $3, $3, 20, $4, $5::text, 'inventory_cover', 'stock_cover',
|
||||
(SELECT COALESCE(SUM(COALESCE(stock_cover_qty, 0)), 0) FROM order_items WHERE order_code = $2::text AND sku_code = $5::text))`,
|
||||
[cycleCode, row.order_code, row.after_amount, branch, row.sku_code]
|
||||
);
|
||||
}
|
||||
@@ -471,8 +471,8 @@ export async function repairMissingCoverLedger(input: {
|
||||
SET amount = $2::numeric, allocated_amount = $2::numeric,
|
||||
cover_qty = (
|
||||
SELECT COALESCE(SUM(COALESCE(stock_cover_qty, 0)), 0)
|
||||
FROM order_items WHERE order_code = $3 AND sku_code = $4
|
||||
))
|
||||
FROM order_items WHERE order_code = $3::text AND sku_code = $4::text
|
||||
)
|
||||
WHERE id = $1`,
|
||||
[existing.rows[0].id, amount, code, sku]
|
||||
);
|
||||
@@ -489,8 +489,8 @@ export async function repairMissingCoverLedger(input: {
|
||||
`INSERT INTO cost_details (
|
||||
cycle_code, order_code, cost_type, cost_subtype, amount, allocated_amount, status,
|
||||
branch_code, sku_code, cost_source, remark, cover_qty
|
||||
) VALUES ($1, $2, 'purchase', 'stock_cover', $3, $3, 20, $4, $5, 'inventory_cover', 'stock_cover',
|
||||
(SELECT COALESCE(SUM(COALESCE(stock_cover_qty, 0)), 0) FROM order_items WHERE order_code = $2 AND sku_code = $5))`,
|
||||
) VALUES ($1, $2::text, 'purchase', 'stock_cover', $3, $3, 20, $4, $5::text, 'inventory_cover', 'stock_cover',
|
||||
(SELECT COALESCE(SUM(COALESCE(stock_cover_qty, 0)), 0) FROM order_items WHERE order_code = $2::text AND sku_code = $5::text))`,
|
||||
[
|
||||
trim(meta.rows[0]?.cycle_code) || '0000',
|
||||
code,
|
||||
|
||||
Reference in New Issue
Block a user