WMS_MAIN/app/model/stock_transaction.js
liufumingren 9845a239e2 1
2026-05-16 02:44:53 +08:00

175 lines
4.1 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';
module.exports = app => {
const { STRING, INTEGER, BIGINT, ENUM, DATE, TEXT } = app.Sequelize;
const StockTransaction = app.model.define('stock_transaction', {
id: {
type: BIGINT(20).UNSIGNED,
primaryKey: true,
autoIncrement: true,
comment: '主键ID',
},
transaction_type: {
type: ENUM('INBOUND', 'OUTBOUND', 'TRANSFER_OUT', 'TRANSFER_IN'),
allowNull: false,
comment: '出入库类型',
},
warehouse_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '仓库ID',
},
store_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '货主ID',
},
stock_id: {
type: BIGINT(20).UNSIGNED,
allowNull: false,
comment: '商品库存ID,关联 wms_stock_warehouse.id',
},
storage_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '库位库存ID,关联 wms_storage.id',
},
space_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '库位ID',
},
quantity: {
type: INTEGER(12),
allowNull: false,
comment: '变动数量(正数)',
},
before_quantity: {
type: INTEGER(12),
allowNull: true,
comment: '变更前总库存数量',
},
after_quantity: {
type: INTEGER(12),
allowNull: true,
comment: '变更后总库存数量',
},
before_locked_quantity: {
type: INTEGER(12),
allowNull: true,
comment: '变更前锁定数量',
},
after_locked_quantity: {
type: INTEGER(12),
allowNull: true,
comment: '变更后锁定数量',
},
batch_no: {
type: STRING(100),
allowNull: true,
comment: '批次号',
},
inventory_type: {
type: ENUM('ZP', 'CC', 'JS', 'XS', 'ZT', 'DJ', 'FP'),
defaultValue: 'ZP',
comment: '库存类型',
},
order_type: {
type: STRING(50),
allowNull: true,
comment: '关联单据类型(如 SCRK=收货入库, MATCH=匹配入库, CGTH=采购退货等)',
},
order_no: {
type: TEXT,
allowNull: true,
comment: '关联单据号',
},
order_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '关联单据ID',
},
receiving_id: {
type: INTEGER,
allowNull: true,
comment: '关联收货单ID',
},
entry_order_id: {
type: BIGINT(20).UNSIGNED,
allowNull: true,
comment: '关联入库单ID',
},
operator_id: {
type: STRING(100),
allowNull: true,
comment: '操作人ID',
},
operator_name: {
type: STRING(100),
allowNull: true,
comment: '操作人名称',
},
remark: {
type: STRING(500),
allowNull: true,
comment: '备注',
},
created_at: {
type: DATE,
allowNull: false,
defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
comment: '创建时间',
},
}, {
tableName: 'wms_stock_transaction',
freezeTableName: true,
timestamps: false,
comment: '出入库流水记录表',
indexes: [
{
name: 'idx_stock_id',
fields: [ 'stock_id' ],
},
{
name: 'idx_warehouse_time',
fields: [ 'warehouse_id', 'created_at' ],
},
{
name: 'idx_order',
fields: [ 'order_type', 'order_id' ],
},
{
name: 'idx_receiving_id',
fields: [ 'receiving_id' ],
},
{
name: 'idx_entry_order_id',
fields: [ 'entry_order_id' ],
},
{
name: 'idx_created_at',
fields: [ 'created_at' ],
},
{
name: 'idx_store_transaction_type',
fields: [ 'store_id', 'transaction_type' ],
},
],
});
StockTransaction.associate = function() {
const { StockWarehouse, Storage } = app.model;
StockTransaction.belongsTo(StockWarehouse, {
foreignKey: 'stock_id',
as: 'stockItem',
});
StockTransaction.belongsTo(Storage, {
foreignKey: 'storage_id',
as: 'storageRecord',
});
};
return StockTransaction;
};