Merge pull request 'fix: 编辑直发单,对应生成单单号保持不变' (#366) from fix_update_direct_record_number into @hera/dev

Reviewed-on: daoyoucloud/tachycode#366
Reviewed-by: sealday <zhanglin@daoyoucloud.com>
This commit is contained in:
sealday 2024-03-13 19:06:01 +08:00
commit b0db14953c

View File

@ -27,7 +27,7 @@ export class RecordService {
if (!values) { if (!values) {
return; return;
} }
await this.createRecord(model, values, transaction, context); await this.createRecord(model, values, transaction, context, null);
} }
/** /**
* *
@ -45,8 +45,9 @@ export class RecordService {
transaction, transaction,
true, true,
); );
const deleteDatas = await this.db.getRepository('records').find({ where: { direct_record_id: model.id } });
// 删除新建时创建的订单 // 删除新建时创建的订单
const data = await this.db.sequelize.query( await this.db.sequelize.query(
` `
delete from records delete from records
where records.direct_record_id = ${model.id} where records.direct_record_id = ${model.id}
@ -55,7 +56,17 @@ export class RecordService {
transaction, transaction,
}, },
); );
await this.createRecord(model, values, transaction, context); const updateData = deleteDatas.map((item) => {
if (item) {
return {
number: item.number,
record_category: item.record_category,
category: item.category,
movement: item.movement,
};
}
});
await this.createRecord(model, values, transaction, context, updateData);
} }
} }
/** /**
@ -634,7 +645,9 @@ export class RecordService {
/** /**
* *
*/ */
async createRecord(model, values, transaction, context) { async createRecord(model, values, transaction, context, updateData) {
delete values.number;
delete values.id;
//采购直发单 //采购直发单
if (values.record_category === RecordTypes.purchaseDirect && values.category === RecordCategory.purchase2lease) { if (values.record_category === RecordTypes.purchaseDirect && values.category === RecordCategory.purchase2lease) {
const inProject = await this.db.getModel('project').findOne({ const inProject = await this.db.getModel('project').findOne({
@ -657,9 +670,14 @@ export class RecordService {
purchaseData['movement'] = Movement.in; purchaseData['movement'] = Movement.in;
purchaseData['category'] = RecordCategory.purchase; purchaseData['category'] = RecordCategory.purchase;
purchaseData['in_stock'] = base_project.dataValues; purchaseData['in_stock'] = base_project.dataValues;
// 编辑时需要删除携带的这写参数 if (updateData) {
delete purchaseData.id; purchaseData['number'] = updateData.find(
delete purchaseData.number; (item) =>
item.category === RecordCategory.purchase &&
item.record_category === RecordTypes.purchaseInStock &&
item.movement === Movement.in,
).number;
}
purchaseData.items.forEach((element) => { purchaseData.items.forEach((element) => {
delete element.record_id; delete element.record_id;
delete element.id; delete element.id;
@ -676,9 +694,14 @@ export class RecordService {
leaseData['contract'] = values.in_contract; leaseData['contract'] = values.in_contract;
leaseData['out_stock'] = base_project.dataValues; leaseData['out_stock'] = base_project.dataValues;
leaseData['in_stock'] = inProject.dataValues; leaseData['in_stock'] = inProject.dataValues;
// 编辑时需要删除携带的这写参数 if (updateData) {
delete leaseData.id; leaseData['number'] = updateData.find(
delete leaseData.number; (item) =>
item.category === RecordCategory.lease &&
item.record_category === RecordTypes.rentOutStock &&
item.movement === Movement.out,
).number;
}
leaseData.items.forEach((element) => { leaseData.items.forEach((element) => {
delete element.record_id; delete element.record_id;
delete element.id; delete element.id;
@ -713,9 +736,14 @@ export class RecordService {
leaseInData['contract'] = values.in_contract; leaseInData['contract'] = values.in_contract;
leaseInData['out_stock'] = outProject.dataValues; leaseInData['out_stock'] = outProject.dataValues;
leaseInData['in_stock'] = baseProject.dataValues; leaseInData['in_stock'] = baseProject.dataValues;
// 编辑时需要删除携带的这写参数 if (updateData) {
delete leaseInData.id; leaseInData['number'] = updateData.find(
delete leaseInData.number; (item) =>
item.category === RecordCategory.lease &&
item.record_category === RecordTypes.rentInStock &&
item.movement === Movement.in,
).number;
}
leaseInData.items.forEach((element) => { leaseInData.items.forEach((element) => {
delete element.record_id; delete element.record_id;
delete element.id; delete element.id;
@ -732,9 +760,14 @@ export class RecordService {
leaseOutData['contract'] = values.in_contract; leaseOutData['contract'] = values.in_contract;
leaseOutData['out_stock'] = baseProject.dataValues; leaseOutData['out_stock'] = baseProject.dataValues;
leaseOutData['in_stock'] = inProject.dataValues; leaseOutData['in_stock'] = inProject.dataValues;
// 编辑时需要删除携带的这写参数 if (updateData) {
delete leaseOutData.id; leaseOutData['number'] = updateData.find(
delete leaseOutData.number; (item) =>
item.category === RecordCategory.lease &&
item.record_category === RecordTypes.rentOutStock &&
item.movement === Movement.out,
).number;
}
leaseOutData.items.forEach((element) => { leaseOutData.items.forEach((element) => {
delete element.record_id; delete element.record_id;
delete element.id; delete element.id;