Search in sources :

Example 6 with StockEventLineItemDto

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

the class StockEventDtoDataBuilder method createStockEventDtoWithTwoLineItems.

/**
 * Create stock event dto object for testing with two line items.
 *
 * @return created dto object.
 */
public static StockEventDto createStockEventDtoWithTwoLineItems() {
    StockEventDto stockEventDto = new StockEventDto();
    stockEventDto.setProgramId(UUID.randomUUID());
    stockEventDto.setFacilityId(UUID.randomUUID());
    UUID orderable = UUID.randomUUID();
    UUID lot = UUID.randomUUID();
    StockEventLineItemDto lineItem1 = new StockEventLineItemDto();
    lineItem1.setOrderableId(orderable);
    lineItem1.setLotId(lot);
    lineItem1.setQuantity(20);
    lineItem1.setOccurredDate(getBaseDate());
    lineItem1.setReasonId(UUID.fromString("279d55bd-42e3-438c-a63d-9c021b185dae"));
    StockEventLineItemDto lineItem2 = new StockEventLineItemDto();
    lineItem2.setOrderableId(orderable);
    lineItem2.setLotId(lot);
    lineItem2.setQuantity(10);
    lineItem2.setOccurredDate(getBaseDate());
    lineItem2.setReasonId(UUID.fromString("b7e99f5b-af04-433d-9c30-d4f90c60c47b"));
    stockEventDto.setLineItems(Arrays.asList(lineItem1, lineItem2));
    return stockEventDto;
}
Also used : StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) UUID(java.util.UUID)

Example 7 with StockEventLineItemDto

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

the class StockEventDtoDataBuilder method createStockEventLineItem.

/**
 * Create stock event line item dto object for testing.
 *
 * @return created dto object.
 */
public static StockEventLineItemDto createStockEventLineItem() {
    StockEventLineItemDto eventLineItemDto = new StockEventLineItemDto();
    eventLineItemDto.setReasonFreeText("d");
    eventLineItemDto.setReasonId(UUID.fromString("e3fc3cf3-da18-44b0-a220-77c985202e06"));
    eventLineItemDto.setQuantity(1);
    eventLineItemDto.setOrderableId(UUID.randomUUID());
    eventLineItemDto.setOccurredDate(LocalDate.now());
    eventLineItemDto.setSourceId(UUID.fromString("0bd28568-43f1-4836-934d-ec5fb11398e8"));
    eventLineItemDto.setDestinationId(UUID.fromString("087e81f6-a74d-4bba-9d01-16e0d64e9609"));
    eventLineItemDto.setSourceFreeText("a");
    eventLineItemDto.setDestinationFreeText("b");
    return eventLineItemDto;
}
Also used : StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto)

Example 8 with StockEventLineItemDto

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

the class StockEventsControllerIntegrationTest method generateStockEventLineItem.

private StockEventLineItemDto generateStockEventLineItem() {
    StockEventLineItemDto item = new StockEventLineItemDto();
    item.setOrderableId(UUID.randomUUID());
    item.setLotId(UUID.randomUUID());
    item.setSourceId(UUID.randomUUID());
    item.setSourceFreeText("source");
    item.setDestinationId(UUID.randomUUID());
    item.setDestinationFreeText("destination");
    item.setQuantity(10);
    item.setReasonId(UUID.randomUUID());
    item.setReasonFreeText("reason");
    item.setOccurredDate(LocalDate.now());
    item.setExtraData(new HashMap<>());
    item.setStockAdjustments(new ArrayList<>());
    return item;
}
Also used : StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto)

Example 9 with StockEventLineItemDto

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

the class StockCardService method saveFromEvent.

/**
 * Generate stock card line items and stock cards based on event, and persist them.
 *
 * @param stockEventDto the origin event.
 * @param savedEventId  saved event id.
 */
void saveFromEvent(StockEventDto stockEventDto, UUID savedEventId) {
    List<StockCard> cardsToUpdate = Lists.newArrayList();
    for (StockEventLineItemDto eventLineItem : stockEventDto.getLineItems()) {
        StockCard stockCard = findOrCreateCard(stockEventDto, eventLineItem, savedEventId, cardsToUpdate);
        createLineItemFrom(stockEventDto, eventLineItem, stockCard, savedEventId);
    }
    cardRepository.save(cardsToUpdate);
    stockEventDto.getContext().refreshCards();
    LOGGER.debug("Stock cards and line items saved");
}
Also used : StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto) StockCard(org.openlmis.stockmanagement.domain.card.StockCard)

Example 10 with StockEventLineItemDto

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

the class StockCardLineItemTest method shouldCreateLineItemFromStockEvent.

@Test
public void shouldCreateLineItemFromStockEvent() throws Exception {
    // given
    StockCard stockCard = new StockCard();
    stockCard.setLineItems(new ArrayList<>());
    // when
    UUID userId = randomUUID();
    StockEventProcessContext context = new StockEventProcessContext();
    context.setCurrentUserId(new LazyResource<>(() -> userId));
    StockEventDto eventDto = createStockEventDto();
    eventDto.setContext(context);
    StockEventLineItemDto eventLineItem = eventDto.getLineItems().get(0);
    eventLineItem.setStockAdjustments(singletonList(createStockAdjustment()));
    UUID eventId = randomUUID();
    StockCardLineItem cardLineItem = createLineItemFrom(eventDto, eventLineItem, stockCard, eventId);
    // then
    assertThat(cardLineItem.getSourceFreeText(), is(eventLineItem.getSourceFreeText()));
    assertThat(cardLineItem.getDestinationFreeText(), is(eventLineItem.getDestinationFreeText()));
    assertThat(cardLineItem.getReasonFreeText(), is(eventLineItem.getReasonFreeText()));
    assertThat(cardLineItem.getDocumentNumber(), is(eventDto.getDocumentNumber()));
    assertThat(cardLineItem.getSignature(), is(eventDto.getSignature()));
    assertThat(cardLineItem.getQuantity(), is(eventLineItem.getQuantity()));
    assertThat(cardLineItem.getReason().getId(), is(eventLineItem.getReasonId()));
    assertThat(cardLineItem.getSource().getId(), is(eventLineItem.getSourceId()));
    assertThat(cardLineItem.getDestination().getId(), is(eventLineItem.getDestinationId()));
    assertThat(cardLineItem.getOccurredDate(), is(eventLineItem.getOccurredDate()));
    assertThat(cardLineItem.getStockCard(), is(stockCard));
    assertThat(cardLineItem.getOriginEvent().getId(), is(eventId));
    assertThat(cardLineItem.getUserId(), is(userId));
    assertEquals(cardLineItem.getStockAdjustments(), eventLineItem.stockAdjustments());
    ZonedDateTime processedDate = cardLineItem.getProcessedDate();
    long between = SECONDS.between(processedDate, ZonedDateTime.now());
    assertThat(between, lessThan(2L));
}
Also used : StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto) ZonedDateTime(java.time.ZonedDateTime) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) StockEventProcessContext(org.openlmis.stockmanagement.util.StockEventProcessContext) Test(org.junit.Test)

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