WMS_MAIN/app/model/receiving_detail.js
liufumingren 19c3fe09a7 refactor(weight): 重量字段统一为 INTEGER(g),取代 DECIMAL(kg)
- 8 个 model 重量字段类型 DECIMAL→INTEGER,注释 kg→g

- order_express 称重校验改为正整数(g)

- delivery_order 手动单查 StockStore + warehouse 称重毛重

- openapi.json 毛重/净重描述 kg→g

- 迁移: 20260725120000-unify-weight-fields-to-int-g

- 脚本: update-stock-warehouse-weight.cjs
2026-07-27 03:46:07 +08:00

183 lines
4.0 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(11),
allowNull: true,
defaultValue: 0,
comment: '重量(g)',
},
box_remainder: {
type: INTEGER,
allowNull: false,
defaultValue: 0,
comment: '箱余数',
},
box_weight: {
type: INTEGER(11),
allowNull: false,
defaultValue: 0,
comment: '箱重量(g)',
},
}, {
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;
};