Search in sources :

Example 11 with StockEventLineItemDto

use of org.openlmis.stockmanagement.dto.StockEventLineItemDto in project openlmis-stockmanagement by OpenLMIS.

the class AdjustmentReasonValidator method validate.

@Override
public void validate(StockEventDto stockEventDto) {
    LOGGER.debug("Validate adjustment reason");
    boolean hasSourceOrDestination = stockEventDto.hasSource() || stockEventDto.hasDestination();
    if (hasSourceOrDestination || !stockEventDto.hasLineItems()) {
        return;
    }
    for (StockEventLineItemDto lineItem : stockEventDto.getLineItems()) {
        if (lineItem.hasReasonId()) {
            validateReason(stockEventDto, lineItem);
        }
    }
}
Also used : StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto)

Example 12 with StockEventLineItemDto

use of org.openlmis.stockmanagement.dto.StockEventLineItemDto in project openlmis-stockmanagement by OpenLMIS.

the class QuantityValidator method calculateStockOnHand.

private void calculateStockOnHand(StockEventDto eventDto, List<StockEventLineItemDto> group, StockCard foundCard) {
    for (StockEventLineItemDto lineItem : group) {
        StockCardLineItem stockCardLineItem = StockCardLineItem.createLineItemFrom(eventDto, lineItem, foundCard, null);
        stockCardLineItem.setReason(eventDto.getContext().findEventReason(lineItem.getReasonId()));
    }
    foundCard.calculateStockOnHand();
}
Also used : StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto) StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem)

Example 13 with StockEventLineItemDto

use of org.openlmis.stockmanagement.dto.StockEventLineItemDto in project openlmis-stockmanagement by OpenLMIS.

the class QuantityValidatorTest method shouldNotRejectWhenEventReasonIdIsNotFound.

@Test
public void shouldNotRejectWhenEventReasonIdIsNotFound() throws Exception {
    // given
    StockEventDto event = createStockEventDto();
    StockEventLineItemDto invalidItem = event.getLineItems().get(0);
    invalidItem.setDestinationId(null);
    setContext(event);
    // when
    quantityValidator.validate(event);
}
Also used : StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) Test(org.junit.Test)

Example 14 with StockEventLineItemDto

use of org.openlmis.stockmanagement.dto.StockEventLineItemDto in project openlmis-stockmanagement by OpenLMIS.

the class QuantityValidatorTest method shouldNotRejectWhenEventLineItemHasNoReason.

@Test
public void shouldNotRejectWhenEventLineItemHasNoReason() throws Exception {
    // given
    StockEventDto event = createStockEventDto();
    setContext(event);
    StockEventLineItemDto invalidItem = event.getLineItems().get(0);
    invalidItem.setDestinationId(randomUUID());
    invalidItem.setReasonId(null);
    // when
    quantityValidator.validate(event);
}
Also used : StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) Test(org.junit.Test)

Example 15 with StockEventLineItemDto

use of org.openlmis.stockmanagement.dto.StockEventLineItemDto in project openlmis-stockmanagement by OpenLMIS.

the class StockEventDtoDataBuilder method createStockEventDto.

/**
 * Create stock event dto object for testing.
 *
 * @return created dto object.
 */
public static StockEventDto createStockEventDto() {
    StockEventDto stockEventDto = new StockEventDto();
    stockEventDto.setDocumentNumber("c");
    stockEventDto.setSignature("e");
    stockEventDto.setProgramId(UUID.randomUUID());
    stockEventDto.setFacilityId(UUID.randomUUID());
    StockEventLineItemDto eventLineItemDto = createStockEventLineItem();
    stockEventDto.setLineItems(singletonList(eventLineItemDto));
    return stockEventDto;
}
Also used : StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto)

Aggregations

StockEventLineItemDto (org.openlmis.stockmanagement.dto.StockEventLineItemDto)16 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)8 UUID (java.util.UUID)5 Test (org.junit.Test)4 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)3 StockEventDtoDataBuilder.createStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto)3 UUID.randomUUID (java.util.UUID.randomUUID)2 StockCardLineItem (org.openlmis.stockmanagement.domain.card.StockCardLineItem)2 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)2 Lists (com.google.common.collect.Lists)1 ZonedDateTime (java.time.ZonedDateTime)1 Collection (java.util.Collection)1 Collections.singletonList (java.util.Collections.singletonList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 NotNull (javax.validation.constraints.NotNull)1 CollectionUtils.isEmpty (org.apache.commons.collections4.CollectionUtils.isEmpty)1 StockCard.createStockCardFrom (org.openlmis.stockmanagement.domain.card.StockCard.createStockCardFrom)1 StockCardLineItem.createLineItemFrom (org.openlmis.stockmanagement.domain.card.StockCardLineItem.createLineItemFrom)1