feat(分拣): 显式结算方式与主系统计划同步状态
分拣支持按重量/按数量结算(数量模式要求订单单位=库存单位);出库按结算方式取量;订单详情展示主系统计划同步状态并支持重试。
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
-- 2026-11-02:分拣行显式结算方式。
|
||||
-- auto:沿用现有口径(库存单位是重量则优先实称重,否则数量)
|
||||
-- weight:按库存单位的实际称重结算
|
||||
-- count:按订单数量结算(仅允许订单单位=库存单位;库存按斤不能直接按个扣)
|
||||
DO $$
|
||||
DECLARE sch text;
|
||||
BEGIN
|
||||
FOR sch IN SELECT nspname FROM pg_namespace WHERE nspname='tenant_template' OR nspname LIKE 'tenant\_%' LOOP
|
||||
IF EXISTS (SELECT 1 FROM information_schema.tables WHERE table_schema=sch AND table_name='picking_items') THEN
|
||||
EXECUTE format('ALTER TABLE %I.picking_items ADD COLUMN IF NOT EXISTS settlement_mode VARCHAR(10) NOT NULL DEFAULT ''auto''', sch);
|
||||
EXECUTE format($c$COMMENT ON COLUMN %I.picking_items.settlement_mode IS '分拣结算方式:auto/weight/count;count 仅当订单单位与库存单位一致'$c$, sch);
|
||||
END IF;
|
||||
END LOOP;
|
||||
END $$;
|
||||
@@ -9,7 +9,7 @@ import { notifyInventoryShortage } from './inventoryShortageNotificationService'
|
||||
import { isPassThroughSku } from './stockModeService';
|
||||
import { skuDirectDeliveryAppliesSql } from './skuDirectDelivery';
|
||||
import { writeAuditLog } from './auditService';
|
||||
import { resolveCompleteReceivedSettlementQty } from './orderItemSupplyUnitSync';
|
||||
import { resolvePickingSettlementQtyByMode } from './orderItemSupplyUnitSync';
|
||||
// 批次选择排序:规格匹配优先 → 先入库先出(全系统唯一一份,禁止别处再写)
|
||||
import { batchSelectionOrderBy } from './inventoryBatchSelection';
|
||||
import { catalogSkuBySpecJoin } from './catalogSkuBySpec';
|
||||
@@ -543,7 +543,7 @@ export async function deductInventoryForOrderDeparture(
|
||||
|
||||
const itemsResult = await client.query(
|
||||
`SELECT pi.id, pi.order_item_id, pi.pick_code, pi.item_name, pi.sku_code, pi.unit,
|
||||
pi.loaded_qty, pi.picked_qty, pi.required_qty, pi.picked_weight,
|
||||
pi.loaded_qty, pi.picked_qty, pi.required_qty, pi.picked_weight, pi.settlement_mode,
|
||||
oi.sku_code AS order_sku,
|
||||
sku_dd.unit AS inventory_unit,
|
||||
catalog.code AS catalog_sku,
|
||||
@@ -613,12 +613,11 @@ export async function deductInventoryForOrderDeparture(
|
||||
// 数量与「计划量对齐 / 界面实收」同一口径(重量 → 真人改过的实配 → 实拣数量 → 镜像实配):
|
||||
// 斤类原来完全不看重量 ⇒ 出现「扣库按数量、计划量按重量」的错位,2026-10-15 统一。
|
||||
const qty =
|
||||
resolveCompleteReceivedSettlementQty(
|
||||
resolvePickingSettlementQtyByMode(
|
||||
row.settlement_mode,
|
||||
row.picked_qty ?? row.loaded_qty,
|
||||
row.picked_weight,
|
||||
row.loaded_qty,
|
||||
row.inventory_unit || row.unit,
|
||||
row.picked_qty,
|
||||
row.required_qty
|
||||
row.inventory_unit || row.unit
|
||||
) ||
|
||||
(options?.fallbackToRequiredQty ? Number(row.required_qty) || 0 : 0);
|
||||
if (qty <= 0) continue;
|
||||
@@ -945,7 +944,7 @@ async function planDeductLinesForOrder(
|
||||
}> {
|
||||
const loading = await client.query(
|
||||
`SELECT pi.id, pi.order_item_id, pi.pick_code, pi.item_name, pi.sku_code,
|
||||
pi.loaded_qty, pi.picked_qty, pi.required_qty, pi.unit, pi.picked_weight,
|
||||
pi.loaded_qty, pi.picked_qty, pi.required_qty, pi.unit, pi.picked_weight, pi.settlement_mode,
|
||||
oi.sku_code AS order_sku, catalog.code AS catalog_sku,
|
||||
sku_dd.unit AS inventory_unit,
|
||||
COALESCE(skip_sup.skip_inbound, false) AS skip_inbound,
|
||||
@@ -1005,12 +1004,11 @@ async function planDeductLinesForOrder(
|
||||
trimSku(row.sku_code) || trimSku(row.order_sku) || trimSku(row.catalog_sku);
|
||||
if (!sku) continue;
|
||||
const qty =
|
||||
resolveCompleteReceivedSettlementQty(
|
||||
resolvePickingSettlementQtyByMode(
|
||||
row.settlement_mode,
|
||||
row.picked_qty ?? row.loaded_qty,
|
||||
row.picked_weight,
|
||||
row.loaded_qty,
|
||||
row.inventory_unit || row.unit,
|
||||
row.picked_qty,
|
||||
row.required_qty
|
||||
row.inventory_unit || row.unit
|
||||
) || 0;
|
||||
if (qty <= 0) continue;
|
||||
const itemKey = trimSku(row.order_item_id) || String(row.id);
|
||||
|
||||
@@ -457,6 +457,37 @@ export async function syncOrderItemFromPickingComplete(
|
||||
return { orderCode };
|
||||
}
|
||||
|
||||
export type PickingSettlementMode = 'auto' | 'weight' | 'count';
|
||||
|
||||
/**
|
||||
* 显式结算方式(2026-11-02):
|
||||
* - auto:旧行为(重量单位优先实称重,否则数量)
|
||||
* - weight:按库存单位的实际称重;没有重量直接 0,不能回退成订单件数
|
||||
* - count:按订单数量;调用方必须先确认订单单位与库存单位一致,不能拿「个」扣「斤」
|
||||
*/
|
||||
export function resolvePickingSettlementQtyByMode(
|
||||
mode: unknown,
|
||||
pickedQty: unknown,
|
||||
pickedWeight: unknown,
|
||||
unit?: string | null
|
||||
): number | null {
|
||||
const normalized = String(mode || 'auto').trim() as PickingSettlementMode;
|
||||
if (normalized === 'weight') {
|
||||
const weight = Number(pickedWeight) || 0;
|
||||
return weight > 0 ? weight : null;
|
||||
}
|
||||
if (normalized === 'count') {
|
||||
const qty = Number(pickedQty) || 0;
|
||||
return qty > 0 ? qty : null;
|
||||
}
|
||||
return resolvePickingSettlementQty(pickedQty, pickedWeight, unit);
|
||||
}
|
||||
|
||||
export function normalizeSettlementMode(value: unknown): PickingSettlementMode {
|
||||
const mode = String(value || 'auto').trim().toLowerCase();
|
||||
return mode === 'weight' || mode === 'count' ? mode : 'auto';
|
||||
}
|
||||
|
||||
/**
|
||||
* 「实收量」统一口径(出库扣库存 / 计划量对齐 / 结案冻结 / 界面实收 共用一条规则):
|
||||
*
|
||||
|
||||
@@ -41,6 +41,8 @@ import {
|
||||
isPickingWeightUnit,
|
||||
normalizePickingSavedMeasures,
|
||||
resolvePickingSettlementQty,
|
||||
resolvePickingSettlementQtyByMode,
|
||||
normalizeSettlementMode,
|
||||
} from './orderItemSupplyUnitSync';
|
||||
import { assertOrderActiveForFulfillment, orderNotDeletedSql } from './orderTrashScope';
|
||||
import {
|
||||
@@ -60,6 +62,8 @@ type PickingProgressRow = {
|
||||
picked_qty: number;
|
||||
picked_weight?: number;
|
||||
diff_reason?: string;
|
||||
settlement_mode?: string | null;
|
||||
inventory_unit?: string | null;
|
||||
unit?: string | null;
|
||||
/** 手选出库批次计划(分拣完成时选定);不传=不动,[]/空=默认 FIFO */
|
||||
outbound_batches?: Array<{ batch_no: string; qty: number }> | null;
|
||||
@@ -1124,14 +1128,30 @@ export async function updatePickingItemProgress(input: {
|
||||
const pickedQty = Number(row.picked_qty) || 0;
|
||||
const pickedWeight = Number(row.picked_weight) || 0;
|
||||
const existing = await client.query(
|
||||
`SELECT unit, picked_qty, picked_weight, order_code
|
||||
FROM picking_items WHERE id = $1 AND pick_code = $2`,
|
||||
`SELECT pi.unit, pi.picked_qty, pi.picked_weight, pi.order_code,
|
||||
sku.unit AS inventory_unit
|
||||
FROM picking_items pi
|
||||
LEFT JOIN order_items oi ON oi.id = pi.order_item_id
|
||||
LEFT JOIN skus sku ON sku.sku_code = COALESCE(NULLIF(TRIM(pi.sku_code), ''), NULLIF(TRIM(oi.sku_code), ''))
|
||||
WHERE pi.id = $1 AND pi.pick_code = $2`,
|
||||
[row.id, input.pickCode]
|
||||
);
|
||||
const existingRow = existing.rows[0];
|
||||
let unit = String(row.unit || existingRow?.unit || '').trim() || null;
|
||||
const inventoryUnit = String(existingRow?.inventory_unit || unit || '').trim() || null;
|
||||
const settlementMode = normalizeSettlementMode(row.settlement_mode);
|
||||
if (settlementMode === 'weight' && !isPickingWeightUnit(inventoryUnit)) {
|
||||
throw Object.assign(new Error('该商品库存单位不是重量单位,不能按重量结算'), { status: 400, code: 'settlement_weight_invalid' });
|
||||
}
|
||||
if (settlementMode === 'count' && unit && inventoryUnit && unit.trim().toLowerCase() !== inventoryUnit.trim().toLowerCase()) {
|
||||
throw Object.assign(
|
||||
new Error(`订单单位「${unit}」与库存单位「${inventoryUnit}」不一致;按数量结算前请先修改库存单位`),
|
||||
{ status: 409, code: 'settlement_unit_mismatch' }
|
||||
);
|
||||
}
|
||||
const saved = normalizePickingSavedMeasures(pickedQty, pickedWeight, unit);
|
||||
const settlement = resolvePickingSettlementQty(saved.picked_qty, saved.picked_weight, unit);
|
||||
const settlement =
|
||||
resolvePickingSettlementQtyByMode(settlementMode, saved.picked_qty, saved.picked_weight, inventoryUnit || unit) || 0;
|
||||
if (settlement <= 0) {
|
||||
throw Object.assign(new Error('实拣数量/重量必须大于 0,不能按 0 确认分拣'), { status: 400 });
|
||||
}
|
||||
@@ -1160,6 +1180,7 @@ export async function updatePickingItemProgress(input: {
|
||||
`UPDATE picking_items
|
||||
SET picked_qty = $1, picked_weight = $2, review_status = $3, diff_reason = $4,
|
||||
unit = COALESCE($7::varchar, unit),
|
||||
settlement_mode = $9,
|
||||
outbound_batches = COALESCE($8::jsonb, outbound_batches)
|
||||
WHERE id = $5 AND pick_code = $6`,
|
||||
[
|
||||
@@ -1173,6 +1194,7 @@ export async function updatePickingItemProgress(input: {
|
||||
row.outbound_batches !== undefined
|
||||
? JSON.stringify(normalizeOutboundBatches(row.outbound_batches) || [])
|
||||
: null,
|
||||
settlementMode,
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -1638,8 +1660,20 @@ export async function confirmPickingComplete(input: {
|
||||
const pickedQty = Number(row.picked_qty) || 0;
|
||||
const pickedWeight = Number(row.picked_weight) || 0;
|
||||
const unit = String(row.unit || '').trim() || null;
|
||||
const inventoryUnit = String(row.inventory_unit || unit || '').trim() || null;
|
||||
const settlementMode = normalizeSettlementMode(row.settlement_mode);
|
||||
if (settlementMode === 'weight' && !isPickingWeightUnit(inventoryUnit)) {
|
||||
throw Object.assign(new Error('该商品库存单位不是重量单位,不能按重量结算'), { status: 400, code: 'settlement_weight_invalid' });
|
||||
}
|
||||
if (settlementMode === 'count' && unit && inventoryUnit && unit.trim().toLowerCase() !== inventoryUnit.trim().toLowerCase()) {
|
||||
throw Object.assign(
|
||||
new Error(`订单单位「${unit}」与库存单位「${inventoryUnit}」不一致;按数量结算前请先修改库存单位`),
|
||||
{ status: 409, code: 'settlement_unit_mismatch' }
|
||||
);
|
||||
}
|
||||
const saved = normalizePickingSavedMeasures(pickedQty, pickedWeight, unit);
|
||||
const settlement = resolvePickingSettlementQty(saved.picked_qty, saved.picked_weight, unit);
|
||||
const settlement =
|
||||
resolvePickingSettlementQtyByMode(settlementMode, saved.picked_qty, saved.picked_weight, inventoryUnit || unit) || 0;
|
||||
if (settlement <= 0) {
|
||||
throw Object.assign(new Error('实拣数量/重量必须大于 0,不能按 0 完成分拣'), { status: 400 });
|
||||
}
|
||||
@@ -1652,6 +1686,7 @@ export async function confirmPickingComplete(input: {
|
||||
`UPDATE picking_items
|
||||
SET picked_qty = $1, picked_weight = $2, review_status = $3, diff_reason = $4,
|
||||
unit = COALESCE($7::varchar, unit),
|
||||
settlement_mode = $10,
|
||||
outbound_batches = COALESCE($8::jsonb, outbound_batches),
|
||||
outbound_photos = COALESCE($9::text[], outbound_photos)
|
||||
WHERE id = $5 AND pick_code = $6`,
|
||||
@@ -1667,6 +1702,7 @@ export async function confirmPickingComplete(input: {
|
||||
? JSON.stringify(normalizeOutboundBatches(row.outbound_batches) || [])
|
||||
: null,
|
||||
rowPhotos.length ? rowPhotos : null,
|
||||
settlementMode,
|
||||
]
|
||||
);
|
||||
}
|
||||
@@ -1679,7 +1715,7 @@ export async function confirmPickingComplete(input: {
|
||||
* 已拣/已核货的行照旧校验(历史事故:分拣完成会把实拣量写成结算量,不能漏行)。
|
||||
*/
|
||||
`SELECT pi.id, pi.order_item_id, pi.item_name, pi.required_qty, pi.picked_qty, pi.picked_weight,
|
||||
pi.review_status, pi.unit, pi.order_code,
|
||||
pi.review_status, pi.unit, pi.order_code, pi.settlement_mode,
|
||||
s.unit AS inventory_unit
|
||||
FROM picking_items pi
|
||||
LEFT JOIN order_items oi ON oi.id = pi.order_item_id
|
||||
@@ -1809,6 +1845,7 @@ export async function confirmPickingComplete(input: {
|
||||
for (const row of items.rows) {
|
||||
const inventoryUnit = String(row.inventory_unit || '').trim();
|
||||
if (
|
||||
String(row.settlement_mode || '') === 'count' ||
|
||||
!inventoryUnit ||
|
||||
!isPickingWeightUnit(inventoryUnit) ||
|
||||
isPickingWeightUnit(row.unit) ||
|
||||
@@ -2285,8 +2322,13 @@ export async function completePickingOutbound(input: {
|
||||
(row: { outbound_at?: string | null }) => !row.outbound_at
|
||||
);
|
||||
/** 库存扣减口径:优先 SKU 库存单位;订单单位/个不能直接当斤。 */
|
||||
const pickingSettlement = (row: { picked_qty?: unknown; picked_weight?: unknown; unit?: unknown; inventory_unit?: unknown }) =>
|
||||
resolvePickingSettlementQty(row.picked_qty, row.picked_weight, String(row.inventory_unit || row.unit || ''));
|
||||
const pickingSettlement = (row: { picked_qty?: unknown; picked_weight?: unknown; unit?: unknown; inventory_unit?: unknown; settlement_mode?: unknown }) =>
|
||||
resolvePickingSettlementQtyByMode(
|
||||
row.settlement_mode,
|
||||
row.picked_qty,
|
||||
row.picked_weight,
|
||||
String(row.inventory_unit || row.unit || '')
|
||||
) || 0;
|
||||
const warehousePending = pendingRows.filter(
|
||||
(row: { is_extra_dish?: unknown; order_status?: unknown }) =>
|
||||
!isTruthyFlag(row.is_extra_dish) && Number(row.order_status) < 50
|
||||
@@ -2593,11 +2635,13 @@ export async function outboundPickingByContainer(input: {
|
||||
const skipWarehouse =
|
||||
isTruthyFlag(item.is_extra_dish) || Number(item.order_status) >= 50;
|
||||
|
||||
const outboundQty = resolvePickingSettlementQty(
|
||||
item.picked_qty,
|
||||
item.picked_weight,
|
||||
String(item.inventory_unit || item.unit || '')
|
||||
);
|
||||
const outboundQty =
|
||||
resolvePickingSettlementQtyByMode(
|
||||
item.settlement_mode,
|
||||
item.picked_qty,
|
||||
item.picked_weight,
|
||||
String(item.inventory_unit || item.unit || '')
|
||||
) || 0;
|
||||
if (!skipWarehouse && outboundQty <= 0) {
|
||||
throw businessError('该件实拣数量/重量为 0,不能出库');
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import {
|
||||
normalizeSettlementMode,
|
||||
resolvePickingSettlementQtyByMode,
|
||||
} from '../src/services/orderItemSupplyUnitSync';
|
||||
|
||||
const read = (rel: string) => readFileSync(new URL(`../${rel}`, import.meta.url), 'utf8');
|
||||
|
||||
describe('分拣结算方式', () => {
|
||||
it('weight 只按实际称重,不从数量回退', () => {
|
||||
expect(resolvePickingSettlementQtyByMode('weight', 70, 30, '斤')).toBe(30);
|
||||
expect(resolvePickingSettlementQtyByMode('weight', 70, 0, '斤')).toBeNull();
|
||||
});
|
||||
|
||||
it('count 只按数量;单位不一致必须由调用方先拦截', () => {
|
||||
expect(resolvePickingSettlementQtyByMode('count', 70, 30, '斤')).toBe(70);
|
||||
expect(resolvePickingSettlementQtyByMode('count', 0, 30, '斤')).toBeNull();
|
||||
expect(normalizeSettlementMode('COUNT')).toBe('count');
|
||||
expect(normalizeSettlementMode('bad')).toBe('auto');
|
||||
});
|
||||
|
||||
it('auto 保留旧口径:重量优先', () => {
|
||||
expect(resolvePickingSettlementQtyByMode('auto', 70, 30, '斤')).toBe(30);
|
||||
expect(resolvePickingSettlementQtyByMode('auto', 70, 0, '个')).toBe(70);
|
||||
});
|
||||
|
||||
it('后端保存/出库/页面都接收 settlement_mode', () => {
|
||||
expect(read('src/services/pickingService.ts')).toContain('settlement_mode');
|
||||
expect(read('src/services/inventoryOutboundService.ts')).toContain('pi.settlement_mode');
|
||||
expect(
|
||||
readFileSync(new URL('../../src/pages/picking/PickingManagement.tsx', import.meta.url), 'utf8')
|
||||
).toContain('settlement_mode');
|
||||
});
|
||||
});
|
||||
@@ -72,13 +72,13 @@ describe('出库扣库存与计划量对齐同源(原来扣库完全不看重
|
||||
it('出库扣库量改调同一口径函数,并查了 picked_weight', () => {
|
||||
const outbound = read('../src/services/inventoryOutboundService.ts');
|
||||
expect(outbound).toContain(
|
||||
"import { resolveCompleteReceivedSettlementQty } from './orderItemSupplyUnitSync';"
|
||||
"import { resolvePickingSettlementQtyByMode } from './orderItemSupplyUnitSync';"
|
||||
);
|
||||
// 两处调用(出库 + 发车/结案补扣),加 import 共 3 次出现
|
||||
expect(outbound.match(/resolveCompleteReceivedSettlementQty/g)?.length).toBe(3);
|
||||
expect(outbound.match(/resolveCompleteReceivedSettlementQty\(/g)?.length).toBe(2);
|
||||
expect(outbound).toContain('pi.loaded_qty, pi.picked_qty, pi.required_qty, pi.picked_weight,');
|
||||
expect(outbound).toContain('pi.loaded_qty, pi.picked_qty, pi.required_qty, pi.unit, pi.picked_weight,');
|
||||
expect(outbound.match(/resolvePickingSettlementQtyByMode/g)?.length).toBe(3);
|
||||
expect(outbound.match(/resolvePickingSettlementQtyByMode\(/g)?.length).toBe(2);
|
||||
expect(outbound).toContain('pi.loaded_qty, pi.picked_qty, pi.required_qty, pi.picked_weight, pi.settlement_mode,');
|
||||
expect(outbound).toContain('pi.loaded_qty, pi.picked_qty, pi.required_qty, pi.unit, pi.picked_weight, pi.settlement_mode,');
|
||||
expect(outbound).not.toContain('const qty = loaded > 0 ? loaded : picked > 0 ? picked : 0;');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -363,6 +363,17 @@ export const orders: MessageDict = {
|
||||
'retailCreated': 'Walk-in sale order created: {{code}} (stock fully deducted; confirm it in Order Management)',
|
||||
'retailSubmitFail': 'Walk-in sale entry failed',
|
||||
'retailConfirmFail': 'Confirm failed',
|
||||
'detail.planSyncTitle': 'Main system plan sync',
|
||||
'detail.planSyncRetry': 'Retry sync',
|
||||
'detail.planSyncRetrying': 'Syncing…',
|
||||
'detail.planSyncRetried': 'Sync retry started',
|
||||
'detail.planSyncRetryFail': 'Sync retry failed',
|
||||
'detail.planSyncStatus.pending': 'Pending',
|
||||
'detail.planSyncStatus.syncing': 'Syncing',
|
||||
'detail.planSyncStatus.synced': 'Synced',
|
||||
'detail.planSyncStatus.failed': 'Failed',
|
||||
'detail.planSyncStatus.conflict': 'Conflict',
|
||||
'detail.planSyncStatus.skipped': 'Skipped',
|
||||
'detail.title': 'Order details',
|
||||
'detail.sheetTitle': 'Fresh delivery note',
|
||||
'detail.docDate': 'Document date: ',
|
||||
|
||||
@@ -284,6 +284,10 @@ export const picking: MessageDict = {
|
||||
'toast.staged': 'Staged: {code}',
|
||||
'toast.stageOk': 'Container staged: {code}',
|
||||
'toast.stageFail': 'Staging failed',
|
||||
'settlement.label': 'Settle by',
|
||||
'settlement.weight': 'By weight ({unit})',
|
||||
'settlement.count': 'By quantity ({unit})',
|
||||
'settlement.countNeedsSameUnit': 'Order unit and stock unit differ; change the stock unit before settling by quantity',
|
||||
'toast.alreadyDone': 'This list is already completed',
|
||||
'toast.noItems': 'No pick line items',
|
||||
'toast.needWeight': 'Picking weigh-in is on; {count} weight-unit items still missing picked weight',
|
||||
|
||||
@@ -363,6 +363,17 @@ export const orders: MessageDict = {
|
||||
'retailCreated': 'Pesanan eceran dibuat: {{code}} (stok sudah dipotong penuh; konfirmasi di Manajemen Pesanan)',
|
||||
'retailSubmitFail': 'Entri penjualan eceran gagal',
|
||||
'retailConfirmFail': 'Konfirmasi gagal',
|
||||
'detail.planSyncTitle': 'Sinkronisasi rencana sistem utama',
|
||||
'detail.planSyncRetry': 'Coba sinkron lagi',
|
||||
'detail.planSyncRetrying': 'Menyinkronkan…',
|
||||
'detail.planSyncRetried': 'Percobaan sinkron dimulai',
|
||||
'detail.planSyncRetryFail': 'Percobaan sinkron gagal',
|
||||
'detail.planSyncStatus.pending': 'Menunggu',
|
||||
'detail.planSyncStatus.syncing': 'Menyinkronkan',
|
||||
'detail.planSyncStatus.synced': 'Tersinkron',
|
||||
'detail.planSyncStatus.failed': 'Gagal',
|
||||
'detail.planSyncStatus.conflict': 'Konflik',
|
||||
'detail.planSyncStatus.skipped': 'Dilewati',
|
||||
'detail.title': 'Detail pesanan',
|
||||
'detail.sheetTitle': 'Surat jalan segar',
|
||||
'detail.docDate': 'Tanggal dokumen: ',
|
||||
|
||||
@@ -284,6 +284,10 @@ export const picking: MessageDict = {
|
||||
'toast.staged': 'Masuk keranjang: {code}',
|
||||
'toast.stageOk': 'Keranjang berhasil: {code}',
|
||||
'toast.stageFail': 'Gagal masuk keranjang',
|
||||
'settlement.label': 'Settle',
|
||||
'settlement.weight': 'Berdasarkan berat ({unit})',
|
||||
'settlement.count': 'Berdasarkan jumlah ({unit})',
|
||||
'settlement.countNeedsSameUnit': 'Satuan pesanan dan stok berbeda; ubah satuan stok sebelum menyelesaikan berdasarkan jumlah',
|
||||
'toast.alreadyDone': 'Daftar ini sudah selesai sortir',
|
||||
'toast.noItems': 'Tidak ada detail sortir',
|
||||
'toast.needWeight': 'Timbang sortir aktif; masih {count} item satuan berat belum isi berat diambil',
|
||||
|
||||
@@ -356,6 +356,17 @@ export const orders: MessageDict = {
|
||||
'retailCreated': '散客单已创建:{{code}}(已全额库存抵扣,可在订单管理点「确认完成」)',
|
||||
'retailSubmitFail': '散客录单失败',
|
||||
'retailConfirmFail': '确认完成失败',
|
||||
'detail.planSyncTitle': '主系统备货计划同步',
|
||||
'detail.planSyncRetry': '重试同步',
|
||||
'detail.planSyncRetrying': '同步中…',
|
||||
'detail.planSyncRetried': '已触发同步重试',
|
||||
'detail.planSyncRetryFail': '同步重试失败',
|
||||
'detail.planSyncStatus.pending': '待同步',
|
||||
'detail.planSyncStatus.syncing': '同步中',
|
||||
'detail.planSyncStatus.synced': '已同步',
|
||||
'detail.planSyncStatus.failed': '同步失败',
|
||||
'detail.planSyncStatus.conflict': '冲突',
|
||||
'detail.planSyncStatus.skipped': '已跳过',
|
||||
'detail.title': '订单详情',
|
||||
'detail.sheetTitle': '生鲜配送单',
|
||||
'detail.docDate': '单据日期:',
|
||||
|
||||
@@ -277,6 +277,10 @@ export const picking: MessageDict = {
|
||||
'toast.staged': '已装框:{code}',
|
||||
'toast.stageOk': '装框成功:{code}',
|
||||
'toast.stageFail': '装框失败',
|
||||
'settlement.label': '结算',
|
||||
'settlement.weight': '按重量({unit})',
|
||||
'settlement.count': '按数量({unit})',
|
||||
'settlement.countNeedsSameUnit': '订单单位与库存单位不一致,需先修改库存单位后再按数量结算',
|
||||
'toast.alreadyDone': '该单已完成分拣',
|
||||
'toast.noItems': '没有分拣明细',
|
||||
'toast.needWeight': '已开启分拣称重,还有 {count} 项重量单位未录入实拣重量',
|
||||
|
||||
@@ -65,6 +65,11 @@ import {
|
||||
import { fetchPrimaryPurchaserForBranch } from '../../../utils/purchaserAssignment';
|
||||
import { loadAllocationRules } from '../../../utils/loadAllocationRules';
|
||||
import { fetchSmartAllocationConfigApi } from '../../../utils/workflowApi';
|
||||
import {
|
||||
listMainSystemPlanChangesApi,
|
||||
retryMainSystemPlanChangesApi,
|
||||
type MainSystemPlanChangeRow,
|
||||
} from '../../../utils/workflowApi';
|
||||
import { formatOrderStatusLabel } from '../../../utils/orderStatusLabels';
|
||||
import { updateProductCatalogCategory, createCatalogProductForOrderLine, createQuickCatalogCategory } from '../../../utils/productCatalog';
|
||||
import { loadDirectDeliverySkuSetClient } from '../../../utils/skuDirectDelivery';
|
||||
@@ -183,6 +188,8 @@ import { buildOrdersListParams, resolveOrderManagementStatusGroup } from './useO
|
||||
import { parseCustomerCodes, serializeCustomerCodesParam } from '../../../utils/customerCodes';
|
||||
import { displayCustomerDeliveryDeadline } from '../../../utils/customerDeliveryDeadline';
|
||||
import { OrderManagementModals } from './OrderManagementModals';
|
||||
import { isUiPreviewMode } from '../../../preview/previewMode';
|
||||
import { installPreviewLoadingFallback } from '../../../preview/previewLoadingFallback';
|
||||
import { matchDraftItem, registerCopilotPage } from '../../../copilot/copilotPageBus';
|
||||
|
||||
/** 下拉宽度按文案估算,并预留搜索图标 + 箭头,避免「全部状态」被裁切 */
|
||||
@@ -367,6 +374,8 @@ export const OrderManagement: React.FC = () => {
|
||||
const [sortOrder, setSortOrder] = useState<'asc' | 'desc'>('desc');
|
||||
const ordersFetchGenerationRef = useRef(0);
|
||||
|
||||
const [planChanges, setPlanChanges] = useState<MainSystemPlanChangeRow[]>([]);
|
||||
const [planSyncing, setPlanSyncing] = useState(false);
|
||||
const [showDetailModal, setShowDetailModal] = useState(false);
|
||||
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
|
||||
/**
|
||||
@@ -2813,6 +2822,41 @@ export const OrderManagement: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!showDetailModal || !selectedOrder?.order_code) {
|
||||
setPlanChanges([]);
|
||||
return;
|
||||
}
|
||||
let cancelled = false;
|
||||
listMainSystemPlanChangesApi(selectedOrder.order_code)
|
||||
.then((rows) => {
|
||||
if (!cancelled) setPlanChanges(Array.isArray(rows) ? rows : []);
|
||||
})
|
||||
.catch(() => {
|
||||
if (!cancelled) setPlanChanges([]);
|
||||
});
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [showDetailModal, selectedOrder?.order_code]);
|
||||
|
||||
const retryPlanSync = async () => {
|
||||
if (planSyncing) return;
|
||||
setPlanSyncing(true);
|
||||
try {
|
||||
await retryMainSystemPlanChangesApi(20);
|
||||
if (selectedOrder?.order_code) {
|
||||
const rows = await listMainSystemPlanChangesApi(selectedOrder.order_code);
|
||||
setPlanChanges(Array.isArray(rows) ? rows : []);
|
||||
}
|
||||
notify.success(t('orders.detail.planSyncRetried'));
|
||||
} catch (error) {
|
||||
notify.error(error instanceof Error ? error.message : t('orders.detail.planSyncRetryFail'));
|
||||
} finally {
|
||||
setPlanSyncing(false);
|
||||
}
|
||||
};
|
||||
|
||||
const openOrderDetail = async (order: Order) => {
|
||||
if (showDetailModal && selectedOrder?.order_code === order.order_code) {
|
||||
closeDetailModal();
|
||||
@@ -2826,6 +2870,14 @@ export const OrderManagement: React.FC = () => {
|
||||
setShowDetailModal(true);
|
||||
setDetailCategoryFilter(null);
|
||||
setOrderItemsLoading(true);
|
||||
// U15:预览模式兜底 —— 详情打开 1.5s 仍未收尾则强制清 loading(渲染已有 fixture/空态)
|
||||
if (isUiPreviewMode()) {
|
||||
installPreviewLoadingFallback({
|
||||
isActive: () => isActiveDetailLoad(generation, order.order_code),
|
||||
clear: () => setOrderItemsLoading(false),
|
||||
timeoutMs: 1500,
|
||||
});
|
||||
}
|
||||
|
||||
const { data: freshOrder, error: freshOrderError } = await supabase
|
||||
.from('orders')
|
||||
@@ -2833,7 +2885,10 @@ export const OrderManagement: React.FC = () => {
|
||||
.eq('order_code', order.order_code)
|
||||
.maybeSingle();
|
||||
|
||||
if (!isActiveDetailLoad(generation, order.order_code)) return;
|
||||
if (!isActiveDetailLoad(generation, order.order_code)) {
|
||||
setOrderItemsLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (freshOrderError || !freshOrder) {
|
||||
setShowDetailModal(false);
|
||||
@@ -2852,7 +2907,10 @@ export const OrderManagement: React.FC = () => {
|
||||
branchName = branchRow?.branch_name;
|
||||
}
|
||||
|
||||
if (!isActiveDetailLoad(generation, order.order_code)) return;
|
||||
if (!isActiveDetailLoad(generation, order.order_code)) {
|
||||
setOrderItemsLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const orderDeliveryAddress = String(order.delivery_address || '').trim();
|
||||
const freshDeliveryAddress = String(
|
||||
@@ -2893,7 +2951,10 @@ export const OrderManagement: React.FC = () => {
|
||||
'';
|
||||
}
|
||||
|
||||
if (!isActiveDetailLoad(generation, order.order_code)) return;
|
||||
if (!isActiveDetailLoad(generation, order.order_code)) {
|
||||
setOrderItemsLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const normalizedOrder: Order = {
|
||||
// 以「列表行」为基底:保住接口算出来的字段(is_main_system_order / is_skip_inbound /
|
||||
@@ -2960,8 +3021,9 @@ export const OrderManagement: React.FC = () => {
|
||||
}
|
||||
})();
|
||||
} finally {
|
||||
// U15:属于本次打开的加载必须收尾(即使谓词因时序/关闭而为 false 也不允许无限 loading)
|
||||
if (detailLoadGenerationRef.current === generation) setOrderItemsLoading(false);
|
||||
if (isActiveDetailLoad(generation, order.order_code)) {
|
||||
setOrderItemsLoading(false);
|
||||
requestAnimationFrame(() => {
|
||||
document
|
||||
.getElementById(`order-detail-panel-${order.order_code}`)
|
||||
@@ -4523,6 +4585,42 @@ export const OrderManagement: React.FC = () => {
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{planChanges.length > 0 ? (
|
||||
<div className="mb-4 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="font-medium text-amber-900">{t('orders.detail.planSyncTitle')}</span>
|
||||
{planChanges.slice(0, 3).map((row) => (
|
||||
<span
|
||||
key={row.id}
|
||||
className={`rounded-full px-2 py-0.5 text-xs ${
|
||||
row.status === 'synced'
|
||||
? 'bg-emerald-100 text-emerald-800'
|
||||
: row.status === 'failed' || row.status === 'conflict'
|
||||
? 'bg-red-100 text-red-800'
|
||||
: 'bg-amber-100 text-amber-800'
|
||||
}`}
|
||||
title={row.last_error || undefined}
|
||||
>
|
||||
{row.before_qty}{row.before_unit} → {row.after_qty}{row.after_unit} · {t(`orders.detail.planSyncStatus.${row.status}`)}
|
||||
</span>
|
||||
))}
|
||||
{planChanges[0]?.status === 'pending' || planChanges[0]?.status === 'failed' || planChanges[0]?.status === 'conflict' ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => void retryPlanSync()}
|
||||
disabled={planSyncing}
|
||||
className="ml-auto rounded border border-amber-300 px-2 py-1 text-xs text-amber-900 hover:bg-amber-100 disabled:opacity-50"
|
||||
>
|
||||
{planSyncing ? t('orders.detail.planSyncRetrying') : t('orders.detail.planSyncRetry')}
|
||||
</button>
|
||||
) : null}
|
||||
</div>
|
||||
{planChanges[0]?.last_error ? (
|
||||
<div className="mt-1 text-xs text-red-700">{planChanges[0].last_error}</div>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<OrderDetailDeliveryNotePanel
|
||||
orderCode={selectedOrder.order_code}
|
||||
customerName={selectedOrder.company_name}
|
||||
|
||||
@@ -114,12 +114,30 @@ const pickingMeasureUnit = (item: Pick<PickingItemRow, 'unit' | 'inventory_unit'
|
||||
return String(item.inventory_unit || item.unit || '').trim();
|
||||
};
|
||||
|
||||
const pickingUnitsDiffer = (item: Pick<PickingItemRow, 'unit' | 'inventory_unit'>): boolean => {
|
||||
const orderUnit = String(item.unit || '').trim().toLowerCase();
|
||||
const inventoryUnit = String(item.inventory_unit || '').trim().toLowerCase();
|
||||
return Boolean(orderUnit && inventoryUnit && orderUnit !== inventoryUnit);
|
||||
};
|
||||
|
||||
const defaultSettlementMode = (
|
||||
item: Pick<PickingItemRow, 'unit' | 'inventory_unit' | 'settlement_mode'>
|
||||
): 'auto' | 'weight' | 'count' => {
|
||||
const saved = String(item.settlement_mode || '').trim();
|
||||
if (saved === 'weight' || saved === 'count') return saved;
|
||||
if (pickingUnitsDiffer(item) && isPickingWeightUnit(item.inventory_unit)) return 'weight';
|
||||
return 'auto';
|
||||
};
|
||||
|
||||
const pickingMustWeigh = (
|
||||
item: Pick<PickingItemRow, 'unit' | 'inventory_unit'>,
|
||||
scaleRequired: boolean
|
||||
scaleRequired: boolean,
|
||||
mode: 'auto' | 'weight' | 'count' = 'auto'
|
||||
): boolean => {
|
||||
if (mode === 'count') return false;
|
||||
const inventoryUnit = pickingMeasureUnit(item);
|
||||
if (!isPickingWeightUnit(inventoryUnit)) return false;
|
||||
if (mode === 'weight') return true;
|
||||
// 库存按重量管理,且订单单位不是重量单位时,必须称重;同单位沿用原有 scale 开关。
|
||||
return scaleRequired || !isPickingWeightUnit(item.unit);
|
||||
};
|
||||
@@ -460,6 +478,7 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
|
||||
const [taskItems, setTaskItems] = useState<PickingItemRow[]>([]);
|
||||
const [draftQty, setDraftQty] = useState<Record<string, string>>({});
|
||||
const [draftWeight, setDraftWeight] = useState<Record<string, string>>({});
|
||||
const [draftSettlement, setDraftSettlement] = useState<Record<string, 'auto' | 'weight' | 'count'>>({});
|
||||
const [batchInfo, setBatchInfo] = useState<
|
||||
Record<string, { loading: boolean; error?: string; data: PickingOutboundBatches | null }>
|
||||
>({});
|
||||
@@ -1086,6 +1105,9 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
|
||||
setDraftWeight(
|
||||
Object.fromEntries(rows.map((row) => [row.id, String(row.picked_weight ?? 0)]))
|
||||
);
|
||||
setDraftSettlement(
|
||||
Object.fromEntries(rows.map((row) => [row.id, defaultSettlementMode(row)])) as Record<string, 'auto' | 'weight' | 'count'>
|
||||
);
|
||||
setPrintSelectedIds({});
|
||||
void refreshPrintContext(task.pick_code);
|
||||
};
|
||||
@@ -1244,9 +1266,15 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
|
||||
}
|
||||
};
|
||||
|
||||
const settlementQtyOf = (itemId: string, item: PickingItemRow) => {
|
||||
const settlementQtyOf = (
|
||||
itemId: string,
|
||||
item: PickingItemRow,
|
||||
mode: 'auto' | 'weight' | 'count' = 'auto'
|
||||
) => {
|
||||
const weight = Number(draftWeight[itemId] ?? item.picked_weight ?? 0) || 0;
|
||||
const qty = Number(draftQty[itemId] ?? item.picked_qty ?? 0) || 0;
|
||||
if (mode === 'count') return qty;
|
||||
if (mode === 'weight') return weight;
|
||||
return weight > 0 ? weight : qty;
|
||||
};
|
||||
|
||||
@@ -1259,7 +1287,7 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
|
||||
if (saved.length) return saved;
|
||||
const batches = batchInfo[item.id]?.data?.batches;
|
||||
if (batches && batches.length) {
|
||||
const need = settlementQtyOf(item.id, item);
|
||||
const need = settlementQtyOf(item.id, item, draftSettlement[item.id] || defaultSettlementMode(item));
|
||||
if (need > 0) {
|
||||
const plan = fifoAllocateBatches(batches, need).plan;
|
||||
if (plan.length) return plan;
|
||||
@@ -1274,7 +1302,7 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
|
||||
const manual = manualPlan[item.id];
|
||||
const batches = batchInfo[item.id]?.data?.batches || [];
|
||||
const saved = normalizeSavedPlan(item.outbound_batches);
|
||||
const need = settlementQtyOf(item.id, item);
|
||||
const need = settlementQtyOf(item.id, item, draftSettlement[item.id] || defaultSettlementMode(item));
|
||||
let plan: BatchPlanEntry[] = [];
|
||||
let shortfall = 0;
|
||||
if (manual && manual.length) {
|
||||
@@ -1353,7 +1381,7 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
|
||||
const item = taskItems.find((row) => row.id === batchEditorItemId);
|
||||
const data = batchEditorItemId ? batchInfo[batchEditorItemId]?.data : null;
|
||||
if (!item || !data) return;
|
||||
const { plan } = fifoAllocateBatches(data.batches, settlementQtyOf(item.id, item));
|
||||
const { plan } = fifoAllocateBatches(data.batches, settlementQtyOf(item.id, item, draftSettlement[item.id] || defaultSettlementMode(item)));
|
||||
const qtyByNo = new Map(plan.map((p) => [p.batch_no, p.qty]));
|
||||
setBatchEditorRows(
|
||||
(data.batches || []).map((b) => ({
|
||||
@@ -1373,7 +1401,7 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
|
||||
const applyBatchEditor = () => {
|
||||
if (!batchEditorItemId) return;
|
||||
const item = taskItems.find((row) => row.id === batchEditorItemId);
|
||||
const need = item ? settlementQtyOf(item.id, item) : 0;
|
||||
const need = item ? settlementQtyOf(item.id, item, draftSettlement[item.id] || defaultSettlementMode(item)) : 0;
|
||||
const total = batchEditorRows.reduce((sum, row) => sum + (Number(row.qty) || 0), 0);
|
||||
// 超量只提醒、不拦截:整件/不可拆分货物可能必须多取,计划合计允许超过实拣量
|
||||
if (total - (Number(need) || 0) > 1e-6) {
|
||||
@@ -1399,13 +1427,17 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
|
||||
taskItems.map((item) => {
|
||||
const pickedQty = Number(draftQty[item.id] ?? item.picked_qty ?? 0) || 0;
|
||||
const pickedWeight = Number(draftWeight[item.id] ?? item.picked_weight ?? 0) || 0;
|
||||
const settlement = pickedWeight > 0 ? pickedWeight : pickedQty;
|
||||
const mode = draftSettlement[item.id] || defaultSettlementMode(item);
|
||||
const settlement =
|
||||
mode === 'count' ? pickedQty : mode === 'weight' ? pickedWeight : pickedWeight > 0 ? pickedWeight : pickedQty;
|
||||
return {
|
||||
id: item.id,
|
||||
required_qty: Number(item.required_qty) || 0,
|
||||
picked_qty: pickedQty,
|
||||
picked_weight: pickedWeight,
|
||||
settlement_mode: mode,
|
||||
unit: item.unit || '',
|
||||
inventory_unit: item.inventory_unit || '',
|
||||
diff_reason:
|
||||
Math.abs(settlement - Number(item.required_qty || 0)) < 0.0001
|
||||
? ''
|
||||
@@ -1452,6 +1484,8 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
|
||||
required_qty: Number(item.required_qty) || 0,
|
||||
picked_qty: Number(item.required_qty) || 0,
|
||||
picked_weight: Number(draftWeight[item.id] ?? item.picked_weight ?? 0) || 0,
|
||||
settlement_mode: draftSettlement[item.id] || defaultSettlementMode(item),
|
||||
inventory_unit: item.inventory_unit || '',
|
||||
diff_reason: '',
|
||||
outbound_batches: resolveItemPlan(item) || undefined,
|
||||
})),
|
||||
@@ -1506,7 +1540,7 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
|
||||
|
||||
const handleStageItem = async (item: PickingItemRow) => {
|
||||
if (!selectedTask) return;
|
||||
const settlement = settlementQtyOf(item.id, item);
|
||||
const settlement = settlementQtyOf(item.id, item, draftSettlement[item.id] || defaultSettlementMode(item));
|
||||
if (settlement <= 0) {
|
||||
notify(t('picking.toast.stageNeedPick'));
|
||||
return;
|
||||
@@ -1593,7 +1627,7 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
|
||||
const missingWeight = taskItems.filter((item) => {
|
||||
const required = Number(item.required_qty) || 0;
|
||||
if (required <= 0) return false;
|
||||
if (!pickingMustWeigh(item, pickingScaleRequired)) return false;
|
||||
if (!pickingMustWeigh(item, pickingScaleRequired, draftSettlement[item.id] || defaultSettlementMode(item))) return false;
|
||||
const weight = Number(draftWeight[item.id] ?? item.picked_weight ?? 0) || 0;
|
||||
return weight <= 0;
|
||||
});
|
||||
@@ -1712,6 +1746,8 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
|
||||
picked_qty: pickedQty,
|
||||
picked_weight: pickedWeight,
|
||||
unit: item.unit || '',
|
||||
inventory_unit: item.inventory_unit || '',
|
||||
settlement_mode: draftSettlement[item.id] || defaultSettlementMode(item),
|
||||
diff_reason: '',
|
||||
outbound_batches: resolveItemPlan(item) || undefined,
|
||||
};
|
||||
@@ -1770,7 +1806,7 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
|
||||
{
|
||||
companyName: selectedTask.company_name || '',
|
||||
itemName: item.item_name || '',
|
||||
qty: settlementQtyOf(item.id, item),
|
||||
qty: settlementQtyOf(item.id, item, draftSettlement[item.id] || defaultSettlementMode(item)),
|
||||
unit: item.unit || '',
|
||||
date: selectedTask.delivery_date
|
||||
? formatPickingTaskCalendarDay(selectedTask.delivery_date)
|
||||
@@ -1803,10 +1839,10 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
|
||||
if (!taskItems.length || !selectedTask) return false;
|
||||
if (Number(selectedTask.pick_status) >= 30) return false;
|
||||
return taskItems.every((item) => {
|
||||
if (!(settlementQtyOf(item.id, item) > 0)) return false;
|
||||
if (!(settlementQtyOf(item.id, item, draftSettlement[item.id] || defaultSettlementMode(item)) > 0)) return false;
|
||||
const required = Number(item.required_qty) || 0;
|
||||
if (required <= 0) return true;
|
||||
if (!pickingMustWeigh(item, pickingScaleRequired)) return true;
|
||||
if (!pickingMustWeigh(item, pickingScaleRequired, draftSettlement[item.id] || defaultSettlementMode(item))) return true;
|
||||
return (Number(draftWeight[item.id] ?? item.picked_weight ?? 0) || 0) > 0;
|
||||
});
|
||||
}, [taskItems, selectedTask, draftQty, draftWeight, pickingScaleRequired]);
|
||||
@@ -3250,7 +3286,7 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
|
||||
if (key === 'required') return required;
|
||||
if (key === 'picked') return picked;
|
||||
if (key === 'weight') return weight;
|
||||
return settlementQtyOf(item.id, item) - required;
|
||||
return settlementQtyOf(item.id, item, draftSettlement[item.id] || defaultSettlementMode(item)) - required;
|
||||
})
|
||||
.map((item, index, arr) => {
|
||||
const itemZone = String(item.storage_zone || '').trim();
|
||||
@@ -3259,7 +3295,7 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
|
||||
const picked = Number(draftQty[item.id] || 0);
|
||||
const weight = Number(draftWeight[item.id] || 0);
|
||||
const required = Number(item.required_qty) || 0;
|
||||
const settlement = settlementQtyOf(item.id, item);
|
||||
const settlement = settlementQtyOf(item.id, item, draftSettlement[item.id] || defaultSettlementMode(item));
|
||||
const hasDiff = Math.abs(settlement - required) > 0.0001;
|
||||
const qtyLocked = Number(selectedTask.pick_status) >= 40;
|
||||
return (
|
||||
@@ -3300,6 +3336,27 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
|
||||
<td key={col.id} className="px-4 py-3">
|
||||
<div className="app-product-name">{item.item_name || t('picking.productFallback')}</div>
|
||||
<div className="text-xs text-gray-500">{item.barcode || t('picking.modal.noBarcode')}</div>
|
||||
{pickingUnitsDiffer(item) || isPickingWeightUnit(item.inventory_unit) ? (
|
||||
<div className="mt-1 flex items-center gap-1 text-xs">
|
||||
<span className="text-gray-500">{t('picking.settlement.label')}</span>
|
||||
<select
|
||||
className="app-input px-1 py-0.5 text-xs rounded border"
|
||||
value={draftSettlement[item.id] || defaultSettlementMode(item)}
|
||||
disabled={qtyLocked}
|
||||
onChange={(e) =>
|
||||
setDraftSettlement((prev) => ({
|
||||
...prev,
|
||||
[item.id]: e.target.value as 'auto' | 'weight' | 'count',
|
||||
}))
|
||||
}
|
||||
>
|
||||
<option value="weight">{t('picking.settlement.weight', { unit: item.inventory_unit || '斤' })}</option>
|
||||
<option value="count" disabled={pickingUnitsDiffer(item)} title={pickingUnitsDiffer(item) ? t('picking.settlement.countNeedsSameUnit') : undefined}>
|
||||
{t('picking.settlement.count', { unit: item.unit || '' })}
|
||||
</option>
|
||||
</select>
|
||||
</div>
|
||||
) : null}
|
||||
{PICKING_LABEL_PRINT_ENABLED ? (
|
||||
<button
|
||||
type="button"
|
||||
@@ -3484,7 +3541,7 @@ function assigneeLabel(user: PickingAssignee, roleLabel: (code: string) => strin
|
||||
? (() => {
|
||||
const item = taskItems.find((row) => row.id === batchEditorItemId);
|
||||
const data = batchInfo[batchEditorItemId]?.data;
|
||||
const need = item ? settlementQtyOf(item.id, item) : 0;
|
||||
const need = item ? settlementQtyOf(item.id, item, draftSettlement[item.id] || defaultSettlementMode(item)) : 0;
|
||||
const total = batchEditorRows.reduce((sum, row) => sum + (Number(row.qty) || 0), 0);
|
||||
const shortfall = fifoAllocateBatches(data?.batches, need).shortfall;
|
||||
return (
|
||||
|
||||
@@ -28,6 +28,8 @@ export interface PickingItemRow {
|
||||
unit?: string | null;
|
||||
/** SKU 库存单位;订单单位与库存单位不一致时,称重按此单位判断 */
|
||||
inventory_unit?: string | null;
|
||||
/** auto/weight/count;weight=按库存单位称重,count=按订单数量(单位一致才允许) */
|
||||
settlement_mode?: 'auto' | 'weight' | 'count' | null;
|
||||
review_status: number;
|
||||
diff_reason?: string | null;
|
||||
barcode?: string | null;
|
||||
|
||||
@@ -898,6 +898,42 @@ export interface SubmitPriceQtyRequestResult {
|
||||
apply_note: string | null;
|
||||
}
|
||||
|
||||
/** 主系统备货计划变更同步台账(供应商本地 outbox)。 */
|
||||
export interface MainSystemPlanChangeRow {
|
||||
id: string;
|
||||
branch_code: string;
|
||||
our_order_code: string;
|
||||
our_order_item_id: string;
|
||||
main_order_item_id: string | null;
|
||||
prep_id: string | null;
|
||||
before_qty: number;
|
||||
before_unit: string | null;
|
||||
after_qty: number;
|
||||
after_unit: string | null;
|
||||
actual_received_qty: number;
|
||||
status: 'pending' | 'syncing' | 'synced' | 'failed' | 'conflict' | 'skipped';
|
||||
attempts: number;
|
||||
last_error: string | null;
|
||||
request_id: string;
|
||||
created_at: string;
|
||||
updated_at: string;
|
||||
synced_at: string | null;
|
||||
}
|
||||
|
||||
export async function listMainSystemPlanChangesApi(orderCode?: string | null) {
|
||||
const qs = orderCode ? `?order_code=${encodeURIComponent(orderCode)}` : '';
|
||||
return workflowFetch<{ data: MainSystemPlanChangeRow[] }>(`/main-system/plan-changes${qs}`).then(
|
||||
(res) => res.data
|
||||
);
|
||||
}
|
||||
|
||||
export async function retryMainSystemPlanChangesApi(limit = 50) {
|
||||
return workflowFetch<{ data: { retried: number; synced: number; failed: number } }>(
|
||||
'/main-system/plan-changes/retry',
|
||||
{ method: 'POST', body: JSON.stringify({ limit }) }
|
||||
).then((res) => res.data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交跨系统改价/改量申请(主系统分配行专用)。
|
||||
* 免审项(补价/改低/减量)提交后立即生效,涨价/加量等主系统管理员审核。
|
||||
@@ -1502,6 +1538,9 @@ export async function confirmPickingCompleteApi(body: {
|
||||
required_qty: number;
|
||||
picked_qty: number;
|
||||
picked_weight?: number;
|
||||
/** auto/weight/count;weight 按库存单位称重,count 按订单数量(单位必须一致) */
|
||||
settlement_mode?: 'auto' | 'weight' | 'count';
|
||||
inventory_unit?: string;
|
||||
diff_reason?: string;
|
||||
outbound_batches?: Array<{ batch_no: string; qty: number }>;
|
||||
/** 分拣出库留证照片(可选,对象路径数组,挂到该商品行;见 docs/design/20261103-分拣出库拍照留证.md) */
|
||||
|
||||
Reference in New Issue
Block a user