| @@ -126,10 +126,7 @@ open class StockInLineService( | |||||
| // update po status to receiving | // update po status to receiving | ||||
| if (po != null) { | if (po != null) { | ||||
| po.apply { | |||||
| status = PurchaseOrderStatus.RECEIVING | |||||
| } | |||||
| val savedPo = poRepository.save(po) | |||||
| val savedPo = updatePurchaseOrderStatus(po) | |||||
| stockInLine.apply { | stockInLine.apply { | ||||
| this.purchaseOrder = savedPo | this.purchaseOrder = savedPo | ||||
| } | } | ||||
| @@ -323,19 +320,21 @@ open class StockInLineService( | |||||
| @Throws(IOException::class) | @Throws(IOException::class) | ||||
| @Transactional | @Transactional | ||||
| open fun updatePurchaseOrderStatus(po : PurchaseOrder) { | |||||
| val unfinishedPol = polRepository | |||||
| .findAllByPurchaseOrderIdAndStatusNotAndDeletedIsFalse(po.id!!, | |||||
| PurchaseOrderLineStatus.COMPLETED) | |||||
| // If all POL is completed | |||||
| if (unfinishedPol.isEmpty()) { | |||||
| po.apply { | |||||
| status = PurchaseOrderStatus.COMPLETED | |||||
| } | |||||
| poRepository.saveAndFlush(po) | |||||
| } else { | |||||
| open fun updatePurchaseOrderStatus(po : PurchaseOrder) : PurchaseOrder { | |||||
| val pols = polRepository.findAllByPurchaseOrderIdAndDeletedIsFalse(po.id!!) | |||||
| var newStatus = PurchaseOrderStatus.PENDING | |||||
| if (pols.isNotEmpty()) { | |||||
| newStatus = if (pols.any { pol-> pol.status != PurchaseOrderLineStatus.COMPLETED }) { | |||||
| PurchaseOrderStatus.RECEIVING | |||||
| } else { | |||||
| PurchaseOrderStatus.COMPLETED | |||||
| } | |||||
| } | |||||
| po.apply { | |||||
| status = newStatus | |||||
| } | } | ||||
| return poRepository.saveAndFlush(po) | |||||
| } | } | ||||
| @Throws(IOException::class) | @Throws(IOException::class) | ||||
| @Transactional | @Transactional | ||||