WMS_MAIN/app/model/stock_check_detail.js

100 lines
2.7 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';
/**
* 库存盘点明细表模型(仅存盘点商品:stock_id + 商品快照)。
* 库位/数量等盘点作业信息存放在 wms_stock_check_record。
* @param {import('egg').Application} app Egg 应用实例。
* @return {import('sequelize').ModelCtor<import('sequelize').Model>} Sequelize 模型。
*/
module.exports = app => {
const { BIGINT, STRING, INTEGER } = app.Sequelize;
const StockCheckDetail = app.model.define('wms_stock_check_detail', {
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(冗余,隔离查询)',
},
stock_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '库存商品ID,关联 wms_stock_warehouse.id',
},
item_code: {
type: STRING(50),
allowNull: false,
comment: '商品编码快照',
},
item_name: {
type: STRING(255),
allowNull: true,
comment: '商品名称快照',
},
spec: {
type: STRING(100),
allowNull: true,
comment: '规格快照(sku_property)',
},
batch_no: {
type: STRING(100),
allowNull: true,
comment: '批次号,批次管理商品时记录',
},
system_quantity: {
type: INTEGER(12),
allowNull: false,
defaultValue: 0,
comment: '账面数量快照(生成盘点明细时的系统库存,用于差异对比)',
},
remark: {
type: STRING(500),
allowNull: true,
comment: '备注',
},
}, {
tableName: 'wms_stock_check_detail',
comment: '库存盘点明细表(盘点商品清单)',
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
paranoid: false,
indexes: [
{ name: 'idx_check_id', fields: [ 'check_id' ] },
{ name: 'idx_warehouse_stock', fields: [ 'warehouse_id', 'stock_id' ] },
{ name: 'idx_stock_id', fields: [ 'stock_id' ] },
],
});
StockCheckDetail.associate = function() {
const { StockCheck, StockWarehouse, StockCheckRecord } = app.model;
// 关联盘点主表
StockCheckDetail.belongsTo(StockCheck, {
foreignKey: 'check_id',
as: 'check',
});
// 关联库存商品
StockCheckDetail.belongsTo(StockWarehouse, {
foreignKey: 'stock_id',
as: 'stockWarehouse',
});
// 一条明细对应多条盘点作业记录
StockCheckDetail.hasMany(StockCheckRecord, {
foreignKey: 'detail_id',
as: 'records',
});
};
return StockCheckDetail;
};