From 1c76bc7e104d6cd4c7551897649802ad049123fe Mon Sep 17 00:00:00 2001 From: ArnaudFofou Date: Thu, 24 Oct 2024 10:36:57 +0100 Subject: [PATCH] update getLot method and update error message in validateMovement --- .../manager/MovStockInsertingManager.java | 5 ++-- .../service/MedicalStockIoOperations.java | 23 ++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java b/src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java index b2581bcc7..ae89b251d 100644 --- a/src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java +++ b/src/main/java/org/isf/medicalstock/manager/MovStockInsertingManager.java @@ -133,7 +133,8 @@ protected void validateMovement(Movement movement, boolean checkReference) throw */ Lot lot = movement.getLot(); if (lot != null) { - + String code = lot.getCode(); + lot = this.getLot(code); if (isCharge && !isAutomaticLotIn() || !isCharge && !isAutomaticLotOut()) { // check everything validateLot(errors, lot, true); @@ -181,7 +182,7 @@ protected void validateMovement(Movement movement, boolean checkReference) throw if (!isAutomaticLotOut()) { if (movement.getType() != null && !isCharge && movement.getQuantity() > lot.getMainStoreQuantity()) { - errors.add(new OHExceptionMessage(MessageBundle.getMessage("angal.medicalstock.movementquantityisgreaterthanthequantityof.msg"))); + errors.add(new OHExceptionMessage(MessageBundle.formatMessage("angal.medicalstock.movementquantityisgreaterthanthequantityof.fmt.msg", movement.getQuantity(), lot.getMainStoreQuantity()))); } } diff --git a/src/main/java/org/isf/medicalstock/service/MedicalStockIoOperations.java b/src/main/java/org/isf/medicalstock/service/MedicalStockIoOperations.java index 0b8e5fa0a..bb5c6ec16 100644 --- a/src/main/java/org/isf/medicalstock/service/MedicalStockIoOperations.java +++ b/src/main/java/org/isf/medicalstock/service/MedicalStockIoOperations.java @@ -292,7 +292,28 @@ public boolean lotExists(String lotCode) throws OHServiceException { * @throws OHServiceException if an error occurs during the check. */ public Lot getLot(String lotCode) throws OHServiceException { - return lotRepository.findById(String.valueOf(lotCode)).orElse(null); + Lot lot = lotRepository.findById(String.valueOf(lotCode)).orElse(null); + if (lot == null) { + return null; + } + List lotCodes = new ArrayList<>(); + lotCodes.add(lotCode); + // Retrieve quantities in batch + List mainStoreQuantities = lotRepository.getMainStoreQuantities(lotCodes); + List wardsTotalQuantities = lotRepository.getWardsTotalQuantities(lotCodes); + + // Process mainStoreQuantities and update lots + for (Object[] result : mainStoreQuantities) { + int mainStoreQuantity = ((Long) result[1]).intValue(); + lot.setMainStoreQuantity(mainStoreQuantity); + } + + // Process wardsTotalQuantities and update lots + for (Object[] result : wardsTotalQuantities) { + Double wardsTotalQuantity = (Double) result[1]; + lot.setWardsTotalQuantity(wardsTotalQuantity); + } + return lot; } /**