{
const inventoryId = trimText(input.inventoryId);
const branchCode = trimText(input.branchCode);
- const remark = trimText(input.remark);
+ /**
+ * 备注改为**选填**(开发者 2026-10-15:「当前这块 调整备注不是必填选项 改为可填」)。
+ * 空备注不再拦,落库时补一个中性标签(与 `inventoryAdjustService` 的
+ * `|| '入库量纠错'` 同一先例),保证审计里**永远有可读留痕**;本函数一贯
+ * **只写 `operation_logs` 审计、跳 `inventory_logs`**(避免与「数量流水」混淆),
+ * 这条既有设计连同「权限 + 通用网关禁写」一概不动。
+ */
+ const remark = trimText(input.remark) || '库存批次修改';
if (!inventoryId) {
throw Object.assign(new Error('缺少库存记录'), { status: 400, code: 'invalid_request' });
}
if (!branchCode) {
throw Object.assign(new Error('请选择当前操作分公司'), { status: 400, code: 'branch_required' });
}
- if (!remark) {
- throw Object.assign(new Error('请填写修改备注'), { status: 400, code: 'invalid_request' });
- }
const client = await pool.connect();
try {
diff --git a/server/tests/inventoryBatchCostRecalc.test.ts b/server/tests/inventoryBatchCostRecalc.test.ts
index 2b3a74f..0627399 100644
--- a/server/tests/inventoryBatchCostRecalc.test.ts
+++ b/server/tests/inventoryBatchCostRecalc.test.ts
@@ -62,9 +62,11 @@ describe('库存管理「修改」这条入口', () => {
expect(editService).toMatch(/if \(\(beforeBatch\.cost_price \?\? null\) !== \(next \?\? null\)\) \{/);
});
- it('备注必填(统一留痕的一半)', () => {
- expect(editService).toContain('请填写修改备注');
- expect(editService).toContain("code: 'invalid_request'");
+ it('备注选填,但留痕不留空(2026-10-15 开发者:改为可填)', () => {
+ // 空备注不再拦(原来 throw '请填写修改备注')
+ expect(editService).not.toContain('请填写修改备注');
+ // 空时补中性标签 ⇒ inventory_logs / 审计里永远有可读留痕
+ expect(editService).toContain("trimText(input.remark) || '库存批次修改'");
});
it('把重算结果回给调用方并写进审计(可追溯改了几个未结算单)', () => {
diff --git a/server/tests/inventoryRemarkOptional.test.ts b/server/tests/inventoryRemarkOptional.test.ts
new file mode 100644
index 0000000..51100f4
--- /dev/null
+++ b/server/tests/inventoryRemarkOptional.test.ts
@@ -0,0 +1,65 @@
+import { readFileSync } from 'node:fs';
+import { describe, expect, it } from 'vitest';
+
+/**
+ * 「调整备注」改为**选填**(开发者 2026-10-15:「当前这块 调整备注不是必填选项 改为可填」)。
+ *
+ * 库存管理「修改可用库存」弹窗会打两条路径:
+ * · 可用数量变了 ⇒ `POST /inventory/adjust`(`adjustInventoryAvailableQty`)
+ * · 批次属性/商品档案变了 ⇒ `POST /inventory/batch-update`(`updateInventoryBatchAttributes`)
+ * 原来两条路径**前后端都拦空备注**,本次按指令放开,但**留痕不留空**:
+ * 备注为空时补中性标签(沿用同仓 `|| '入库量纠错'` 先例)。
+ *
+ * ⚠️ 这是 `.cursor/rules/inventory-freeze.mdc` 点名保护的「备注必填」项,本次经开发者
+ * 直接指令放开;同批保护的「双日志 / 权限 / 「已拣未出库允许调高」例外 / 通用网关禁写」
+ * **一概不动** —— 本文件同时钉住这一点,防后续顺手删掉。
+ */
+const read = (rel: string) => readFileSync(new URL(rel, import.meta.url), 'utf8');
+
+const adjustService = read('../src/services/inventoryAdjustService.ts');
+const editService = read('../src/services/inventoryBatchEditService.ts');
+const page = read('../../src/pages/inventory/InventoryManagement.tsx');
+
+describe('调整备注选填 · 服务端', () => {
+ it('inventory/adjust:空备注不再拦,补中性标签', () => {
+ expect(adjustService).toContain("String(input.remark || '').trim() || '库存调整'");
+ expect(adjustService).not.toContain('请填写调整备注');
+ });
+
+ it('inventory/batch-update:空备注不再拦,补中性标签', () => {
+ expect(editService).toContain("trimText(input.remark) || '库存批次修改'");
+ expect(editService).not.toContain('请填写修改备注');
+ });
+
+ it('留痕相关一概未动:adjust 仍双日志(inventory_logs + 审计),batch-update 仍走审计', () => {
+ // adjust:数量流水 + 审计
+ expect(adjustService).toContain('INSERT INTO inventory_logs');
+ expect(adjustService).toContain('writeAuditLog');
+ expect(adjustService).toContain("operation_type");
+ // batch-update:既有设计只写 operation_logs(跳 inventory_logs,避免与数量流水混淆)
+ expect(editService).toContain('writeAuditLog');
+ expect(editService).not.toContain('INSERT INTO inventory_logs');
+ });
+
+ it('其余校验与例外一概未动(分公司必选、数量非负、已拣未出库允许调高)', () => {
+ expect(adjustService).toContain("'请选择当前操作分公司'");
+ expect(adjustService).toContain('可用数量须为不小于 0 的数字');
+ expect(adjustService).toContain('已拣未出库');
+ });
+});
+
+describe('调整备注选填 · 前端弹窗', () => {
+ it('不再做前端必填拦截,也没有必填红星', () => {
+ expect(page).not.toContain("notify.error(t('inventory.toast.remarkRequired'))");
+ // 标签上不再挂红色星号(原来:{t('inventory.adjust.remark')} *)
+ expect(page).not.toContain(
+ "{t('inventory.adjust.remark')} *"
+ );
+ });
+
+ it('仍然把备注传给两条接口(空串由服务端补默认标签)', () => {
+ expect(page).toContain('remark: adjustRemark.trim(),');
+ expect(page).toContain('adjustInventoryAvailableApi({');
+ expect(page).toContain('updateInventoryBatchApi({');
+ });
+});
diff --git a/src/pages/inventory/InventoryManagement.tsx b/src/pages/inventory/InventoryManagement.tsx
index 9cc926b..6298daf 100644
--- a/src/pages/inventory/InventoryManagement.tsx
+++ b/src/pages/inventory/InventoryManagement.tsx
@@ -483,11 +483,6 @@ export const InventoryManagement: React.FC = () => {
notify.error(t('inventory.toast.qtyInvalid'));
return;
}
- if (!adjustRemark.trim()) {
- notify.error(t('inventory.toast.remarkRequired'));
- return;
- }
-
const branch = operatingBranchCode || readOperatingBranchCode();
const beforeZone = adjustItem.storage_zone || '';
const beforeShelfLife = adjustItem.shelf_life || '';
@@ -1934,7 +1929,7 @@ export const InventoryManagement: React.FC = () => {