Search in sources :

Example 11 with StockEvent

use of org.openlmis.stockmanagement.domain.event.StockEvent in project openlmis-stockmanagement by OpenLMIS.

the class StockEventDataBuilder method build.

/**
 * Creates stock event based on parameters from the builder.
 */
public StockEvent build() {
    StockEvent event = new StockEvent(facilityId, programId, userId, processedDate, signature, documentNumber, lineItems);
    event.setId(id);
    return event;
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent)

Example 12 with StockEvent

use of org.openlmis.stockmanagement.domain.event.StockEvent in project openlmis-stockmanagement by OpenLMIS.

the class StockCardSummariesV2DtoBuilderTest method before.

@Before
public void before() {
    ReflectionTestUtils.setField(builder, "serviceUrl", "https://openlmis/");
    orderable1 = new OrderableDtoDataBuilder().build();
    orderable2 = new OrderableDtoDataBuilder().build();
    orderable3 = new OrderableDtoDataBuilder().build();
    StockEvent event = new StockEventDataBuilder().withFacility(facilityId).withProgram(programId).build();
    stockCard = new StockCardDataBuilder(event).buildWithStockOnHandAndLineItemAndOrderableId(12, new StockCardLineItemDataBuilder().buildWithStockOnHand(16), orderable1.getId());
    stockCard1 = new StockCardDataBuilder(event).buildWithStockOnHandAndLineItemAndOrderableId(26, new StockCardLineItemDataBuilder().buildWithStockOnHand(30), orderable3.getId());
    stockCard2 = new StockCardDataBuilder(event).withLot(UUID.randomUUID()).buildWithStockOnHandAndLineItemAndOrderableId(22, new StockCardLineItemDataBuilder().buildWithStockOnHand(10), orderable3.getId());
    fulfillMap = new HashMap<>();
    fulfillMap.put(orderable1.getId(), new OrderableFulfillDtoDataBuilder().withCanFulfillForMe(asList(orderable2.getId(), orderable3.getId())).build());
    fulfillMap.put(orderable2.getId(), new OrderableFulfillDtoDataBuilder().withCanFulfillForMe(Collections.singletonList(orderable1.getId())).build());
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) OrderableDtoDataBuilder(org.openlmis.stockmanagement.testutils.OrderableDtoDataBuilder) StockCardDataBuilder(org.openlmis.stockmanagement.testutils.StockCardDataBuilder) StockEventDataBuilder(org.openlmis.stockmanagement.testutils.StockEventDataBuilder) OrderableFulfillDtoDataBuilder(org.openlmis.stockmanagement.testutils.OrderableFulfillDtoDataBuilder) StockCardLineItemDataBuilder(org.openlmis.stockmanagement.testutils.StockCardLineItemDataBuilder) Before(org.junit.Before)

Example 13 with StockEvent

use of org.openlmis.stockmanagement.domain.event.StockEvent in project openlmis-stockmanagement by OpenLMIS.

the class StockEventDto method toEvent.

/**
 * Convert dto to jpa model.
 *
 * @return the converted jpa model object.
 */
public StockEvent toEvent() {
    List<StockEventLineItem> domainLines = this.lineItems.stream().map(StockEventLineItemDto::toEventLineItem).collect(Collectors.toList());
    StockEvent event = new StockEvent(facilityId, programId, context.getCurrentUserId(), // processed date generated by server side
    now(), signature, documentNumber, domainLines);
    domainLines.forEach(lineItem -> {
        lineItem.setStockAdjustments(lineItem.stockAdjustments());
        lineItem.setStockEvent(event);
    });
    return event;
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) StockEventLineItem(org.openlmis.stockmanagement.domain.event.StockEventLineItem)

Example 14 with StockEvent

use of org.openlmis.stockmanagement.domain.event.StockEvent in project openlmis-stockmanagement by OpenLMIS.

the class StockCardServiceIntegrationTest method shouldSaveLineItemsWithProgramFacilityOrderableForNonFirstMovement.

@Test
public void shouldSaveLineItemsWithProgramFacilityOrderableForNonFirstMovement() throws Exception {
    // given
    // 1. there is an existing event that caused a stock card to exist
    StockEventDto existingEventDto = createStockEventDto();
    final StockEvent existingEvent = save(existingEventDto, randomUUID());
    UUID orderableId = existingEventDto.getLineItems().get(0).getOrderableId();
    // 2. and there is a new event coming
    StockEventDto newEventDto = createStockEventDto();
    newEventDto.setProgramId(existingEventDto.getProgramId());
    newEventDto.setFacilityId(existingEventDto.getFacilityId());
    newEventDto.getLineItems().get(0).setOrderableId(orderableId);
    // when
    long cardAmountBeforeSave = stockCardRepository.count();
    UUID userId = randomUUID();
    StockEvent savedNewEvent = save(newEventDto, userId);
    long cardAmountAfterSave = stockCardRepository.count();
    // then
    StockCard savedCard = stockCardRepository.findByOriginEvent(existingEvent);
    List<StockCardLineItem> lineItems = savedCard.getLineItems();
    lineItems.sort(Comparator.comparing(StockCardLineItem::getProcessedDate));
    StockCardLineItem latestLineItem = lineItems.get(lineItems.size() - 1);
    assertThat(cardAmountAfterSave, is(cardAmountBeforeSave));
    assertThat(latestLineItem.getOriginEvent().getId(), is(savedNewEvent.getId()));
    assertThat(latestLineItem.getStockCard().getId(), is(savedCard.getId()));
    assertThat(latestLineItem.getUserId(), is(userId));
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) BaseIntegrationTest(org.openlmis.stockmanagement.BaseIntegrationTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 15 with StockEvent

use of org.openlmis.stockmanagement.domain.event.StockEvent in project openlmis-stockmanagement by OpenLMIS.

the class StockCardServiceIntegrationTest method shouldSaveStockCardLineItemsAndCreateStockCardForFirstMovement.

@Test
public void shouldSaveStockCardLineItemsAndCreateStockCardForFirstMovement() throws Exception {
    // given
    UUID userId = randomUUID();
    StockEventDto stockEventDto = createStockEventDto();
    StockEvent savedEvent = save(stockEventDto, userId);
    // when
    stockCardService.saveFromEvent(stockEventDto, savedEvent.getId());
    // then
    StockCard savedCard = stockCardRepository.findByOriginEvent(savedEvent);
    StockCardLineItem firstLineItem = savedCard.getLineItems().get(0);
    assertThat(firstLineItem.getUserId(), is(userId));
    assertThat(firstLineItem.getSource().isRefDataFacility(), is(true));
    assertThat(firstLineItem.getDestination().isRefDataFacility(), is(false));
    assertThat(firstLineItem.getStockCard().getOriginEvent().getId(), is(savedEvent.getId()));
    assertThat(firstLineItem.getStockCard().getFacilityId(), is(savedEvent.getFacilityId()));
    assertThat(firstLineItem.getStockCard().getProgramId(), is(savedEvent.getProgramId()));
    UUID orderableId = savedEvent.getLineItems().get(0).getOrderableId();
    assertThat(firstLineItem.getStockCard().getOrderableId(), is(orderableId));
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) BaseIntegrationTest(org.openlmis.stockmanagement.BaseIntegrationTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)18 UUID (java.util.UUID)10 Test (org.junit.Test)8 UUID.randomUUID (java.util.UUID.randomUUID)7 BaseIntegrationTest (org.openlmis.stockmanagement.BaseIntegrationTest)6 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)5 StockEventDtoDataBuilder.createStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto)5 StockCardDataBuilder (org.openlmis.stockmanagement.testutils.StockCardDataBuilder)4 StockEventDataBuilder (org.openlmis.stockmanagement.testutils.StockEventDataBuilder)4 StockCardLineItem (org.openlmis.stockmanagement.domain.card.StockCardLineItem)3 StockCardDto (org.openlmis.stockmanagement.dto.StockCardDto)3 Before (org.junit.Before)2 PhysicalInventoryDto (org.openlmis.stockmanagement.dto.PhysicalInventoryDto)2 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)2 StockCardLineItemDataBuilder (org.openlmis.stockmanagement.testutils.StockCardLineItemDataBuilder)2 Message (org.openlmis.stockmanagement.util.Message)2 ZonedDateTime (java.time.ZonedDateTime)1 Collections (java.util.Collections)1