fix(stock): 修复 warehouse.import 条码不生效,补差异同步 wms_stock_barcodes

- 创建/更新成功后,若归一化 barcode 为非空数组,调用 saveWarehouseStockBarcode 同步条码

- 条码同步失败计入该行 fail_items;未传条码不触发同步,避免误清空已有条码
This commit is contained in:
liufumingren 2026-08-22 17:22:21 +08:00
parent aacf9c8539
commit b3bdb566c4
2 changed files with 32 additions and 1 deletions

View File

@ -651,6 +651,23 @@ class WarehouseService extends MainService {
if (hasSku) {
result = await service.systems.stockStore.saveWarehouseStock(normalizedRow);
} else {
result = await service.systems.stockStore.createWarehouseStock(normalizedRow);
}
// 条码同步:仅当传入非空条码时写入 wms_stock_barcodes 表(未传条码则保留原有条码)
const barcodes = Array.isArray(normalizedRow.barcode) ? normalizedRow.barcode : [];
if (barcodes.length > 0) {
const stockId = (result && result.id != null) ? result.id : normalizedRow.id;
if (stockId != null) {
await service.systems.stockStore.saveWarehouseStockBarcode({
id: stockId,
barcodes,
});
}
}
if (hasSku) {
summary.updated_count += 1;
if (result && result.id != null) {
summary.updated_ids.push(result.id);
@ -658,7 +675,6 @@ class WarehouseService extends MainService {
summary.updated_ids.push(normalizedRow.id);
}
} else {
result = await service.systems.stockStore.createWarehouseStock(normalizedRow);
summary.created_count += 1;
if (result && result.id != null) {
summary.created_ids.push(result.id);

View File

@ -1,4 +1,19 @@
[
{
"version": "2026.08.22-stock.warehouse.import-barcode-sync",
"date": "2026-08-22",
"type": "fixed",
"summary": "修复 stock.warehouse.import 传入 barcode(条码)不生效的问题:归一化后条码未在新建/更新路径写入 wms_stock_barcodes 表。现在导入行携带非空 barcode 时,在商品创建/更新成功后调用 saveWarehouseStockBarcode 差异同步条码(未传条码则保留原有条码)。",
"methods": [
"stock.warehouse.import"
],
"notes": [
"app/service/systemMethods/stock/warehouse.js import():创建/更新成功后,若归一化 barcode 为非空数组,则按结果 id(缺省用行内 SKU)调用 systems.stockStore.saveWarehouseStockBarcode 同步到 wms_stock_barcodes 表",
"条码同步失败计入该行 fail_items,且该行不再计入成功计数,便于定位",
"未传 barcode(空数组)时不触发同步,避免误清空已有条码;barcode 格式与导出对齐(逗号分隔字符串)"
],
"module": "stock.warehouse"
},
{
"version": "2026.08.22-storage.inventory.list-filter-zero-quantity",
"date": "2026-08-22",