refactor(仓内加工): 对齐主系统批次口径
移除独立原料采购面板,原料回到自采单行;迁移文件统一为主系统命名;录单行内补原材料按钮。
This commit is contained in:
@@ -58,12 +58,7 @@ import {
|
||||
} from '../../../services/zeroSupplyCostConfigService';
|
||||
import { listPurchaseOrdersForManagement, sumSelfPurchaseTotalAmount } from '../../../services/purchaseOrderQueryService';
|
||||
import { listPriceInvertRisks } from '../../../services/priceInvertRiskQueryService';
|
||||
import {
|
||||
listProcessingRawPurchases,
|
||||
submitProcessingRawPurchase,
|
||||
syncRawMaterialPurchasesForOutputSku,
|
||||
updateProcessingRawPurchase,
|
||||
} from '../../../services/processingRawMaterialService';
|
||||
import { syncRawMaterialPurchasesForOutputSku } from '../../../services/processingRawMaterialService';
|
||||
import { resolveSelfPurchaseWriteAccess } from '../../../services/selfPurchaseHttpAccess';
|
||||
import { assertOwnedStoragePaths } from '../../../services/storageObjectOwnership';
|
||||
|
||||
@@ -1192,59 +1187,6 @@ router.get('/purchase-orders/management-counts', authMiddleware, async (req: Aut
|
||||
|
||||
|
||||
|
||||
router.get('/purchase-orders/processing-raw-materials', authMiddleware, async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const ctx = await getWorkflowCtx(req);
|
||||
requireWorkflowPermission(ctx, ['purchase_manage']);
|
||||
const branchCode = getEffectiveBranchCode(ctx, readOperatingBranchCode(req));
|
||||
const data = await listProcessingRawPurchases({
|
||||
branchCode: branchCode || null,
|
||||
statusGroup: (req.query.status_group as any) || null,
|
||||
search: req.query.search ? String(req.query.search) : null,
|
||||
limit: req.query.limit ? Number(req.query.limit) : 200,
|
||||
});
|
||||
return res.json({ data });
|
||||
} catch (error: any) {
|
||||
return res.status(error?.status || 500).json({ error: error?.code || 'server_error', error_description: error?.message || '加载加工原料采购失败' });
|
||||
}
|
||||
});
|
||||
|
||||
router.patch('/purchase-orders/processing-raw-materials/:id', authMiddleware, async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const ctx = await getWorkflowCtx(req);
|
||||
requireWorkflowPermission(ctx, ['purchase_manage']);
|
||||
const branchCode = getEffectiveBranchCode(ctx, readOperatingBranchCode(req));
|
||||
await updateProcessingRawPurchase({
|
||||
id: String(req.params.id || ''),
|
||||
branchCode: branchCode || null,
|
||||
plannedQty: req.body?.planned_qty != null ? Number(req.body.planned_qty) : undefined,
|
||||
unitCost: req.body?.unit_cost != null ? Number(req.body.unit_cost) : undefined,
|
||||
remark: req.body?.remark !== undefined ? String(req.body.remark) : undefined,
|
||||
});
|
||||
return res.json({ success: true });
|
||||
} catch (error: any) {
|
||||
return res.status(error?.status || 500).json({ error: error?.code || 'server_error', error_description: error?.message || '修改加工原料采购失败' });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/purchase-orders/processing-raw-materials/:id/submit', authMiddleware, async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const ctx = await getWorkflowCtx(req);
|
||||
requireWorkflowPermission(ctx, ['purchase_manage']);
|
||||
const branchCode = getEffectiveBranchCode(ctx, readOperatingBranchCode(req));
|
||||
const data = await submitProcessingRawPurchase({
|
||||
id: String(req.params.id || ''),
|
||||
branchCode: branchCode || null,
|
||||
actualQty: req.body?.actual_qty != null ? Number(req.body.actual_qty) : undefined,
|
||||
unitCost: req.body?.unit_cost != null ? Number(req.body.unit_cost) : undefined,
|
||||
operatorId: ctx?.userId || 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 || '提交加工原料采购失败' });
|
||||
}
|
||||
});
|
||||
|
||||
/** BOM 配置保存后调用:只同步未完工加工单,不阻断商品保存 */
|
||||
router.post('/purchase-orders/processing-raw-materials/sync', authMiddleware, async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
|
||||
@@ -26,7 +26,7 @@ function item(
|
||||
|
||||
describe('历史分拣需求数量回填', () => {
|
||||
it('迁移把已完工成品的未开始分拣行需求改成实收分配量', () => {
|
||||
const migration = read('migrations/20261109_processing_picking_required_sync.sql');
|
||||
const migration = read('migrations/20261102_processing_picking_required_sync.sql');
|
||||
expect(migration).toContain('SET required_qty = oi.received_qty');
|
||||
expect(migration).toContain("processing_owner, '''')) = ''warehouse''");
|
||||
expect(migration).toContain('received_stage');
|
||||
@@ -250,7 +250,7 @@ describe('阶段 2 原型边界(未接线,不得静默改库存/验收/订
|
||||
});
|
||||
|
||||
it('幂等标记迁移只加列,不新增业务表', () => {
|
||||
const migration = read('migrations/20261108_processing_finished_output_apply.sql');
|
||||
const migration = read('migrations/20261102_processing_finished_output_apply.sql');
|
||||
expect(migration).toContain('finished_output_applied_at');
|
||||
expect(migration).toContain('finished_output_actual_qty');
|
||||
expect(migration).toContain('finished_output_plan');
|
||||
|
||||
@@ -75,7 +75,7 @@ describe('processing_bom 解析与损耗估算', () => {
|
||||
expect(service).toContain('只复用「未开始/加工中」需求单');
|
||||
expect(service).toContain('PROCESS_STATUS.pending');
|
||||
expect(service).toContain('[input.branchCode, input.deliveryDate, input.sku, input.method, 30]');
|
||||
const migration = read('migrations/20261114_processing_demand_reuse_open_only.sql');
|
||||
const migration = read('migrations/20261102_processing_demand_reuse_open_only.sql');
|
||||
expect(migration).toContain('process_status < 30');
|
||||
expect(migration).toContain('idx_processing_demand_sheet_key');
|
||||
});
|
||||
@@ -131,7 +131,7 @@ describe('自动采购开关', () => {
|
||||
});
|
||||
|
||||
describe('迁移与租户名单', () => {
|
||||
const migration = read('migrations/20261107_processing_raw_material_purchase.sql');
|
||||
const migration = read('migrations/20261102_processing_raw_material_purchase.sql');
|
||||
|
||||
it('新增 processing_bom 列与 processing_raw_purchases 表并登记 tenant_business_tables', () => {
|
||||
expect(migration).toContain('processing_bom JSONB');
|
||||
@@ -194,9 +194,9 @@ describe('同步/提交/回写规则(源码契约)', () => {
|
||||
it('不再暴露独立原料采购列表/编辑/提交接口;仅保留 BOM 变更同步入口', () => {
|
||||
const routes = read('server/src/modules/workflow/routes/purchaseRoutes.ts');
|
||||
// 供应商系统保留采购页加工原料面板所需的列表/修改/提交接口。
|
||||
expect(routes).toContain("router.get('/purchase-orders/processing-raw-materials'");
|
||||
expect(routes).toContain("router.patch('/purchase-orders/processing-raw-materials/:id'");
|
||||
expect(routes).toContain("router.post('/purchase-orders/processing-raw-materials/:id/submit'");
|
||||
expect(routes).not.toContain("router.get('/purchase-orders/processing-raw-materials'");
|
||||
expect(routes).not.toContain("router.patch('/purchase-orders/processing-raw-materials/:id'");
|
||||
expect(routes).not.toContain("router.post('/purchase-orders/processing-raw-materials/:id/submit'");
|
||||
expect(routes).toContain('/purchase-orders/processing-raw-materials/sync');
|
||||
});
|
||||
|
||||
@@ -206,7 +206,7 @@ describe('同步/提交/回写规则(源码契约)', () => {
|
||||
expect(prep).toContain('DELETE FROM inspections i');
|
||||
expect(prep).toContain("TRIM(COALESCE(oi.processing_owner, '')) = 'warehouse'");
|
||||
expect(prep).toContain("TRIM(oi.processing_method) <> '原材料'");
|
||||
const migration = read('migrations/20261111_processing_finished_pending_inspection_cleanup.sql');
|
||||
const migration = read('migrations/20261102_processing_finished_pending_inspection_cleanup.sql');
|
||||
expect(migration).toContain('inspection_time IS NULL');
|
||||
expect(migration).toContain("processing_owner, ''");
|
||||
});
|
||||
@@ -221,7 +221,7 @@ describe('同步/提交/回写规则(源码契约)', () => {
|
||||
const inspection = read('server/src/services/inspectionComplianceService.ts');
|
||||
expect(inspection).toContain("'processing_raw_material'");
|
||||
expect(inspection).toContain('independent_inbound');
|
||||
const migration = read('migrations/20261112_processing_raw_inspection_visibility.sql');
|
||||
const migration = read('migrations/20261102_processing_raw_inspection_visibility.sql');
|
||||
expect(migration).toContain('independent_inbound');
|
||||
expect(migration).toContain('processing_raw_material');
|
||||
});
|
||||
@@ -235,7 +235,7 @@ describe('同步/提交/回写规则(源码契约)', () => {
|
||||
expect(read('server/src/services/purchaseOperationService.ts')).toContain(
|
||||
'syncProcessingRawPurchaseFromPurchaseOrder'
|
||||
);
|
||||
const migration = read('migrations/20261110_processing_raw_purchase_mirror.sql');
|
||||
const migration = read('migrations/20261102_processing_raw_purchase_mirror.sql');
|
||||
expect(migration).toContain('processing_raw_material');
|
||||
expect(migration).toContain('CEIL(planned_qty)');
|
||||
});
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { RefreshCw, Send, Save } from 'lucide-react';
|
||||
import { useT } from '../../i18n';
|
||||
import { notify } from '../../utils/notify';
|
||||
import {
|
||||
listProcessingRawPurchasesApi,
|
||||
submitProcessingRawPurchaseApi,
|
||||
updateProcessingRawPurchaseApi,
|
||||
type ProcessingRawPurchaseRow,
|
||||
} from '../../utils/workflowApi';
|
||||
|
||||
const STATUS_LABEL: Record<number, string> = { 10: '待采购', 20: '已提交待入库', 30: '已入库', 40: '已取消' };
|
||||
|
||||
export function ProcessingRawMaterialPanel({ refreshToken = 0 }: { refreshToken?: number }) {
|
||||
const t = useT();
|
||||
const [rows, setRows] = useState<ProcessingRawPurchaseRow[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [drafts, setDrafts] = useState<Record<string, { qty: string; cost: string }>>({});
|
||||
const [savingId, setSavingId] = useState<string | null>(null);
|
||||
const [submittingId, setSubmittingId] = useState<string | null>(null);
|
||||
|
||||
const load = useCallback(async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const result = await listProcessingRawPurchasesApi({ statusGroup: 'all' });
|
||||
const nextRows = result.data || [];
|
||||
setRows(nextRows);
|
||||
setDrafts((current) => {
|
||||
const next: Record<string, { qty: string; cost: string }> = {};
|
||||
for (const row of nextRows) next[row.id] = current[row.id] || { qty: String(row.planned_qty ?? ''), cost: String(row.unit_cost ?? '') };
|
||||
return next;
|
||||
});
|
||||
} catch (error: any) {
|
||||
notify.error(error?.message || t('purchase.rawMaterial.loadFail'));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [t]);
|
||||
|
||||
useEffect(() => { void load(); }, [load, refreshToken]);
|
||||
|
||||
const save = async (row: ProcessingRawPurchaseRow) => {
|
||||
const draft = drafts[row.id] || { qty: String(row.planned_qty), cost: String(row.unit_cost) };
|
||||
const qty = Number(draft.qty);
|
||||
const cost = draft.cost === '' ? undefined : Number(draft.cost);
|
||||
if (!(qty > 0)) { notify.error(t('purchase.rawMaterial.qtyRequired')); return; }
|
||||
setSavingId(row.id);
|
||||
try {
|
||||
await updateProcessingRawPurchaseApi(row.id, { planned_qty: qty, ...(cost !== undefined ? { unit_cost: cost } : {}) });
|
||||
notify.success(t('purchase.rawMaterial.saved'));
|
||||
await load();
|
||||
} catch (error: any) {
|
||||
notify.error(error?.message || t('purchase.rawMaterial.saveFail'));
|
||||
} finally { setSavingId(null); }
|
||||
};
|
||||
|
||||
const submit = async (row: ProcessingRawPurchaseRow) => {
|
||||
setSubmittingId(row.id);
|
||||
try {
|
||||
await submitProcessingRawPurchaseApi(row.id, { actual_qty: Number(drafts[row.id]?.qty ?? row.planned_qty), unit_cost: Number(drafts[row.id]?.cost ?? row.unit_cost) });
|
||||
notify.success(t('purchase.rawMaterial.submitted'));
|
||||
await load();
|
||||
} catch (error: any) {
|
||||
notify.error(error?.message || t('purchase.rawMaterial.submitFail'));
|
||||
} finally { setSubmittingId(null); }
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="app-surface app-border rounded-xl border p-4">
|
||||
<div className="mb-3 flex items-center justify-between gap-2">
|
||||
<div>
|
||||
<h2 className="text-base font-semibold">{t('purchase.rawMaterial.title')}</h2>
|
||||
<p className="mt-0.5 text-xs app-foreground-muted">{t('purchase.rawMaterial.hint')}</p>
|
||||
</div>
|
||||
<button type="button" onClick={() => void load()} disabled={loading} className="app-button-secondary inline-flex items-center gap-1 rounded-lg border px-3 py-1.5 text-sm disabled:opacity-50">
|
||||
<RefreshCw className={`h-4 w-4 ${loading ? 'animate-spin' : ''}`} />
|
||||
{t('common.refresh')}
|
||||
</button>
|
||||
</div>
|
||||
{rows.length === 0 ? <p className="py-6 text-center text-sm app-foreground-muted">{t('purchase.rawMaterial.empty')}</p> : (
|
||||
<div className="overflow-auto">
|
||||
<table className="min-w-full text-sm">
|
||||
<thead className="app-table-head"><tr>
|
||||
<th className="px-2 py-2 text-left">{t('purchase.rawMaterial.output')}</th>
|
||||
<th className="px-2 py-2 text-left">{t('purchase.rawMaterial.material')}</th>
|
||||
<th className="px-2 py-2 text-right">{t('purchase.rawMaterial.qty')}</th>
|
||||
<th className="px-2 py-2 text-right">{t('purchase.rawMaterial.cost')}</th>
|
||||
<th className="px-2 py-2 text-center">{t('purchase.rawMaterial.status')}</th>
|
||||
<th className="px-2 py-2 text-center">{t('purchase.rawMaterial.actions')}</th>
|
||||
</tr></thead>
|
||||
<tbody>
|
||||
{rows.map((row) => {
|
||||
const draft = drafts[row.id] || { qty: '', cost: '' };
|
||||
const editable = Number(row.purchase_status) === 10 || Number(row.purchase_status) === 20;
|
||||
return (
|
||||
<tr key={row.id} className="border-t app-border">
|
||||
<td className="px-2 py-2"><div className="font-medium">{row.output_name || row.output_sku}</div><div className="text-xs app-foreground-muted">{row.processing_method} · {row.task_code || '-'}</div></td>
|
||||
<td className="px-2 py-2"><div>{row.material_name || row.material_sku}</div><div className="text-xs app-foreground-muted">{row.unit || ''}</div></td>
|
||||
<td className="px-2 py-2 text-right">{editable ? <input type="number" min={0} step="0.001" value={draft.qty} onChange={(e) => setDrafts((prev) => ({ ...prev, [row.id]: { ...draft, qty: e.target.value } }))} className="app-input w-24 rounded border px-2 py-1 text-right" /> : row.planned_qty}</td>
|
||||
<td className="px-2 py-2 text-right">{editable ? <input type="number" min={0} step="0.0001" value={draft.cost} onChange={(e) => setDrafts((prev) => ({ ...prev, [row.id]: { ...draft, cost: e.target.value } }))} className="app-input w-24 rounded border px-2 py-1 text-right" /> : row.unit_cost}</td>
|
||||
<td className="px-2 py-2 text-center">{STATUS_LABEL[Number(row.purchase_status)] || row.purchase_status}</td>
|
||||
<td className="px-2 py-2"><div className="flex justify-center gap-1">
|
||||
{editable ? <button type="button" onClick={() => void save(row)} disabled={savingId === row.id} className="app-button-secondary inline-flex items-center gap-1 rounded border px-2 py-1 text-xs disabled:opacity-50"><Save className="h-3.5 w-3.5" />{t('common.save')}</button> : null}
|
||||
{Number(row.purchase_status) === 10 ? <button type="button" onClick={() => void submit(row)} disabled={submittingId === row.id} className="app-button-primary inline-flex items-center gap-1 rounded px-2 py-1 text-xs disabled:opacity-50"><Send className="h-3.5 w-3.5" />{t('purchase.rawMaterial.submit')}</button> : null}
|
||||
</div></td>
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import { ProcessingRawMaterialPanel } from '../../components/purchase/ProcessingRawMaterialPanel';
|
||||
import React, { startTransition, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import {
|
||||
Plus,
|
||||
@@ -2933,7 +2932,6 @@ export const PurchaseManagement: React.FC<PurchaseManagementProps> = ({
|
||||
|
||||
return (
|
||||
<div className="space-y-6 min-w-0">
|
||||
<ProcessingRawMaterialPanel />
|
||||
<div className="grid grid-cols-2 gap-3 sm:grid-cols-4 lg:gap-4">
|
||||
<StatusSummaryCard
|
||||
className="app-surface rounded-lg p-5 border app-border"
|
||||
|
||||
@@ -2205,64 +2205,6 @@ export async function deleteCompletedOrderProcessingTaskApi(taskId: string) {
|
||||
}
|
||||
|
||||
|
||||
export interface ProcessingRawPurchaseRow {
|
||||
id: string;
|
||||
purchase_code: string;
|
||||
branch_code: string;
|
||||
demand_task_id: string;
|
||||
task_code: string | null;
|
||||
output_sku: string;
|
||||
output_name: string | null;
|
||||
processing_method: string;
|
||||
material_sku: string;
|
||||
material_name: string | null;
|
||||
unit: string | null;
|
||||
planned_qty: number;
|
||||
actual_qty: number | null;
|
||||
unit_cost: number;
|
||||
total_amount: number;
|
||||
purchase_status: number;
|
||||
inspection_id: string | null;
|
||||
inventory_id: string | null;
|
||||
purchaser_code: string | null;
|
||||
purchaser_name: string | null;
|
||||
remark: string | null;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
}
|
||||
|
||||
export async function listProcessingRawPurchasesApi(options?: {
|
||||
statusGroup?: 'pending' | 'completed' | 'all' | null;
|
||||
search?: string;
|
||||
}) {
|
||||
const params = new URLSearchParams();
|
||||
if (options?.statusGroup) params.set('status_group', options.statusGroup);
|
||||
if (options?.search) params.set('search', options.search);
|
||||
const qs = params.toString();
|
||||
return workflowFetch<{ data: ProcessingRawPurchaseRow[] }>(
|
||||
`/purchase-orders/processing-raw-materials${qs ? `?${qs}` : ''}`
|
||||
);
|
||||
}
|
||||
|
||||
export async function updateProcessingRawPurchaseApi(
|
||||
id: string,
|
||||
body: { planned_qty?: number; unit_cost?: number; remark?: string }
|
||||
) {
|
||||
return workflowFetch<{ success: boolean }>(
|
||||
`/purchase-orders/processing-raw-materials/${encodeURIComponent(id)}`,
|
||||
{ method: 'PATCH', body: JSON.stringify(body) }
|
||||
);
|
||||
}
|
||||
|
||||
export async function submitProcessingRawPurchaseApi(
|
||||
id: string,
|
||||
body?: { actual_qty?: number; unit_cost?: number }
|
||||
) {
|
||||
return workflowFetch<{ success: boolean; data: { inspectionId: string; batchNo: string } }>(
|
||||
`/purchase-orders/processing-raw-materials/${encodeURIComponent(id)}/submit`,
|
||||
{ method: 'POST', body: JSON.stringify(body || {}) }
|
||||
);
|
||||
}
|
||||
export async function syncProcessingRawMaterialPurchasesApi(outputSku?: string) {
|
||||
return workflowFetch<{ data: { created: number; updated: number; cancelled: number; flagged: number } }>(
|
||||
'/purchase-orders/processing-raw-materials/sync',
|
||||
|
||||
Reference in New Issue
Block a user