From c39d5c08058d50e724265bb878ae6ea4900fc6ef Mon Sep 17 00:00:00 2001 From: Usama Khan Date: Thu, 6 Mar 2025 22:19:14 -0800 Subject: [PATCH] fixed null pointer Exception --- .../com/utopiaindustries/service/InventoryService.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/utopiaindustries/service/InventoryService.java b/src/main/java/com/utopiaindustries/service/InventoryService.java index 40ea767..fd79832 100644 --- a/src/main/java/com/utopiaindustries/service/InventoryService.java +++ b/src/main/java/com/utopiaindustries/service/InventoryService.java @@ -346,12 +346,13 @@ public class InventoryService { .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity())); for (Bundle subBundle : wrapper.getBundles()) { long accountId = masterBundleDAO.find(subBundle.getMasterBundleId()).getAccountId(); - if(subBundle.getCurrentProduction().compareTo(BigDecimal.ZERO) != 0){ + if(subBundle.getCurrentProduction() != null && subBundle.getCurrentProduction().compareTo(BigDecimal.ZERO) != 0){ Bundle bundle = bundleDAO.find(subBundle.getId()); jobCard = jobCardDAO.find(subBundle.getJobCardId()); long production = (bundle.getProduction() == null) ? 0 : bundle.getProduction().longValue() ; long wrapQuantity = bundle.getWrapQuantity().longValue(); JobCardItem jobCardItem = jobCardItemDAO.findByCardIdAndItemId(subBundle.getJobCardId(),subBundle.getItemId()); + BigDecimal previousTotalProduction = jobCardItem.getTotalProduction() == null ? BigDecimal.ZERO : jobCardItem.getTotalProduction(); InventoryTransactionLeg lastInvTransaction = lastBundleIdInTransactionMap.getOrDefault(subBundle.getId(), null); @@ -367,10 +368,10 @@ public class InventoryService { // create IN Transactions of Finished Items into account createTransactions(stitchingOfflineItems, accountId, InventoryArtifactType.STITCHING_OFFLINE.name()); - jobCardItem.setTotalProduction(jobCardItem.getTotalProduction().add(subBundle.getCurrentProduction())); + jobCardItem.setTotalProduction(previousTotalProduction.add(subBundle.getCurrentProduction())); jobCardItem.setJobCardId(jobCard.getId()); updatedItems.add(jobCardItem); - BigDecimal pro = subBundle.getCurrentProduction(); + BigDecimal pro = BigDecimal.valueOf(production + subBundle.getCurrentProduction().longValue()); bundle.setProduction(pro); bundleDAO.save(bundle); }