Skip to content

Commit

Permalink
OP-1340 Add method for multiple lots update (#1434)
Browse files Browse the repository at this point in the history
* Add method for multiple lots update

* Apply code review suggestions

* Add test

* Apply Junit 5 standard

* Disable tests to be fixed in another PR
  • Loading branch information
mwithi authored Oct 15, 2024
1 parent d1cd74e commit f3007ce
Show file tree
Hide file tree
Showing 2 changed files with 252 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.isf.generaldata.GeneralData;
import org.isf.generaldata.MessageBundle;
import org.isf.medicalinventory.model.MedicalInventoryRow;
import org.isf.medicals.model.Medical;
import org.isf.medicals.service.MedicalsIoOperations;
import org.isf.medicalstock.model.Lot;
Expand Down Expand Up @@ -152,7 +150,7 @@ protected void validateMovement(Movement movement, boolean checkReference) throw
*/
List<Integer> medicalIds = ioOperations.getMedicalsFromLot(lot.getCode());
if (movement.getMedical() != null && !(medicalIds.isEmpty() || medicalIds.size() == 1 && medicalIds.get(0).intValue() == movement
.getMedical().getCode().intValue())) {
.getMedical().getCode().intValue())) {
errors.add(new OHExceptionMessage(MessageBundle.getMessage("angal.medicalstock.thislotreferstoanothermedical.msg")));
}

Expand Down Expand Up @@ -237,7 +235,7 @@ private boolean isAutomaticLotIn() {
private boolean isAutomaticLotOut() {
return GeneralData.AUTOMATICLOT_OUT;
}

/**
* Retrieves all the {@link Lot} associated to the specified {@link Medical}, expiring first on top, zero quantities will be stripped out.
*
Expand All @@ -250,7 +248,8 @@ public List<Lot> getLotByMedical(Medical medical) throws OHServiceException {
}

/**
* Retrieves all the {@link Lot} associated to the specified {@link Medical}, expiring first on top, zero quantities will be stripped out if {@code removeEmtpy} is set to true.
* Retrieves all the {@link Lot} associated to the specified {@link Medical}, expiring first on top, zero quantities will be stripped out if
* {@code removeEmtpy} is set to true.
*
* @param medical the medical.
* @param removeEmpty
Expand Down Expand Up @@ -303,8 +302,7 @@ public boolean refNoExists(String refNo) throws OHServiceException {
* Insert a list of charging {@link Movement}s and related {@link Lot}s
*
* @param movements - the list of {@link Movement}s
* @param referenceNumber - the reference number to be set for all movements
* if {@link null}, each movements must have a different referenceNumber
* @param referenceNumber - the reference number to be set for all movements if {@link null}, each movements must have a different referenceNumber
* @return a list of inserted {@link Movement}s.
* @throws OHServiceException
*/
Expand All @@ -328,8 +326,8 @@ public List<Movement> newMultipleChargingMovements(List<Movement> movements, Str
} catch (OHServiceException e) {
List<OHExceptionMessage> errors = e.getMessages();
errors.add(new OHExceptionMessage(
mov.getMedical() != null ? mov.getMedical().getDescription()
: MessageBundle.getMessage("angal.medicalstock.nodescription.txt")));
mov.getMedical() != null ? mov.getMedical().getDescription()
: MessageBundle.getMessage("angal.medicalstock.nodescription.txt")));
throw new OHDataValidationException(errors);
}
}
Expand All @@ -352,16 +350,35 @@ protected Movement prepareChargingMovement(Movement movement, boolean checkRefer

/**
* Retrieves the {@link Lot}.
*
* @param lotCode - the lot code.
* @return the retrieved {@link Lot}.
* @throws OHServiceException if an error occurs during the check.
*/
public Lot getLot(String lotCode) throws OHServiceException {
return ioOperations.getLot(lotCode);
}


/**
* Update the list of {@link Lot}s.
*
* @param lots - the list of lots.
* @return the list of {@link Lot}s updated.
* @throws OHServiceException if an error occurs during the check.
*/
@Transactional
public List<Lot> updateLot(List<Lot> lots) throws OHServiceException {
List<Lot> updatedLots = new ArrayList<>();
for (Lot lot : lots) {
Lot updatedLot = updateLot(lot);
updatedLots.add(updatedLot);
}
return updatedLots;
}

/**
* Update the {@link Lot}.
*
* @param lot - the lot.
* @return the {@link Lot} updated.
* @throws OHServiceException if an error occurs during the check.
Expand All @@ -374,8 +391,7 @@ public Lot updateLot(Lot lot) throws OHServiceException {
* Insert a list of discharging {@link Movement}s
*
* @param movements - the list of {@link Movement}s
* @param referenceNumber - the reference number to be set for all movements
* if {@link null}, each movements must have a different referenceNumber
* @param referenceNumber - the reference number to be set for all movements if {@link null}, each movements must have a different referenceNumber
* @return a list of {@Link Movement}s.
* @throws OHServiceException
*/
Expand All @@ -402,9 +418,10 @@ public List<Movement> newMultipleDischargingMovements(List<Movement> movements,
}
return dischargingMovements;
}

/**
* Stores the specified {@link Lot}.
*
* @param lotCode the {@link Lot} code.
* @param lot the lot to store.
* @param medical
Expand Down
Loading

0 comments on commit f3007ce

Please sign in to comment.