WMS_MAIN/app/model/stock_check_record.js
liufumingren 9743416187 feat: 盘点作业数据接口改造与账面口径全量统一(可用+锁定)
- workData 三视图:goods 视图 locations=商品所在全部库位列表(明盘每库位 system_quantity 账面/quantity 盘点、盲盘只显示库位);space 视图同口径;新增 workDataSpaceDetails 分页版
- workDataDetail 增加 goods 分支(单行结构,复用视图构建器);detail 补 profit_total/loss_total 差异汇总
- 库位账面全量统一为 SUM(available_quantity+locked_quantity)(可用+锁定)并标记 locked_quantity:result/report/finish/detail/addDetail 拆行快照与作业视图一致
- 未盘行不误显盘亏:diff/is_diff 仅存在作业记录时计算
- 文档 methods/system.json 0.3.249 + changes 变更记录,开发/生产库已回填
2026-10-06 03:24:41 +08:00

132 lines
4.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/**
* 库存盘点作业记录表模型(存储盘点的库位、数量信息)。
* 一个盘点明细(商品行或库位行)可在多个库位/商品维度多次上报,每次上报一条记录;
* 覆盖式语义为「同明细 + 同商品 + 同库位」(uk_detail_stock_location 唯一索引);
* 支持未知商品(仿收货明细口径):stock_id 为空(NULL)+ barcode + item_name,
* 唯一索引中 NULL 不参与唯一约束,未知商品查重由应用层保证。
* @param {import('egg').Application} app Egg 应用实例。
* @return {import('sequelize').ModelCtor<import('sequelize').Model>} Sequelize 模型。
*/
module.exports = app => {
const { BIGINT, STRING, INTEGER, DATE, BOOLEAN } = app.Sequelize;
const StockCheckRecord = app.model.define('wms_stock_check_record', {
id: {
type: BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
comment: '主键',
},
check_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '关联盘点主表 wms_stock_check.id(冗余,便于按任务查记录)',
},
warehouse_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '仓库ID(冗余,隔离查询)',
},
detail_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '关联盘点明细 wms_stock_check_detail.id',
},
stock_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '库存商品ID(冗余,商品维度查询),关联 wms_stock_warehouse.id;NULL=未知商品',
},
barcode: {
type: STRING(100),
allowNull: true,
comment: '扫描到的条码/编码(未知商品上报使用;已知商品可为空)',
},
item_name: {
type: STRING(255),
allowNull: true,
comment: '未知商品名称快照(缺省为条码);已知商品为空',
},
is_empty: {
type: BOOLEAN,
allowNull: false,
defaultValue: false,
comment: '是否空库位标记(true=确认库位为空,stock_id/barcode/item_name 均为空、quantity=0)',
},
location_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '库位ID,关联 wms_location_space.id;库位编码匹配时回填,未匹配为空',
},
location_code: {
type: STRING(50),
allowNull: false,
defaultValue: '',
comment: '库位编码(盘点上报的库位,空串表示无库位分组)',
},
quantity: {
type: INTEGER(12),
allowNull: false,
defaultValue: 0,
comment: '实盘数量(不小于0的整数)',
},
checker_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '盘点人账户ID',
},
checker_name: {
type: STRING(50),
allowNull: true,
comment: '盘点人名称快照',
},
checked_at: {
type: DATE,
allowNull: true,
comment: '上报时间',
},
remark: {
type: STRING(500),
allowNull: true,
comment: '备注',
},
}, {
tableName: 'wms_stock_check_record',
comment: '库存盘点作业记录表(库位+数量)',
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
paranoid: false,
indexes: [
{ name: 'idx_check_id', fields: [ 'check_id' ] },
{ name: 'idx_detail_id', fields: [ 'detail_id' ] },
{ name: 'idx_stock_id', fields: [ 'stock_id' ] },
{ name: 'idx_warehouse_location', fields: [ 'warehouse_id', 'location_code' ] },
{ name: 'uk_detail_stock_location', unique: true, fields: [ 'detail_id', 'stock_id', 'location_code' ] },
],
});
StockCheckRecord.associate = function() {
const { StockCheck, StockCheckDetail, StockWarehouse } = app.model;
// 关联盘点主表
StockCheckRecord.belongsTo(StockCheck, {
foreignKey: 'check_id',
as: 'check',
});
// 关联盘点明细
StockCheckRecord.belongsTo(StockCheckDetail, {
foreignKey: 'detail_id',
as: 'detail',
});
// 关联库存商品
StockCheckRecord.belongsTo(StockWarehouse, {
foreignKey: 'stock_id',
as: 'stockWarehouse',
});
};
return StockCheckRecord;
};