oms/backend/database/migrations/20261105070300-add-subsidiary-to-stock-bills.js
liufumingren 9774ee1414 feat(stock): 出入库单/记录增加货主并按货主隔离,创建人显示员工名称
- 迁移:inbound_orders / outbound_orders 增加 subsidiary_id 与索引,按仓库回填
- 单据货主由仓库决定:创建写入、改仓库同步,接口不接受直写 subsidiary_id
- 入库单/出库单列表返回 subsidiary_name 并新增货主筛选;详情/编辑/删除/审核/
  推送/完成/取消/恢复/作废/驳回与明细接口统一加货主越界 403
- 出入库记录按仓库归属货主:列表与导出收窄、返回 subsidiary_id/subsidiary_name、
  新增货主列与筛选
- 导出:入库单/出库单/出入库记录新增货主列并按所在公司权限收窄
- 新增 resolveAccountNameMap:列表/详情返回 creator_name/auditor_name/voider_name,
  创建人展示员工名称(principal_users.name),不再回退成邮箱账号
- 前端:三个列表新增货主列与筛选,创建人/作废人展示改为员工名称

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-05 15:13:22 +08:00

42 lines
1.5 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';
/**
* 出入库单绑定货主(下属公司):inbound_orders / outbound_orders 增加 subsidiary_id。
*
* 取值跟随单据仓库的货主(warehouses.subsidiary_id),历史数据按仓库回填;
* 货主权限仅可见自己所属公司的出入库单,且不可越界操作。
*/
const BILL_TABLES = [ 'inbound_orders', 'outbound_orders' ];
module.exports = {
async up(queryInterface, Sequelize) {
for (const table of BILL_TABLES) {
await queryInterface.addColumn(table, 'subsidiary_id', {
type: Sequelize.BIGINT.UNSIGNED,
allowNull: true,
comment: '所属货主(下属公司ID),跟随仓库',
references: { model: 'principal_subsidiaries', key: 'id' },
after: 'principal_id',
});
await queryInterface.addIndex(table, [ 'principal_id', 'subsidiary_id' ], {
name: `idx_${table}_principal_subsidiary`,
});
// 按单据仓库的货主回填历史数据
await queryInterface.sequelize.query(
`UPDATE ${table} t`
+ ' JOIN warehouses w ON w.id = t.warehouse_id'
+ ' SET t.subsidiary_id = w.subsidiary_id'
+ ' WHERE t.subsidiary_id IS NULL AND w.subsidiary_id IS NOT NULL'
);
}
},
async down(queryInterface) {
for (const table of BILL_TABLES) {
await queryInterface.removeIndex(table, `idx_${table}_principal_subsidiary`);
await queryInterface.removeColumn(table, 'subsidiary_id');
}
},
};