fix: 修复 docs 页面 JS 失效 + 入库 locked_quantity 流水补全 + stock_store 查询条件补全 is_valid

1. docs.js: 修复模板字面量中 '\n' 被服务端解释为换行符导致客户端 JS SyntaxError,所有交互功能失效(搜索/发送按钮)
2. inbound_direct_log.js: batch_no 修正为 effectiveBatchNo;storage 表更新时补全 before_locked_quantity/after_locked_quantity;新增 stock_id 归属校验
3. stock_store.js: 多处查询/更新补全 is_valid='Y' 过滤条件,避免软删除/失效数据泄露或误操作
4. storage/entry.js: 入库完成时补全 storage 表 before_locked_quantity/after_locked_quantity 流水字段
This commit is contained in:
liufumingren 2026-08-09 00:23:42 +08:00
parent 358fef0f71
commit 3e7c9a7a10
4 changed files with 37 additions and 3 deletions

View File

@ -2043,7 +2043,7 @@ Content-Type: application/json
}).then(function(res) {
return res.text().then(function(txt) { return { status: res.status, body: txt }; });
}).then(function(r) {
resultEl.textContent = 'HTTP ' + r.status + '\n' + r.body;
resultEl.textContent = 'HTTP ' + r.status + '\\n' + r.body;
resultEl.className = r.status === 200 ? 'req-result success' : 'req-result error';
}).catch(function(err) {
resultEl.textContent = '推送失败: ' + err.message;

View File

@ -1042,7 +1042,7 @@ class InboundDirectLogService extends Service {
where: {
space_id: spaceId,
stock_id: stockId,
batch_no: batchNo,
batch_no: effectiveBatchNo,
inventory_type: inventoryType,
is_enabled: 1,
delete_at: null,
@ -1054,10 +1054,20 @@ class InboundDirectLogService extends Service {
let sId = null;
let sBeforeQty = 0;
let sAfterQty = 0;
let sBeforeLockedQty = 0;
let sAfterLockedQty = 0;
if (sRecord) {
if (Number(sRecord.stock_id) !== Number(stockId)) {
throw new Error(
`入库库存归属冲突: storage_id=${sRecord.id} 当前 stock_id=${sRecord.stock_id}, ` +
`本次入库 stock_id=${stockId}, space_id=${spaceId}, batch_no=${effectiveBatchNo}`
);
}
sBeforeQty = Number(sRecord.quantity) || 0;
sAfterQty = sBeforeQty + qty;
sBeforeLockedQty = Number(sRecord.locked_quantity) || 0;
sAfterLockedQty = sBeforeLockedQty;
await ctx.model.Storage.update({
quantity: app.Sequelize.literal(`quantity + ${qty}`),
@ -1077,6 +1087,8 @@ class InboundDirectLogService extends Service {
} else {
sBeforeQty = 0;
sAfterQty = qty;
sBeforeLockedQty = 0;
sAfterLockedQty = 0;
const createdStorage = await ctx.model.Storage.create({
warehouse_id: warehouseId,
@ -1114,6 +1126,8 @@ class InboundDirectLogService extends Service {
quantity: qty,
before_quantity: sBeforeQty,
after_quantity: sAfterQty,
before_locked_quantity: sBeforeLockedQty,
after_locked_quantity: sAfterLockedQty,
batch_no: effectiveBatchNo,
inventory_type: inventoryType,
order_type: 'entry_order',

View File

@ -1437,6 +1437,7 @@ class stockStoreService extends Service {
warehouse_id: warehouseId,
store_id: sourceData.store_id,
deleted_at: null,
is_valid: 'Y',
},
attributes: [ 'id' ],
raw: true,
@ -1548,6 +1549,7 @@ class stockStoreService extends Service {
goods_code: sourceData.goods_code,
warehouse_id: warehouseId,
is_valid: 'Y',
deleted_at: null,
},
attributes: [ 'id' ],
raw: true,
@ -2557,7 +2559,8 @@ class stockStoreService extends Service {
where: {
id: { [Op.in]: ids },
warehouse_id: warehouseId,
delete_at: null,
deleted_at: null,
is_valid: 'Y',
},
attributes: [ 'id' ],
});
@ -2784,6 +2787,8 @@ class stockStoreService extends Service {
} else {
const StockWarehouseWhere = {
warehouse_id: warehouseId,
deleted_at: null,
is_valid: 'Y',
};
const StockStoreWhere = {};
if (store_id) {
@ -2905,6 +2910,7 @@ class stockStoreService extends Service {
where: {
warehouse_id: warehouseId,
deleted_at: null,
is_valid: 'Y',
id: warehouse_stock,
},
attributes: [
@ -2985,6 +2991,7 @@ class stockStoreService extends Service {
where: {
warehouse_id: warehouseId,
deleted_at: null,
is_valid: 'Y',
id,
},
attributes: [
@ -3078,6 +3085,7 @@ class stockStoreService extends Service {
where: {
id,
deleted_at: null,
is_valid: 'Y',
warehouse_id: ctx.user.store_id,
},
transaction,
@ -3325,6 +3333,7 @@ class stockStoreService extends Service {
store_id: owner_id,
warehouse_id,
deleted_at: null,
is_valid: 'Y',
};
if (item_id) {
@ -3370,6 +3379,7 @@ class stockStoreService extends Service {
[Op.and]: [
{ id: { [Op.in]: ids } },
{ deleted_at: null },
{ is_valid: 'Y' },
],
};
@ -3678,6 +3688,7 @@ class stockStoreService extends Service {
const whereCondition = {
warehouse_id: warehouseId,
deleted_at: null,
is_valid: 'Y',
};
// 如果有传入store_id,则添加store_id条件
@ -3923,6 +3934,7 @@ class stockStoreService extends Service {
id: stock_id,
warehouse_id: warehouseId,
deleted_at: null,
is_valid: 'Y',
},
attributes: [ 'id', 'item_code', 'item_name', 'sku_property', 'stock_unit', 'quantity', 'locked_quantity' ],
raw: true,

View File

@ -1553,10 +1553,14 @@ class EntryService extends Service {
let storageId = null;
let storageBeforeQty = 0;
let storageAfterQty = 0;
let storageBeforeLockedQty = 0;
let storageAfterLockedQty = 0;
if (storageRecord) {
storageBeforeQty = Number(storageRecord.quantity) || 0;
storageAfterQty = storageBeforeQty + planQty;
storageBeforeLockedQty = Number(storageRecord.locked_quantity) || 0;
storageAfterLockedQty = storageBeforeLockedQty;
await ctx.model.Storage.update({
quantity: app.Sequelize.literal(`quantity + ${planQty}`),
@ -1573,6 +1577,8 @@ class EntryService extends Service {
} else {
storageBeforeQty = 0;
storageAfterQty = planQty;
storageBeforeLockedQty = 0;
storageAfterLockedQty = 0;
const createdStorage = await ctx.model.Storage.create({
warehouse_id: warehouseId,
@ -1608,6 +1614,8 @@ class EntryService extends Service {
quantity: planQty,
before_quantity: storageBeforeQty,
after_quantity: storageAfterQty,
before_locked_quantity: storageBeforeLockedQty,
after_locked_quantity: storageAfterLockedQty,
batch_no: batchNo,
inventory_type: inventoryType,
order_type: 'entry_order',