@things-factory/sales-base 4.3.770 → 4.3.771

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -101,7 +101,7 @@ export async function generateReleaseGoods(_generateReleaseGoodsRecord, context:
101
101
  })
102
102
 
103
103
  for (let index = 0; index < updatableDraftOrders.length; index++) {
104
- await getConnection().transaction(async (innerTx1: EntityManager) => {
104
+ await getConnection().transaction(async (orderTx: EntityManager) => {
105
105
  const draftOrder = updatableDraftOrders[index]
106
106
  const releaseShelfLifeOverride =
107
107
  draftOrder?.deliverTo?.releaseShelfLife != null && draftOrder.deliverTo.releaseShelfLife !== 0
@@ -112,11 +112,11 @@ export async function generateReleaseGoods(_generateReleaseGoodsRecord, context:
112
112
  let companyBizplace: Bizplace
113
113
 
114
114
  if (draftOrder?.bizplace?.id) {
115
- foundPermittedBizplace = await innerTx1.getRepository(Bizplace).findOne(draftOrder.bizplace.id, {
115
+ foundPermittedBizplace = await orderTx.getRepository(Bizplace).findOne(draftOrder.bizplace.id, {
116
116
  relations: ['company', 'company.domain']
117
117
  })
118
118
  const companyDomain: Domain = foundPermittedBizplace.company.domain
119
- companyBizplace = await innerTx1.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
119
+ companyBizplace = await orderTx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
120
120
  } else {
121
121
  return false
122
122
  }
@@ -187,7 +187,7 @@ export async function generateReleaseGoods(_generateReleaseGoodsRecord, context:
187
187
  : filters
188
188
  },
189
189
  context,
190
- innerTx1
190
+ orderTx
191
191
  )
192
192
 
193
193
  draftOrder.orderProducts = draftOrder.orderProducts.map(itm => {
@@ -196,7 +196,8 @@ export async function generateReleaseGoods(_generateReleaseGoodsRecord, context:
196
196
  foundProductInv = productInventory.items.find(
197
197
  i =>
198
198
  (i.productDetailId == itm?.productDetailId || i.productId == itm?.productBundle?.id) &&
199
- itm.releaseQty <= i.remainQty
199
+ itm.releaseQty <= i.remainQty &&
200
+ i.remainQty > 0
200
201
  )
201
202
  if (!foundProductInv) {
202
203
  failReleaseOrder.push(draftOrder.name)
@@ -206,14 +207,15 @@ export async function generateReleaseGoods(_generateReleaseGoodsRecord, context:
206
207
  foundProductInv = productInventory.items.find(
207
208
  i =>
208
209
  (i.productDetailId == pbs?.productDetail.id || i.productId == pbs?.product?.id) &&
209
- itm.releaseQty <= i.remainQty
210
+ itm.releaseQty <= i.remainQty &&
211
+ i.remainQty > 0
210
212
  )
211
213
  })
212
214
  }
213
215
  return {
214
216
  ...itm,
215
- releaseUomValue: foundProductInv
216
- ? (foundProductInv?.remainUomValue / foundProductInv?.remainQty) * itm.releaseQty
217
+ releaseUomValue: foundProductInv && foundProductInv.remainQty > 0
218
+ ? (foundProductInv.remainUomValue / foundProductInv.remainQty) * itm.releaseQty
217
219
  : 0,
218
220
  status: foundProductInv ? 'suffice' : 'insufficient'
219
221
  }
@@ -248,7 +250,7 @@ export async function generateReleaseGoods(_generateReleaseGoodsRecord, context:
248
250
  const itm: Partial<OrderProduct> = draftOrder.orderProducts[index]
249
251
  let data = []
250
252
  if (itm.productBundle) {
251
- let bundle: ProductBundle = await innerTx1.getRepository(ProductBundle).findOne({
253
+ let bundle: ProductBundle = await orderTx.getRepository(ProductBundle).findOne({
252
254
  where: { id: itm.productBundle.id },
253
255
  relations: [
254
256
  'productBundleSettings',
@@ -304,112 +306,105 @@ export async function generateReleaseGoods(_generateReleaseGoodsRecord, context:
304
306
 
305
307
  if (existingOI) {
306
308
  existingOI.releaseQty = existingOI.releaseQty + data.releaseQty
307
- existingOI.releaseUomValue = existingOI.releaseUomValue + data.uomValue
308
- existingOI.uomValue = existingOI.uomValue + data.uomValue
309
+ existingOI.releaseUomValue = existingOI.releaseUomValue + data.releaseUomValue
310
+ existingOI.uomValue = (existingOI.uomValue || 0) + data.releaseUomValue
309
311
  } else {
310
- orderInventories.push({ ...data, orderProduct: itm })
312
+ orderInventories.push({ ...data, uomValue: data.releaseUomValue, orderProduct: itm })
311
313
  }
312
314
  })
313
315
  }
314
316
 
315
- await getConnection().transaction(async (innerTx2: EntityManager) => {
316
- const foundRo = await innerTx2.getRepository(ReleaseGood).find({
317
- where: { draftReleaseGood: { id: draftOrder.id }, domain }
318
- })
319
-
320
- if (foundRo.length > 0) {
321
- throw new Error('generating release orders')
322
- }
317
+ const foundRo = await orderTx.getRepository(ReleaseGood).find({
318
+ where: { draftReleaseGood: { id: draftOrder.id }, domain }
319
+ })
323
320
 
324
- let availableItems: any[] = await bulkReleaseGoodsAvailableItemsFunction(
325
- orderInventories,
326
- draftOrder.bizplace.id,
327
- context,
328
- innerTx2
329
- )
321
+ if (foundRo.length > 0) {
322
+ throw new Error('generating release orders')
323
+ }
330
324
 
331
- if (availableItems.some(item => item.orderProduct.productDetail.deletedAt != null)) {
332
- throw new ValidationError({
333
- ...ValidationError.ERROR_CODES.DELETED_PRODUCT_DETAIL,
334
- detail: { data: JSON.stringify(availableItems) }
335
- })
336
- }
325
+ let availableItems: any[] = await bulkReleaseGoodsAvailableItemsFunction(
326
+ orderInventories,
327
+ draftOrder.bizplace.id,
328
+ context,
329
+ orderTx
330
+ )
337
331
 
338
- if (availableItems.some(item => !item.releaseQty || item.releaseQty > item.assignedQty))
339
- throw new ValidationError({
340
- ...ValidationError.ERROR_CODES.INSUFFICIENT_STOCK,
341
- detail: { data: JSON.stringify(availableItems) }
342
- })
343
- // update orderInventories if availableItems are valid
344
- releaseGood.noOfItems = orderInventories.length
332
+ if (availableItems.some(item => item.orderProduct.productDetail.deletedAt != null)) {
333
+ throw new ValidationError({
334
+ ...ValidationError.ERROR_CODES.DELETED_PRODUCT_DETAIL,
335
+ detail: { data: JSON.stringify(availableItems) }
336
+ })
337
+ }
345
338
 
346
- releaseGood.orderInventories = availableItems.map(itm => {
347
- return {
348
- ...itm,
349
- releaseQty: itm.releaseQty,
350
- releaseUomValue: itm.releaseUomValue,
351
- uomValue: itm.uomValue
352
- }
339
+ if (availableItems.some(item => !item.releaseQty || item.releaseQty > item.assignedQty))
340
+ throw new ValidationError({
341
+ ...ValidationError.ERROR_CODES.INSUFFICIENT_STOCK,
342
+ detail: { data: JSON.stringify(availableItems) }
353
343
  })
344
+ // update orderInventories if availableItems are valid
345
+ releaseGood.noOfItems = orderInventories.length
354
346
 
355
- let createdReleaseGood: ReleaseGood
356
-
357
- await getConnection().transaction(async (innerTx3: EntityManager) => {
358
- createdReleaseGood = await bulkGenerateReleaseGood(
359
- releaseGood,
360
- releaseGood.bizplace.id,
361
- roNoSetting,
362
- domain,
363
- user,
364
- draftOrder,
365
- innerTx3
366
- )
347
+ releaseGood.orderInventories = availableItems.map(itm => {
348
+ return {
349
+ ...itm,
350
+ releaseQty: itm.releaseQty,
351
+ releaseUomValue: itm.releaseUomValue,
352
+ uomValue: itm.uomValue
353
+ }
354
+ })
367
355
 
368
- const existingReleaseGood = await innerTx3.getRepository(ReleaseGood).find({
369
- where: { draftReleaseGood: { id: draftOrder.id }, domain }
370
- })
356
+ let createdReleaseGood: ReleaseGood = await bulkGenerateReleaseGood(
357
+ releaseGood,
358
+ releaseGood.bizplace.id,
359
+ roNoSetting,
360
+ domain,
361
+ user,
362
+ draftOrder,
363
+ orderTx
364
+ )
371
365
 
372
- if (existingReleaseGood.length > 1) {
373
- throw new Error('generating release orders')
374
- }
375
- // successReleaseOrder.push({ draftName: draftOrder?.name, status: 'success' })
376
- })
366
+ const existingReleaseGood = await orderTx.getRepository(ReleaseGood).find({
367
+ where: { draftReleaseGood: { id: draftOrder.id }, domain }
368
+ })
377
369
 
378
- await innerTx2
379
- .getRepository(DraftReleaseGood)
380
- .update({ id: draftOrder.id }, { status: DRAFT_RELEASE_ORDER_STATUS.SUBMITTED })
370
+ if (existingReleaseGood.length > 1) {
371
+ throw new Error('generating release orders')
372
+ }
381
373
 
382
- const directReceiveSetting: Setting = await innerTx2.getRepository(Setting).findOne({
383
- where: { domain, category: 'id-rule', name: 'enable-direct-receive-release-order' }
384
- })
374
+ await orderTx
375
+ .getRepository(DraftReleaseGood)
376
+ .update({ id: draftOrder.id }, { status: DRAFT_RELEASE_ORDER_STATUS.SUBMITTED })
385
377
 
386
- const partnerDirectReceiveSetting: PartnerSetting = await innerTx2
387
- .getRepository(PartnerSetting)
388
- .findOne({
389
- where: { setting: directReceiveSetting, domain, partnerDomain: draftOrder.bizplace?.domain }
390
- })
378
+ const directReceiveSetting: Setting = await orderTx.getRepository(Setting).findOne({
379
+ where: { domain, category: 'id-rule', name: 'enable-direct-receive-release-order' }
380
+ })
381
+
382
+ const partnerDirectReceiveSetting: PartnerSetting = await orderTx
383
+ .getRepository(PartnerSetting)
384
+ .findOne({
385
+ where: { setting: directReceiveSetting, domain, partnerDomain: draftOrder.bizplace?.domain }
386
+ })
391
387
 
392
- let settingValue
388
+ let settingValue
393
389
 
394
- if (
395
- !isNaN(partnerDirectReceiveSetting?.value) &&
396
- !isNaN(parseFloat(partnerDirectReceiveSetting?.value))
397
- ) {
398
- settingValue = parseFloat(partnerDirectReceiveSetting.value)
399
- } else {
400
- settingValue = parseFloat(directReceiveSetting.value)
401
- }
390
+ if (
391
+ !isNaN(partnerDirectReceiveSetting?.value) &&
392
+ !isNaN(parseFloat(partnerDirectReceiveSetting?.value))
393
+ ) {
394
+ settingValue = parseFloat(partnerDirectReceiveSetting.value)
395
+ } else {
396
+ settingValue = parseFloat(directReceiveSetting.value)
397
+ }
402
398
 
403
- createdReleaseGood = await confirmReleaseGood(createdReleaseGood.name, context, innerTx2)
399
+ createdReleaseGood = await confirmReleaseGood(createdReleaseGood.name, context, orderTx)
404
400
 
405
- successReleaseOrder.push({ draftName: draftOrder?.name, status: 'success' })
406
- if (settingValue > 1) {
407
- createdReleaseGood = await receiveReleaseGood(createdReleaseGood.name, context, innerTx2)
408
- }
401
+ successReleaseOrder.push({ draftName: draftOrder?.name, status: 'success' })
402
+ if (settingValue > 1) {
403
+ createdReleaseGood = await receiveReleaseGood(createdReleaseGood.name, context, orderTx)
404
+ }
409
405
 
410
- webhookHandler(draftOrder, draftOrder.bizplace, WebhookEventsEnum.DraftOrderConverted)
411
- webhookHandler(createdReleaseGood, createdReleaseGood.bizplace, WebhookEventsEnum.ReleaseOrderCreated)
412
- })
406
+ webhookHandler(draftOrder, draftOrder.bizplace, WebhookEventsEnum.DraftOrderConverted)
407
+ webhookHandler(createdReleaseGood, createdReleaseGood.bizplace, WebhookEventsEnum.ReleaseOrderCreated)
413
408
  } else {
414
409
  if (
415
410
  draftOrder.orderProducts.some(op => op.id === failedInventory?.id && op.productDetail.deletedAt != null)
@@ -492,22 +487,16 @@ export async function generatePartialReleaseGoods(_generatePartialReleaseGoodsRe
492
487
  })
493
488
 
494
489
  for (let draftOrder of updatableDraftOrders) {
495
- await getConnection().transaction(async (tx: EntityManager) => {
490
+ await getConnection().transaction(async (orderTx: EntityManager) => {
496
491
  let foundPermittedBizplace: Bizplace
497
492
  let companyBizplace: Bizplace
498
493
 
499
- // //remove op productBundle as there no support for partial release
500
-
501
- // if (draftOrder.orderProducts.some(itm => !itm.product)) {
502
- // draftOrder.orderProducts = draftOrder.orderProducts.filter(itm => itm.product)
503
- // }
504
-
505
494
  if (draftOrder?.bizplace?.id) {
506
- foundPermittedBizplace = await tx.getRepository(Bizplace).findOne(draftOrder.bizplace.id, {
495
+ foundPermittedBizplace = await orderTx.getRepository(Bizplace).findOne(draftOrder.bizplace.id, {
507
496
  relations: ['company', 'company.domain']
508
497
  })
509
498
  const companyDomain: Domain = foundPermittedBizplace.company.domain
510
- companyBizplace = await tx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
499
+ companyBizplace = await orderTx.getRepository(Bizplace).findOne({ where: { domain: companyDomain } })
511
500
  } else {
512
501
  return false
513
502
  }
@@ -541,7 +530,7 @@ export async function generatePartialReleaseGoods(_generatePartialReleaseGoodsRe
541
530
  ]
542
531
  },
543
532
  context,
544
- tx
533
+ orderTx
545
534
  )
546
535
 
547
536
  draftOrder.orderProducts = draftOrder.orderProducts.filter(op => op.status == 'DRAFT')
@@ -556,15 +545,16 @@ export async function generatePartialReleaseGoods(_generatePartialReleaseGoodsRe
556
545
  let foundProductInv = productInventory.items.find(
557
546
  i =>
558
547
  (i.productDetailId == itm?.productDetailId || i.productId == itm?.productBundle?.id) &&
559
- !(i.remainQty === 0)
548
+ i.remainQty > 0
560
549
  )
561
550
  if (foundProductInv && itm.product) {
562
551
  releaseOrderProducts.push({
563
552
  ...itm,
564
- releaseUomValue:
565
- itm.releaseQty > foundProductInv.remainQty
553
+ releaseUomValue: foundProductInv.remainQty > 0
554
+ ? itm.releaseQty > foundProductInv.remainQty
566
555
  ? (foundProductInv.remainUomValue / foundProductInv.remainQty) * foundProductInv.remainQty
567
- : (foundProductInv.remainUomValue / foundProductInv.remainQty) * itm.releaseQty,
556
+ : (foundProductInv.remainUomValue / foundProductInv.remainQty) * itm.releaseQty
557
+ : 0,
568
558
  status: itm.releaseQty <= foundProductInv.remainQty ? 'suffice' : 'partial-release',
569
559
  releaseQty: itm.releaseQty > foundProductInv.remainQty ? foundProductInv.remainQty : itm.releaseQty, //it will take the remainQty instead of releaseQty when remainQty < releaseQty
570
560
  newReleaseQty:
@@ -573,16 +563,19 @@ export async function generatePartialReleaseGoods(_generatePartialReleaseGoodsRe
573
563
  } else if (foundProductInv && itm.productBundle) {
574
564
  itm.productBundle.productBundleSettings.map(pbs => {
575
565
  foundProductInv = productInventory.items.find(
576
- i => i.productDetailId == pbs?.productDetail.id || i.productId == pbs?.product?.id
566
+ i =>
567
+ (i.productDetailId == pbs?.productDetail.id || i.productId == pbs?.product?.id) &&
568
+ i.remainQty > 0
577
569
  )
578
570
 
579
571
  if (foundProductInv) {
580
572
  releaseOrderProducts.push({
581
573
  ...itm,
582
- releaseUomValue:
583
- itm.releaseQty > foundProductInv.remainQty
574
+ releaseUomValue: foundProductInv.remainQty > 0
575
+ ? itm.releaseQty > foundProductInv.remainQty
584
576
  ? (foundProductInv.remainUomValue / foundProductInv.remainQty) * foundProductInv.remainQty
585
- : (foundProductInv.remainUomValue / foundProductInv.remainQty) * itm.releaseQty,
577
+ : (foundProductInv.remainUomValue / foundProductInv.remainQty) * itm.releaseQty
578
+ : 0,
586
579
  status: itm.releaseQty * pbs.bundleQty <= foundProductInv.remainQty ? 'suffice' : 'insuffice'
587
580
  })
588
581
  }
@@ -619,7 +612,7 @@ export async function generatePartialReleaseGoods(_generatePartialReleaseGoodsRe
619
612
  const itm: Partial<OrderProduct> = sufficient[index]
620
613
  let data = []
621
614
  if (itm.productBundle) {
622
- let bundle: ProductBundle = await tx.getRepository(ProductBundle).findOne({
615
+ let bundle: ProductBundle = await orderTx.getRepository(ProductBundle).findOne({
623
616
  where: { id: itm.productBundle.id },
624
617
  relations: [
625
618
  'productBundleSettings',
@@ -672,115 +665,117 @@ export async function generatePartialReleaseGoods(_generatePartialReleaseGoodsRe
672
665
 
673
666
  if (existingOI) {
674
667
  existingOI.releaseQty = existingOI.releaseQty + data.releaseQty
675
- existingOI.releaseUomValue = existingOI.releaseUomValue + data.uomValue
676
- existingOI.uomValue = existingOI.uomValue + data.uomValue
668
+ existingOI.releaseUomValue = existingOI.releaseUomValue + data.releaseUomValue
669
+ existingOI.uomValue = (existingOI.uomValue || 0) + data.releaseUomValue
677
670
  } else {
678
- orderInventories.push({ ...data, orderProduct: itm })
671
+ orderInventories.push({ ...data, uomValue: data.releaseUomValue, orderProduct: itm })
679
672
  }
680
673
  })
681
674
  }
682
- await getConnection().transaction(async (tx: EntityManager) => {
683
- let availableItems: any[] = await bulkReleaseGoodsAvailableItemsFunction(
684
- orderInventories,
685
- draftOrder.bizplace.id,
686
- context,
687
- tx
688
- )
689
675
 
690
- // first condition for partial release (values use for generating release good)
691
- if (draftOrder.id === value.id && value.releaseType === 'partial') {
692
- releaseGood.orderInventories = availableItems.map(itm => {
693
- return {
694
- ...itm,
695
- releaseQty: itm.assignedQty,
696
- releaseUomValue: itm.releaseUomValue,
697
- uomValue: itm.uomValue
698
- }
699
- })
700
- } else if (availableItems.some(item => !item.releaseQty || item.releaseQty > item.assignedQty)) {
701
- throw new ValidationError({
702
- ...ValidationError.ERROR_CODES.INSUFFICIENT_STOCK,
703
- detail: { data: JSON.stringify(availableItems) }
704
- })
705
- } else {
706
- releaseGood.orderInventories = availableItems.map(itm => {
707
- return {
708
- ...itm,
709
- releaseQty: itm.releaseQty,
710
- releaseUomValue: itm.releaseUomValue,
711
- uomValue: itm.uomValue
712
- }
713
- })
714
- }
676
+ let availableItems: any[] = await bulkReleaseGoodsAvailableItemsFunction(
677
+ orderInventories,
678
+ draftOrder.bizplace.id,
679
+ context,
680
+ orderTx
681
+ )
715
682
 
716
- // update orderInventories if availableItems are valid
717
- releaseGood.noOfItems = orderInventories.length
718
-
719
- let createdReleaseGood: ReleaseGood = await bulkGenerateReleaseGood(
720
- releaseGood,
721
- releaseGood.bizplace.id,
722
- roNoSetting,
723
- domain,
724
- user,
725
- draftOrder,
726
- tx
727
- )
683
+ // first condition for partial release (values use for generating release good)
684
+ if (draftOrder.id === value.id && value.releaseType === 'partial') {
685
+ releaseGood.orderInventories = availableItems.map(itm => {
686
+ return {
687
+ ...itm,
688
+ releaseQty: itm.assignedQty,
689
+ releaseUomValue: itm.releaseUomValue,
690
+ uomValue: itm.uomValue
691
+ }
692
+ })
693
+ } else if (availableItems.some(item => !item.releaseQty || item.releaseQty > item.assignedQty)) {
694
+ throw new ValidationError({
695
+ ...ValidationError.ERROR_CODES.INSUFFICIENT_STOCK,
696
+ detail: { data: JSON.stringify(availableItems) }
697
+ })
698
+ } else {
699
+ releaseGood.orderInventories = availableItems.map(itm => {
700
+ return {
701
+ ...itm,
702
+ releaseQty: itm.releaseQty,
703
+ releaseUomValue: itm.releaseUomValue,
704
+ uomValue: itm.uomValue
705
+ }
706
+ })
707
+ }
728
708
 
729
- await tx
730
- .getRepository(DraftReleaseGood)
731
- .update({ id: draftOrder.id }, { status: DRAFT_RELEASE_ORDER_STATUS.PARTIAL_RELEASED })
709
+ // update orderInventories if availableItems are valid
710
+ releaseGood.noOfItems = orderInventories.length
711
+
712
+ let createdReleaseGood: ReleaseGood = await bulkGenerateReleaseGood(
713
+ releaseGood,
714
+ releaseGood.bizplace.id,
715
+ roNoSetting,
716
+ domain,
717
+ user,
718
+ draftOrder,
719
+ orderTx
720
+ )
732
721
 
733
- const directReceiveSetting: Setting = await tx.getRepository(Setting).findOne({
734
- where: { domain, category: 'id-rule', name: 'enable-direct-receive-release-order' }
735
- })
722
+ await orderTx
723
+ .getRepository(DraftReleaseGood)
724
+ .update({ id: draftOrder.id }, { status: DRAFT_RELEASE_ORDER_STATUS.PARTIAL_RELEASED })
736
725
 
737
- const partnerDirectReceiveSetting: PartnerSetting = await tx.getRepository(PartnerSetting).findOne({
726
+ const directReceiveSetting: Setting = await orderTx.getRepository(Setting).findOne({
727
+ where: { domain, category: 'id-rule', name: 'enable-direct-receive-release-order' }
728
+ })
729
+
730
+ const partnerDirectReceiveSetting: PartnerSetting = await orderTx
731
+ .getRepository(PartnerSetting)
732
+ .findOne({
738
733
  where: { setting: directReceiveSetting, domain, partnerDomain: draftOrder.bizplace?.domain }
739
734
  })
740
735
 
741
- let settingValue
736
+ let settingValue
742
737
 
743
- if (
744
- !isNaN(partnerDirectReceiveSetting?.value) &&
745
- !isNaN(parseFloat(partnerDirectReceiveSetting?.value))
746
- ) {
747
- settingValue = parseFloat(partnerDirectReceiveSetting.value)
748
- } else {
749
- settingValue = parseFloat(directReceiveSetting.value)
750
- }
738
+ if (
739
+ !isNaN(partnerDirectReceiveSetting?.value) &&
740
+ !isNaN(parseFloat(partnerDirectReceiveSetting?.value))
741
+ ) {
742
+ settingValue = parseFloat(partnerDirectReceiveSetting.value)
743
+ } else {
744
+ settingValue = parseFloat(directReceiveSetting.value)
745
+ }
746
+
747
+ createdReleaseGood = await confirmReleaseGood(createdReleaseGood.name, context, orderTx)
748
+
749
+ if (settingValue > 1) {
750
+ createdReleaseGood = await receiveReleaseGood(createdReleaseGood.name, context, orderTx)
751
+
752
+ for (let value = 0; value < sufficient.length; value++) {
753
+ if (sufficient[value].status == 'partial-release') {
754
+ let newOrderProduct = sufficient.map(item => {
755
+ return {
756
+ ...item,
757
+ name: OrderNoGenerator.orderProduct(),
758
+ draftReleaseGood: draftOrder,
759
+ releaseQty: item.newReleaseQty,
760
+ bizplace: draftOrder.bizplace,
761
+ domain: draftOrder.domain,
762
+ creator: user,
763
+ updater: user,
764
+ productDetail: item.productDetail,
765
+ status: ORDER_STATUS.DRAFT
766
+ }
767
+ })
768
+
769
+ delete newOrderProduct[value].id
770
+ delete newOrderProduct[value].releaseUomValue
771
+
772
+ let generatedOrderProduct = await orderTx
773
+ .getRepository(OrderProduct)
774
+ .save(newOrderProduct[value])
751
775
 
752
- createdReleaseGood = await confirmReleaseGood(createdReleaseGood.name, context, tx)
753
-
754
- if (settingValue > 1) {
755
- createdReleaseGood = await receiveReleaseGood(createdReleaseGood.name, context, tx)
756
-
757
- for (let value = 0; value < sufficient.length; value++) {
758
- if (sufficient[value].status == 'partial-release') {
759
- let newOrderProduct = sufficient.map(item => {
760
- return {
761
- ...item,
762
- name: OrderNoGenerator.orderProduct(),
763
- draftReleaseGood: draftOrder,
764
- releaseQty: item.newReleaseQty,
765
- bizplace: draftOrder.bizplace,
766
- domain: draftOrder.domain,
767
- creator: user,
768
- updater: user,
769
- productDetail: item.productDetail,
770
- status: ORDER_STATUS.DRAFT
771
- }
772
- })
773
-
774
- delete newOrderProduct[value].id
775
- delete newOrderProduct[value].releaseUomValue
776
-
777
- let generatedOrderProduct = await tx.getRepository(OrderProduct).save(newOrderProduct[value])
778
-
779
- console.log(generatedOrderProduct)
780
- }
781
776
  }
782
777
  }
783
- })
778
+ }
784
779
  }
785
780
  } catch (e) {
786
781
  logger.error(`draft-release-good-mutation[generateReleaseGoodsFromDraft:${loggerJson}]: ${e?.message}`)