WMS_MAIN/app/model/receiving_detail.js
liufumingren 5ef99e3bed 1
2026-07-01 14:00:59 +08:00

180 lines
3.9 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.

// app/model/receiving_detail.js
module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM, BIGINT } = app.Sequelize;
const ReceivingDetail = app.model.define('wms_receiving_detail', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
comment: '明细ID',
},
receiving_id: {
type: INTEGER,
allowNull: false,
comment: '收货单ID',
},
product_name: {
type: STRING(200),
allowNull: false,
comment: '商品名称',
},
barcode: {
type: STRING(100),
comment: '商品条码',
},
product_snapshot: {
type: TEXT,
comment: '商品信息快照(JSON格式)',
},
system_product_id: {
type: INTEGER,
comment: '关联的系统商品ID(可以为空)',
},
actual_quantity: {
type: INTEGER,
allowNull: false,
comment: '实际收货数量',
},
box_quantity: {
type: INTEGER,
defaultValue: 0,
comment: '箱数',
},
boxes_per_pallet: {
type: INTEGER,
defaultValue: 1,
comment: '每托盘箱数(箱规)',
},
pallet_quantity: {
type: INTEGER,
defaultValue: 0,
comment: '托盘数',
},
receiving_time: {
type: DATE,
comment: '收货时间(该商品的收货时间)',
},
receiving_status: {
type: ENUM('pending', 'receiving', 'completed', 'cancelled'),
defaultValue: 'pending',
comment: '收货状态',
},
storage_status: {
type: ENUM('none', 'waiting', 'partial', 'all'),
defaultValue: 'none',
comment: '入库状态:none-未入库, waiting-等待入库, partial-部分入库, all-全部入库',
},
stored_quantity: {
type: INTEGER,
defaultValue: 0,
comment: '已入库数量',
},
batch_number: {
type: STRING(100),
comment: '批次号',
},
production_date: {
type: DATE,
comment: '生产日期',
},
expiry_date: {
type: DATE,
comment: '保质期/到期日期',
},
remark: {
type: TEXT,
comment: '备注',
},
space_id: {
type: BIGINT.UNSIGNED,
defaultValue: 1,
comment: '存放库位',
},
creator_id: {
type: BIGINT.UNSIGNED,
allowNull: false,
},
box_width: {
type: DECIMAL(10, 2),
},
box_length: {
type: DECIMAL(10, 2),
},
box_height: {
type: DECIMAL(10, 2),
},
weight: {
type: INTEGER,
},
box_remainder: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
comment: '箱余数',
},
box_weight: {
type: DECIMAL(10, 2),
allowNull: false,
defaultValue: '0.00',
comment: '箱重量(kg)',
},
}, {
tableName: 'wms_receiving_detail',
timestamps: true,
createdAt: 'created_at',
updatedAt: 'updated_at',
paranoid: false,
indexes: [
{
fields: [ 'receiving_id' ],
},
{
fields: [ 'barcode' ],
},
{
fields: [ 'system_product_id' ],
},
{
fields: [ 'receiving_status' ],
},
{
fields: [ 'storage_status' ],
},
{
fields: [ 'matched_status' ],
},
{
fields: [ 'batch_number' ],
},
{
fields: [ 'receiving_id', 'barcode' ], // 添加这个复合索引
},
],
});
ReceivingDetail.associate = function() {
const { Receiving, StockWarehouse, LocationSpace } = app.model;
// 关联主表
ReceivingDetail.belongsTo(Receiving, {
foreignKey: 'receiving_id',
as: 'receiving',
});
// 关联系统商品
ReceivingDetail.belongsTo(StockWarehouse, {
foreignKey: 'system_product_id',
as: 'system_product',
});
// 关联系统商品
ReceivingDetail.belongsTo(LocationSpace, {
foreignKey: 'space_id',
as: 'receiving_space',
});
};
return ReceivingDetail;
};