Files
SupplierSystem/migrations/20261081_template_cost_details_cover_qty.sql
Ubuntu 83eb8f9c12
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
fix: 库存抵扣成本/商品成本排行收口 + 主系统事件定向消费 + 关闭主数据不卡流程
- 库存抵扣成本按目标抵扣量幂等更新,作废/退货清 cover_qty;多批次展示按加权均价;商品成本排行纳入库存抵扣成本并改标签为“成本”
- 主系统事件:allocated 定向 order_code、returned 等批量状态核对、clamped/全量兜底下调频、失败不计 applied
- 订单完成:零价闸门排除已退货行;供应商系统关闭“主数据不卡流程”入口与执行接口
- 迁移 20261080/20261081;补充相关契约/回归测试
2026-10-24 18:24:05 +08:00

32 lines
1.2 KiB
SQL
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
-- 模板表补 cover_qty(2026-10-24 财务口径;20261080 首版排除了 tenant_template)
--
-- 新租户从 tenant_template 克隆;模板缺列会让新租户 postInventoryCoverPurchaseCost
-- 直接 42703。这里补模板列,并复用 20261080 的回填口径(模板通常 0 行,仍幂等)。
DO $$
BEGIN
IF EXISTS (
SELECT 1 FROM information_schema.tables
WHERE table_schema = 'tenant_template' AND table_name = 'cost_details'
) THEN
PERFORM set_config('app.branch_code', 'TEMPLATE', true);
ALTER TABLE tenant_template.cost_details
ADD COLUMN IF NOT EXISTS cover_qty numeric(14,4);
IF EXISTS (
SELECT 1 FROM information_schema.tables
WHERE table_schema = 'tenant_template' AND table_name = 'order_items'
) THEN
UPDATE tenant_template.cost_details c
SET cover_qty = src.qty
FROM (
SELECT order_code, sku_code, SUM(COALESCE(stock_cover_qty, 0))::numeric(14,4) AS qty
FROM tenant_template.order_items
GROUP BY order_code, sku_code
) src
WHERE c.order_code = src.order_code
AND c.sku_code = src.sku_code
AND c.cost_source = 'inventory_cover'
AND c.cover_qty IS NULL;
END IF;
END IF;
END $$;