WMS_MAIN/app/model/stock_check_detail.js

143 lines
3.8 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';
/**
* 库存盘点明细表模型。
* @param {import('egg').Application} app Egg 应用实例。
* @return {import('sequelize').ModelCtor<import('sequelize').Model>} Sequelize 模型。
*/
module.exports = app => {
const { BIGINT, STRING, INTEGER, DATE, TINYINT } = 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',
},
location_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '库位ID,关联 wms_location_space.id;无库位商品为空',
},
location_code: {
type: STRING(50),
allowNull: true,
comment: '库位编码快照(space_code)',
},
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: '账面数量(生成盘点任务时的系统库存快照)',
},
check_quantity: {
type: INTEGER(12),
allowNull: true,
comment: '实盘数量;未盘点时为空',
},
diff_quantity: {
type: INTEGER(12),
allowNull: true,
comment: '差异数量 = 实盘数量 - 账面数量;正数盘盈,负数盘亏;未盘点时为空',
},
is_diff: {
type: TINYINT(1),
allowNull: false,
defaultValue: 0,
comment: '是否有差异:1=有差异,0=无差异',
},
status: {
type: STRING(20),
allowNull: false,
defaultValue: 'unchecked',
comment: '明细状态:unchecked=未盘,checked=已盘,confirmed=已确认',
},
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_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' ] },
{ name: 'idx_location_id', fields: [ 'location_id' ] },
{ name: 'idx_is_diff', fields: [ 'is_diff' ] },
],
});
StockCheckDetail.associate = function() {
const { StockCheck, StockWarehouse } = app.model;
// 关联盘点主表
StockCheckDetail.belongsTo(StockCheck, {
foreignKey: 'check_id',
as: 'check',
});
// 关联库存商品
StockCheckDetail.belongsTo(StockWarehouse, {
foreignKey: 'stock_id',
as: 'stockWarehouse',
});
};
return StockCheckDetail;
};