feat(库存): 支持真实删除已用完库存批次
方案A:available<=0 且无活动抵扣/未出库分拣引用时物理删除;流水/报告保留,关联单据 inventory_id 置空;新增真实删除入口与审计。
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
# 库存批次真实删除(方案 A)
|
||||
|
||||
- 日期:2026-10-31
|
||||
- 范围:库存管理「删除库存批次」增加真实删除;商品删除前的库存阻塞同步
|
||||
- 状态:本地实现,未部署
|
||||
|
||||
## 1. 背景
|
||||
|
||||
现有「删除库存批次」只把 `available_qty=0`,`quantity`(入库总量)与批次行仍保留。
|
||||
商品删除检查 `inventory.quantity>0 OR available_qty>0`,所以已用完批次仍阻塞商品删除。
|
||||
数据库触发器 `inventory_prevent_delete_when_occupied` 也用 `quantity-available>0` 拒绝 DELETE,
|
||||
把「已消耗」误当「仍占用」。
|
||||
|
||||
## 2. 语义
|
||||
|
||||
- **清空可用量**:保留批次与历史,现有行为;
|
||||
- **真实删除**:仅当批次已无可用库存(`available_qty<=0`)且无当前业务占用时,物理删除 `inventory` 行。
|
||||
|
||||
真实删除保留:
|
||||
- `inventory_logs`(批次流水,审计);
|
||||
- `inventory_batch_reports`(报告文件本身);
|
||||
- `self_purchase_stock_inbounds` / `processing_task_outputs` 单据,`inventory_id` 置空;
|
||||
- 操作日志 `inventory_batch_hard_delete` 记录快照。
|
||||
|
||||
删除/解除:
|
||||
- `inventory_batch_report_matches` 批次关联删除(报告本身保留);
|
||||
- `inventory` 行物理删除。
|
||||
|
||||
## 3. 删除前置校验
|
||||
|
||||
1. 批次存在、属于当前分公司;
|
||||
2. `available_qty <= 1e-9`(有可用库存必须先清空,不能真删);
|
||||
3. 没有作为当前库存抵扣被未完成订单占用:
|
||||
- `order_items.cover_batches` 含该 `batch_no` 且订单未退货/未完成;
|
||||
- `picking_items.outbound_batches` 含该 `batch_no` 且 `outbound_at IS NULL`;
|
||||
4. 有占用时返回 409,提示先取消抵扣/处理分拣。
|
||||
|
||||
不把 `inventory_logs` 的历史记录当作占用。
|
||||
|
||||
## 4. 接口
|
||||
|
||||
`POST /inventory/batches/:inventoryId/hard-delete`
|
||||
|
||||
```json
|
||||
{ "reason": "已用完清理", "operating_branch_code": "BR002" }
|
||||
```
|
||||
|
||||
权限:`inventory_adjust`。
|
||||
|
||||
## 5. UI
|
||||
|
||||
库存列表操作列:
|
||||
|
||||
- 现有「删除」继续叫「清空可用」;
|
||||
- `available_qty<=0` 的行显示「真实删除」;
|
||||
- 二次确认,提示不删除流水/报告,但批次不可恢复;
|
||||
- 成功后刷新库存列表和流水。
|
||||
|
||||
商品删除仍保留库存检查;用户先真实删除已用完批次,再删除商品。
|
||||
|
||||
## 6. 验收
|
||||
|
||||
1. 有可用库存的批次真实删除被拒绝;
|
||||
2. available=0、quantity>0 且无占用的批次可物理删除;
|
||||
3. 流水/报告保留,关联表 inventory_id 置空/匹配删除;
|
||||
4. 删除后商品删除不再被该批次阻塞;
|
||||
5. 有活动抵扣/未出库分拣引用时拒绝;
|
||||
6. 操作日志记录快照;
|
||||
7. 迁移幂等、typecheck、测试通过。
|
||||
@@ -0,0 +1,33 @@
|
||||
-- 2026-10-31:库存批次真实删除(方案 A)。
|
||||
-- 旧触发器把 quantity-available>0(已消耗)也当成占用,导致已用完批次永远不能 DELETE。
|
||||
-- 新规则:只阻止仍有可用库存(available_qty>0)的批次;服务层 additionally 校验活动抵扣/分拣引用。
|
||||
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='inventory') THEN
|
||||
EXECUTE format($sql$
|
||||
CREATE OR REPLACE FUNCTION %I.inventory_prevent_delete_when_occupied()
|
||||
RETURNS trigger AS $body$
|
||||
BEGIN
|
||||
IF COALESCE(OLD.available_qty, 0) > 1e-9 THEN
|
||||
RAISE EXCEPTION '该库存批次仍有可用库存,请先清空可用量再删除'
|
||||
USING ERRCODE = 'check_violation';
|
||||
END IF;
|
||||
RETURN OLD;
|
||||
END;
|
||||
$body$ LANGUAGE plpgsql;
|
||||
$sql$, sch);
|
||||
EXECUTE format('DROP TRIGGER IF EXISTS trg_inventory_prevent_delete_when_occupied ON %I.inventory', sch);
|
||||
EXECUTE format($sql$
|
||||
CREATE TRIGGER trg_inventory_prevent_delete_when_occupied
|
||||
BEFORE DELETE ON %I.inventory
|
||||
FOR EACH ROW EXECUTE FUNCTION %I.inventory_prevent_delete_when_occupied()
|
||||
$sql$, sch, sch);
|
||||
END IF;
|
||||
END LOOP;
|
||||
END $$;
|
||||
@@ -669,6 +669,34 @@ export function mountInventoryWorkflowRoutes(router: Router): void {
|
||||
}
|
||||
);
|
||||
|
||||
/** 真实删除已用完库存批次(需 inventory_adjust;有可用库存/活动占用时拒绝) */
|
||||
router.post(
|
||||
'/inventory/batches/:inventoryId/hard-delete',
|
||||
authMiddleware,
|
||||
async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
const ctx = await getWorkflowCtx(req);
|
||||
requireWorkflowPermission(ctx, ['inventory_adjust']);
|
||||
const branchCode = resolveBranch(req, ctx!, req.body?.operating_branch_code);
|
||||
const { hardDeleteInventoryBatch } = await import(
|
||||
'../../../services/inventoryBatchHardDeleteService'
|
||||
);
|
||||
const data = await hardDeleteInventoryBatch({
|
||||
inventoryId: String(req.params.inventoryId || ''),
|
||||
branchCode,
|
||||
operatorId: req.userId || null,
|
||||
reason: req.body?.reason ? String(req.body.reason) : null,
|
||||
});
|
||||
return res.json({ data });
|
||||
} catch (error: any) {
|
||||
return res.status(error?.status || 500).json({
|
||||
error: error?.code || 'server_error',
|
||||
error_description: error?.message || '真实删除库存批次失败',
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
/** 按批次调整可用库存(需 inventory_adjust) */
|
||||
router.post('/inventory/adjust', authMiddleware, async (req: AuthRequest, res: Response) => {
|
||||
try {
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
import { pool } from '../db';
|
||||
import { writeAuditLog } from './auditService';
|
||||
|
||||
function bad(message: string, code: string, status = 400): Error {
|
||||
return Object.assign(new Error(message), { status, code });
|
||||
}
|
||||
|
||||
/**
|
||||
* 库存批次真实删除(2026-10-31 方案 A)。
|
||||
*
|
||||
* 只允许 available_qty<=0 且没有活动抵扣/未出库分拣引用的批次;
|
||||
* 保留 inventory_logs / 报告文件 / 自采购入库/加工单据(仅把 inventory_id 置空)。
|
||||
*/
|
||||
export async function hardDeleteInventoryBatch(input: {
|
||||
inventoryId: string;
|
||||
branchCode: string;
|
||||
operatorId?: string | null;
|
||||
reason?: string | null;
|
||||
}): Promise<{
|
||||
id: string;
|
||||
batch_no: string;
|
||||
sku_code: string;
|
||||
quantity: number;
|
||||
available_qty: number;
|
||||
}> {
|
||||
const inventoryId = String(input.inventoryId || '').trim();
|
||||
const branchCode = String(input.branchCode || '').trim();
|
||||
if (!inventoryId || !branchCode) throw bad('缺少库存记录或分公司', 'invalid_request');
|
||||
|
||||
const client = await pool.connect();
|
||||
let snapshot: { id: string; batch_no: string; sku_code: string; quantity: number; available_qty: number } | null = null;
|
||||
try {
|
||||
await client.query('BEGIN');
|
||||
const locked = await client.query(
|
||||
`SELECT id, batch_no, sku_code, quantity, available_qty
|
||||
FROM inventory
|
||||
WHERE id = $1::uuid AND branch_code = $2
|
||||
FOR UPDATE`,
|
||||
[inventoryId, branchCode]
|
||||
);
|
||||
if (!locked.rowCount) throw bad('库存记录不存在或不属于当前分公司', 'not_found', 404);
|
||||
const row = locked.rows[0];
|
||||
const available = Number(row.available_qty) || 0;
|
||||
const quantity = Number(row.quantity) || 0;
|
||||
if (available > 1e-9) {
|
||||
throw bad('该批次仍有可用库存,请先清空可用量,再真实删除', 'batch_has_available');
|
||||
}
|
||||
const batchNo = String(row.batch_no || '').trim();
|
||||
if (!batchNo) throw bad('库存批次号为空,不能删除', 'batch_no_missing');
|
||||
|
||||
// 活动抵扣:未退货、未完成订单的 cover_batches 含该批次。
|
||||
const coverRef = await client.query(
|
||||
`SELECT 1
|
||||
FROM order_items oi
|
||||
JOIN orders o ON o.order_code = oi.order_code
|
||||
WHERE oi.branch_code = $1
|
||||
AND COALESCE(oi.is_returned, false) = false
|
||||
AND COALESCE(o.deleted_at, NULL) IS NULL
|
||||
AND COALESCE(o.order_status, 0) < 90
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM jsonb_array_elements(COALESCE(oi.cover_batches, '[]'::jsonb)) e
|
||||
WHERE e->>'batch_no' = $2
|
||||
)
|
||||
LIMIT 1`,
|
||||
[branchCode, batchNo]
|
||||
);
|
||||
if (coverRef.rowCount) {
|
||||
throw bad('该批次仍被未完成订单抵扣占用,请先取消抵扣或换批次', 'batch_in_active_cover', 409);
|
||||
}
|
||||
|
||||
// 未出库分拣引用:picking_items.outbound_batches 含该批次且尚未出库。
|
||||
const pickRef = await client.query(
|
||||
`SELECT 1
|
||||
FROM picking_items pi
|
||||
WHERE pi.branch_code = $1
|
||||
AND pi.outbound_at IS NULL
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM jsonb_array_elements(COALESCE(pi.outbound_batches, '[]'::jsonb)) e
|
||||
WHERE e->>'batch_no' = $2
|
||||
)
|
||||
LIMIT 1`,
|
||||
[branchCode, batchNo]
|
||||
);
|
||||
if (pickRef.rowCount) {
|
||||
throw bad('该批次仍被未出库分拣引用,请先处理分拣后再删除', 'batch_in_active_picking', 409);
|
||||
}
|
||||
|
||||
snapshot = {
|
||||
id: String(row.id),
|
||||
batch_no: batchNo,
|
||||
sku_code: String(row.sku_code || ''),
|
||||
quantity,
|
||||
available_qty: available,
|
||||
};
|
||||
|
||||
// 报告关联删除;报告文件本身保留。
|
||||
await client.query(
|
||||
`DELETE FROM inventory_batch_report_matches WHERE inventory_id = $1::uuid`,
|
||||
[inventoryId]
|
||||
);
|
||||
// 保留业务单据历史,仅解除对已删除批次行的引用。
|
||||
await client.query(
|
||||
`UPDATE self_purchase_stock_inbounds SET inventory_id = NULL WHERE inventory_id = $1::uuid`,
|
||||
[inventoryId]
|
||||
);
|
||||
await client.query(
|
||||
`UPDATE processing_task_outputs SET inventory_id = NULL WHERE inventory_id = $1::uuid`,
|
||||
[inventoryId]
|
||||
);
|
||||
|
||||
await client.query(`DELETE FROM inventory WHERE id = $1::uuid`, [inventoryId]);
|
||||
await client.query('COMMIT');
|
||||
} catch (error) {
|
||||
await client.query('ROLLBACK').catch(() => undefined);
|
||||
throw error;
|
||||
} finally {
|
||||
client.release();
|
||||
}
|
||||
|
||||
try {
|
||||
await writeAuditLog({
|
||||
operatorId: input.operatorId || null,
|
||||
operationType: 'inventory_batch_hard_delete',
|
||||
targetTable: 'inventory',
|
||||
targetId: inventoryId,
|
||||
oldValue: snapshot,
|
||||
newValue: {
|
||||
...snapshot,
|
||||
reason: String(input.reason || '').trim() || '已用完清理',
|
||||
inventory_logs_kept: true,
|
||||
report_files_kept: true,
|
||||
},
|
||||
branchCode,
|
||||
actionCategory: 'inventory',
|
||||
});
|
||||
} catch (error) {
|
||||
console.warn('[inventory-hard-delete] 审计失败(不影响删除):', (error as Error)?.message || error);
|
||||
}
|
||||
return snapshot!;
|
||||
}
|
||||
@@ -71,6 +71,8 @@ export const inventory: MessageDict = {
|
||||
inboundDate: 'In {date}',
|
||||
'action.edit': 'Edit',
|
||||
'action.editTitle': 'Adjust available stock',
|
||||
'action.hardDeleteTitle': 'Permanently delete (no available stock)',
|
||||
'action.hardDelete': 'Delete permanently',
|
||||
'action.delete': 'Delete',
|
||||
'action.deleteTitle': 'Zero this batch and hide it from the default list',
|
||||
'pager.inventory': 'batches',
|
||||
@@ -132,6 +134,14 @@ export const inventory: MessageDict = {
|
||||
'holding.loading': 'Loading…',
|
||||
'holding.empty': 'No holding cost',
|
||||
|
||||
'hardDelete.title': 'Permanently delete stock batch',
|
||||
'hardDelete.body': 'Available stock is 0. This permanently deletes the inventory batch so it no longer blocks product deletion. Stock logs and report files are kept.',
|
||||
'hardDelete.confirm': 'Delete permanently',
|
||||
'hardDelete.processing': 'Deleting…',
|
||||
'hardDelete.done': 'Stock batch permanently deleted',
|
||||
'hardDelete.failed': 'Permanent delete failed',
|
||||
'hardDelete.reason': 'Consumed cleanup',
|
||||
'hardDelete.keepHint': 'Stock logs and report files are kept; this cannot be undone.',
|
||||
'void.title': 'Void stock batch',
|
||||
'void.bodyOne':
|
||||
'Set this batch available to 0 and hide it from the default list. No hard delete; logs remain. Do not void batches that are still physically in stock.',
|
||||
|
||||
@@ -74,6 +74,8 @@ export const inventory: MessageDict = {
|
||||
inboundDate: 'Masuk {date}',
|
||||
'action.edit': 'Ubah',
|
||||
'action.editTitle': 'Ubah stok tersedia',
|
||||
'action.hardDeleteTitle': 'Hapus permanen (tidak ada stok tersedia)',
|
||||
'action.hardDelete': 'Hapus permanen',
|
||||
'action.delete': 'Hapus',
|
||||
'action.deleteTitle':
|
||||
'Nolkan batch ini dan sembunyikan dari daftar default',
|
||||
@@ -136,6 +138,14 @@ export const inventory: MessageDict = {
|
||||
'holding.loading': 'Memuat…',
|
||||
'holding.empty': 'Tidak ada biaya holding',
|
||||
|
||||
'hardDelete.title': 'Hapus permanen batch stok',
|
||||
'hardDelete.body': 'Stok tersedia 0. Batch inventaris akan dihapus permanen dan tidak lagi memblokir penghapusan produk. Log stok dan file laporan tetap disimpan.',
|
||||
'hardDelete.confirm': 'Hapus permanen',
|
||||
'hardDelete.processing': 'Menghapus…',
|
||||
'hardDelete.done': 'Batch stok dihapus permanen',
|
||||
'hardDelete.failed': 'Gagal menghapus permanen',
|
||||
'hardDelete.reason': 'Pembersihan stok habis',
|
||||
'hardDelete.keepHint': 'Log stok dan file laporan tetap disimpan; tidak dapat dibatalkan.',
|
||||
'void.title': 'Hapus batch stok',
|
||||
'void.bodyOne':
|
||||
'Set tersedia batch ini ke 0 dan sembunyikan dari daftar default. Tidak hapus fisik; log tetap. Jangan void batch yang masih ada di gudang.',
|
||||
|
||||
@@ -70,6 +70,8 @@ export const inventory: MessageDict = {
|
||||
inboundDate: '入库 {date}',
|
||||
'action.edit': '修改',
|
||||
'action.editTitle': '修改可用库存',
|
||||
'action.hardDeleteTitle': '可真实删除(已无可用库存)',
|
||||
'action.hardDelete': '真实删除',
|
||||
'action.delete': '删除',
|
||||
'action.deleteTitle': '将本批次可用清零并从默认列表隐藏',
|
||||
'pager.inventory': '条库存',
|
||||
@@ -130,6 +132,14 @@ export const inventory: MessageDict = {
|
||||
'holding.loading': '加载中…',
|
||||
'holding.empty': '暂无在库存货(账外进仓台账)',
|
||||
|
||||
'hardDelete.title': '真实删除库存批次',
|
||||
'hardDelete.body': '该批次可用库存已为 0。真实删除后会物理删除库存批次,商品不再被它引用;库存流水和报告文件保留。',
|
||||
'hardDelete.confirm': '确认真实删除',
|
||||
'hardDelete.processing': '删除中…',
|
||||
'hardDelete.done': '库存批次已真实删除',
|
||||
'hardDelete.failed': '真实删除失败',
|
||||
'hardDelete.reason': '已用完清理',
|
||||
'hardDelete.keepHint': '不会删除库存流水/报告文件,删除后不可恢复。',
|
||||
'void.title': '删除库存批次',
|
||||
'void.bodyOne':
|
||||
'将本批次可用改为 0,默认列表不再显示。不物理删库,流水保留。请勿把真实在库批次一并删掉。',
|
||||
|
||||
@@ -44,6 +44,7 @@ import { TablePaginationBar } from '../../components/ui/TablePaginationBar';
|
||||
import { SortableThLabel } from '../../components/ui/SortableThLabel';
|
||||
import {
|
||||
adjustInventoryAvailableApi,
|
||||
hardDeleteInventoryBatchApi,
|
||||
updateInventoryBatchApi,
|
||||
type UpdateInventoryBatchPayload,
|
||||
listUnitsApi,
|
||||
@@ -412,6 +413,8 @@ export const InventoryManagement: React.FC = () => {
|
||||
const [unitChoices, setUnitChoices] = useState<Array<{ value: string; label: string }>>([]);
|
||||
const [voidTargets, setVoidTargets] = useState<InventoryItem[]>([]);
|
||||
const [voidSaving, setVoidSaving] = useState(false);
|
||||
const [hardDeleteTarget, setHardDeleteTarget] = useState<InventoryItem | null>(null);
|
||||
const [hardDeleting, setHardDeleting] = useState(false);
|
||||
const [voidProgress, setVoidProgress] = useState('');
|
||||
const [stockCoverEnabled, setStockCoverEnabled] = useState(true);
|
||||
const [stockImportOpen, setStockImportOpen] = useState(false);
|
||||
@@ -593,6 +596,25 @@ export const InventoryManagement: React.FC = () => {
|
||||
};
|
||||
}, []);
|
||||
|
||||
const submitHardDeleteBatch = async () => {
|
||||
if (!hardDeleteTarget || hardDeleting) return;
|
||||
setHardDeleting(true);
|
||||
try {
|
||||
await hardDeleteInventoryBatchApi({
|
||||
inventoryId: hardDeleteTarget.id,
|
||||
reason: t('inventory.hardDelete.reason'),
|
||||
operatingBranchCode: operatingBranchCode || readOperatingBranchCode(),
|
||||
});
|
||||
notify.success(t('inventory.hardDelete.done'));
|
||||
setHardDeleteTarget(null);
|
||||
await Promise.all([fetchInventory(), fetchInventoryLogs()]);
|
||||
} catch (error: any) {
|
||||
notify.error(error?.message || t('inventory.hardDelete.failed'));
|
||||
} finally {
|
||||
setHardDeleting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const closeVoidModal = () => {
|
||||
if (voidSaving) return;
|
||||
setVoidTargets([]);
|
||||
@@ -1770,14 +1792,25 @@ export const InventoryManagement: React.FC = () => {
|
||||
>
|
||||
{t('inventory.action.edit')}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setVoidTargets([item])}
|
||||
className="inline-flex items-center px-2.5 py-1.5 text-xs font-medium text-red-600 hover:bg-red-50 rounded-lg"
|
||||
title={t('inventory.action.deleteTitle')}
|
||||
>
|
||||
{t('inventory.action.delete')}
|
||||
</button>
|
||||
{Number(item.available_qty) <= 1e-9 ? (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setHardDeleteTarget(item)}
|
||||
className="inline-flex items-center px-2.5 py-1.5 text-xs font-medium text-red-700 hover:bg-red-50 rounded-lg"
|
||||
title={t('inventory.action.hardDeleteTitle')}
|
||||
>
|
||||
{t('inventory.action.hardDelete')}
|
||||
</button>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setVoidTargets([item])}
|
||||
className="inline-flex items-center px-2.5 py-1.5 text-xs font-medium text-red-600 hover:bg-red-50 rounded-lg"
|
||||
title={t('inventory.action.deleteTitle')}
|
||||
>
|
||||
{t('inventory.action.delete')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
);
|
||||
@@ -2182,6 +2215,31 @@ export const InventoryManagement: React.FC = () => {
|
||||
</DialogOverlay>
|
||||
)}
|
||||
|
||||
{hardDeleteTarget && (
|
||||
<DialogOverlay onBackdropMouseDown={() => (hardDeleting ? undefined : setHardDeleteTarget(null))}>
|
||||
<div className="app-surface rounded-xl shadow-xl w-full max-w-md p-5" onClick={(e) => e.stopPropagation()}>
|
||||
<div className="flex items-center justify-between mb-4">
|
||||
<h3 className="text-lg font-semibold text-black dark:text-slate-100">{t('inventory.hardDelete.title')}</h3>
|
||||
<button type="button" onClick={() => setHardDeleteTarget(null)} disabled={hardDeleting} className="p-1.5 rounded-lg hover:bg-gray-100 disabled:opacity-50" aria-label={t('common.close')}>
|
||||
<X className="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
<p className="text-sm text-gray-600 dark:text-slate-300">{t('inventory.hardDelete.body')}</p>
|
||||
<div className="mt-3 space-y-2 text-sm">
|
||||
<div><p className="text-gray-500 text-xs">{t('inventory.void.product')}</p><p className="font-medium">{hardDeleteTarget.sku_name || hardDeleteTarget.sku_code}</p></div>
|
||||
<div><p className="text-gray-500 text-xs">{t('inventory.void.batch')}</p><p className="font-mono text-xs">{hardDeleteTarget.batch_no}</p></div>
|
||||
<p className="text-xs text-gray-500">{t('inventory.hardDelete.keepHint')}</p>
|
||||
</div>
|
||||
<div className="mt-5 flex justify-end gap-2">
|
||||
<button type="button" onClick={() => setHardDeleteTarget(null)} disabled={hardDeleting} className="px-3 py-2 text-sm rounded-lg border border-gray-200 hover:bg-gray-50 disabled:opacity-50">{t('common.cancel')}</button>
|
||||
<button type="button" onClick={() => void submitHardDeleteBatch()} disabled={hardDeleting} className="px-3 py-2 text-sm rounded-lg bg-red-600 text-white hover:bg-red-700 disabled:opacity-50">
|
||||
{hardDeleting ? t('inventory.hardDelete.processing') : t('inventory.hardDelete.confirm')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</DialogOverlay>
|
||||
)}
|
||||
|
||||
{adjustItem && (
|
||||
<DialogOverlay onBackdropMouseDown={closeAdjustModal}>
|
||||
<div
|
||||
|
||||
@@ -3965,6 +3965,29 @@ export async function adjustInventoryAvailableApi(input: {
|
||||
}).then((res) => res.data);
|
||||
}
|
||||
|
||||
/** 真实删除已用完库存批次(有可用库存/活动占用时服务端拒绝) */
|
||||
export async function hardDeleteInventoryBatchApi(input: {
|
||||
inventoryId: string;
|
||||
reason?: string | null;
|
||||
operatingBranchCode?: string | null;
|
||||
}) {
|
||||
return workflowFetch<{
|
||||
data: {
|
||||
id: string;
|
||||
batch_no: string;
|
||||
sku_code: string;
|
||||
quantity: number;
|
||||
available_qty: number;
|
||||
};
|
||||
}>(`/inventory/batches/${encodeURIComponent(input.inventoryId)}/hard-delete`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
reason: input.reason || undefined,
|
||||
operating_branch_code: input.operatingBranchCode || undefined,
|
||||
}),
|
||||
}).then((res) => res.data);
|
||||
}
|
||||
|
||||
/** 库存管理「修改」:批次属性 + 商品档案字段(数量走 adjustInventoryAvailableApi) */
|
||||
export interface UpdateInventoryBatchPayload {
|
||||
storage_zone?: string;
|
||||
|
||||
Reference in New Issue
Block a user