Skip to content

Commit

Permalink
update getLot method and update error message in validateMovement
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudFofou committed Oct 24, 2024
1 parent 5db7c84 commit 1c76bc7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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())));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> lotCodes = new ArrayList<>();
lotCodes.add(lotCode);
// Retrieve quantities in batch
List<Object[]> mainStoreQuantities = lotRepository.getMainStoreQuantities(lotCodes);
List<Object[]> 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;
}

/**
Expand Down

0 comments on commit 1c76bc7

Please sign in to comment.