- 入库单 COMPLETED 状态放开绑定收货单,事务内按 SKU 同步收货单明细入库进度(stored_quantity/storage_status) - wms_entry_order_receiving 新增 allocated_quantity 台账列(迁移已在生产执行),多收货单绑定按剩余可分配量封顶防超扣 - 统一锁序(入库单主行→绑定行→收货明细行)修复并发绑定死锁;解绑/作废按台账回滚,不再整体清零共享收货单 - 同步 entry_items.received_quantity 口径,与绑定收货单 stored_quantity 可对账 - 同步 methods 文档与变更记录、AI_METHOD_ROUTING 方法清单
83 lines
2.0 KiB
JavaScript
83 lines
2.0 KiB
JavaScript
'use strict';
|
||
|
||
module.exports = app => {
|
||
const { BIGINT, DATE, JSON: JSON_TYPE } = app.Sequelize;
|
||
|
||
const EntryOrderReceiving = app.model.define('wms_entry_order_receiving', {
|
||
id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
primaryKey: true,
|
||
autoIncrement: true,
|
||
comment: '主键ID',
|
||
},
|
||
entry_order_id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
allowNull: false,
|
||
comment: '入库单ID,关联 wms_entry_order.id',
|
||
},
|
||
receiving_id: {
|
||
type: BIGINT(20).UNSIGNED,
|
||
allowNull: false,
|
||
comment: '收货单ID,关联 wms_receiving.id',
|
||
},
|
||
allocated_quantity: {
|
||
type: JSON_TYPE,
|
||
allowNull: true,
|
||
defaultValue: null,
|
||
comment: '数量台账:收货明细ID→已分配数量(JSON对象,如 {"123":8});null 表示旧数据未初始化',
|
||
},
|
||
created_at: {
|
||
type: DATE,
|
||
allowNull: false,
|
||
comment: '创建时间',
|
||
},
|
||
updated_at: {
|
||
type: DATE,
|
||
allowNull: false,
|
||
comment: '更新时间',
|
||
},
|
||
}, {
|
||
tableName: 'wms_entry_order_receiving',
|
||
comment: '入库单-收货单主表级绑定关系表',
|
||
timestamps: true,
|
||
createdAt: 'created_at',
|
||
updatedAt: 'updated_at',
|
||
paranoid: true,
|
||
deletedAt: 'deleted_at',
|
||
indexes: [
|
||
{
|
||
name: 'idx_entry_order_id',
|
||
fields: [ 'entry_order_id' ],
|
||
},
|
||
{
|
||
name: 'idx_receiving_id',
|
||
fields: [ 'receiving_id' ],
|
||
},
|
||
{
|
||
name: 'uk_entry_order_receiving',
|
||
unique: true,
|
||
fields: [ 'entry_order_id', 'receiving_id' ],
|
||
},
|
||
],
|
||
});
|
||
|
||
// 关联关系
|
||
EntryOrderReceiving.associate = function() {
|
||
const { EntryOrderReceiving, EntryOrder, Receiving } = app.model;
|
||
|
||
// 关联入库单
|
||
EntryOrderReceiving.belongsTo(EntryOrder, {
|
||
foreignKey: 'entry_order_id',
|
||
as: 'entryOrder',
|
||
});
|
||
|
||
// 关联收货单
|
||
EntryOrderReceiving.belongsTo(Receiving, {
|
||
foreignKey: 'receiving_id',
|
||
as: 'receiving',
|
||
});
|
||
};
|
||
|
||
return EntryOrderReceiving;
|
||
};
|