feat(库存抵扣弹窗): 就地改批次入库成本(口径甲)—— 订单管理 →「库存抵扣」批次弹窗
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s

按开发者 2026-10-14 定的入口位置落地(订单详情成本列仍只读;改价入口只在抵扣批次弹窗):
- 路由(与弹窗接口同族,orderRoutes.ts):
  · GET  /orders/:orderCode/stock-cover-batches/batch-cost-impact?batch_no=&new_cost=
    —— 风险块数据(只读):现价/新价、受影响订单行金额前后、**已结算跳过清单**;
  · PATCH /orders/:orderCode/stock-cover-batches/batch-cost(batch_no/cost_price/remark)
    —— 委派 inventoryBatchCostService.applyBatchCostChange(备注必填;同事务改批次成本 +
      重算未结算订单抵扣账本 + inventory_logs/审计;已结算订单不回改)。
- 前端 API:previewBatchCostImpactApi / applyBatchCostChangeApi + BatchCostImpactDto。
- 弹窗(OrderStockCoverBatchesModal):每条批次行「改成本」→ 内联区块(新价 + 备注 + 两步确认
  「查看影响」→「确认修改」)+ 风险清单(受影响订单/金额 ¥X→¥Y/已结算 N 行不回改)+ 在途锁;
  改完就地刷新批次明细。
- 三语 14 条 orders.coverBatch.*(改成本/风险/备注必填/已结算不改/成功失败)。

验证:两侧 tsc 0 错;service 层已真库实测(¥3→¥3.5 ⇒ 账本 ¥90→¥105、成本页 ¥159→¥174、改回幂等;
inventory_logs 两条)。接口层实测受 admin 令牌无分公司绑定所限(`assertOrderCodeAccess` 对无作用域
令牌返回「订单不存在」,与既有 cover-batches GET 同因),需用有 BR002 作用域的登录态在页面上验。

排队:供应商结算(下一轮)、采购管理日期窗口排查、抵扣量回退重评状态。
This commit is contained in:
Ubuntu
2026-10-14 19:54:42 +08:00
parent 8af3478ba1
commit 34823bcfe8
6 changed files with 305 additions and 0 deletions
@@ -1260,6 +1260,80 @@ router.get('/orders/:orderCode/stock-cover-batches', authMiddleware, async (req:
}
});
/**
* **改批次入库成本的「影响面」预览**(订单管理 →「库存抵扣」批次弹窗的风险块数据,只读)。
*
* 返回:该批次现价/新价、受影响订单行(金额前后)、**已结算被跳过**的清单。
* 见 docs/design/20261014-入库列表改批次成本(并重算抵扣账本).md(口径「甲」)。
*/
router.get('/orders/:orderCode/stock-cover-batches/batch-cost-impact', authMiddleware, async (req: AuthRequest, res: Response) => {
try {
const ctx = await getWorkflowCtx(req);
requireWorkflowPermission(ctx, [
'order_manage',
'order_edit',
'inventory_manage',
'purchase_manage',
]);
const orderCode = String(req.params.orderCode || '').trim();
await assertOrderCodeAccess(orderCode, ctx!);
const { previewBatchCostImpact } = await import(
'../../../services/inventoryBatchCostService'
);
const rawNew = req.query?.new_cost;
const data = await previewBatchCostImpact({
batchNo: String(req.query?.batch_no || '').trim(),
newCost: rawNew == null || String(rawNew).trim() === '' ? null : Number(rawNew),
branchCode: ctx?.branchCode || null,
});
if (!data) {
return res.status(404).json({ error: 'batch_not_found', error_description: '批次不存在' });
}
return res.json({ data });
} catch (error: any) {
return res.status(error?.status || 500).json({
error: error?.code || 'server_error',
error_description: error?.message || '读取批次成本影响面失败',
});
}
});
/**
* **改批次入库成本**(口径「甲」,开发者 2026-10-14):
* 改 `inventory.cost_price` + **同事务**按该行实际抵扣的批次重算**未结算**订单的抵扣账本;
* **已结算订单(客户/供应商结算单任一已确认)不回改**。备注必填;写 inventory_logs + 审计。
* 入口在订单管理 →「库存抵扣」批次弹窗(订单详情成本列仍只读)。
*/
router.patch('/orders/:orderCode/stock-cover-batches/batch-cost', authMiddleware, async (req: AuthRequest, res: Response) => {
try {
const ctx = await getWorkflowCtx(req);
requireWorkflowPermission(ctx, [
'order_manage',
'order_edit',
'inventory_manage',
'purchase_manage',
]);
const orderCode = String(req.params.orderCode || '').trim();
await assertOrderCodeAccess(orderCode, ctx!);
const { applyBatchCostChange } = await import(
'../../../services/inventoryBatchCostService'
);
const data = await applyBatchCostChange({
batchNo: String(req.body?.batch_no || '').trim(),
newCost: Number(req.body?.cost_price),
remark: String(req.body?.remark || ''),
operatorId: req.userId,
branchCode: ctx?.branchCode || null,
});
return res.json({ success: true, data });
} catch (error: any) {
return res.status(error?.status || 500).json({
error: error?.code || 'server_error',
error_description: error?.message || '修改批次入库成本失败',
});
}
});
/**
* 「我方指定这一行抵扣用哪几批」(2026-10-13 开发者·方案甲:改完分拣时要对应得上)。
*