Files
SupplierSystem/migrations/20261102_processing_finished_pending_inspection_cleanup.sql
Ubuntu 39569df290
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
refactor(仓内加工): 对齐主系统批次口径
移除独立原料采购面板,原料回到自采单行;迁移文件统一为主系统命名;录单行内补原材料按钮。
2026-11-03 14:18:58 +08:00

41 lines
1.4 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.
-- 仓内加工成品不应进入待入库/验收:清理历史遗留的成品待验行。
-- 只删「未验收、未入库」且对应订单行是仓内加工成品的 inspections;
-- 原料的独立入库待验(order_code 为空)不受影响。
-- 设计:docs/design/20261102-warehouse-processing-raw-material-auto-purchase.md
DO $$
DECLARE
sch text;
BEGIN
FOR sch IN
SELECT n.nspname FROM pg_namespace n
WHERE n.nspname IN ('public','legacy_public','tenant_template') OR n.nspname LIKE 'tenant\_%'
ORDER BY n.nspname
LOOP
IF to_regclass(format('%I.inspections', sch)) IS NULL
OR to_regclass(format('%I.order_items', sch)) IS NULL THEN
CONTINUE;
END IF;
EXECUTE format(
'DELETE FROM %I.inspections i
USING %I.order_items oi
WHERE i.order_code = oi.order_code
AND i.inspection_time IS NULL
AND i.inbound_batch_no IS NULL
AND TRIM(COALESCE(oi.processing_owner, '''')) = ''warehouse''
AND NULLIF(TRIM(COALESCE(oi.processing_method, '''')), '''') IS NOT NULL
AND TRIM(oi.processing_method) <> ''原材料''
AND (
(oi.sku_code IS NOT NULL AND i.sku_code = oi.sku_code)
OR (
oi.sku_code IS NULL
AND i.sku_code IS NULL
AND TRIM(COALESCE(i.item_name, '''')) = TRIM(COALESCE(oi.item_name, ''''))
)
)',
sch, sch
);
END LOOP;
END $$;