Search in sources :

Example 16 with StockCard

use of org.openlmis.stockmanagement.domain.card.StockCard in project openlmis-stockmanagement by OpenLMIS.

the class QuantityValidatorTest method shouldNotRejectWhenStockOnHandFromMiddleIsLessThanStockAdjustment.

@Test
public void shouldNotRejectWhenStockOnHandFromMiddleIsLessThanStockAdjustment() {
    // given
    StockCard card = new StockCardDataBuilder(new StockEventDataBuilder().build()).withLineItem(buildPhysicalInventoryLineItem(100, Month.JANUARY)).withLineItem(buildPhysicalInventoryLineItem(80, Month.MARCH)).build();
    StockEventDto event = createPhysicalInventoryEventDto(LocalDate.of(2017, Month.FEBRUARY, 28), 15, null);
    mockCardFound(event, card);
    // when
    quantityValidator.validate(event);
}
Also used : StockCardDataBuilder(org.openlmis.stockmanagement.testutils.StockCardDataBuilder) StockEventDataBuilder(org.openlmis.stockmanagement.testutils.StockEventDataBuilder) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) Test(org.junit.Test)

Example 17 with StockCard

use of org.openlmis.stockmanagement.domain.card.StockCard in project openlmis-stockmanagement by OpenLMIS.

the class StockCardSummariesV2DtoBuilderTest method shouldSortStockCardSummaries.

@Test
public void shouldSortStockCardSummaries() throws Exception {
    List<StockCard> stockCards = asList(stockCard, stockCard1, stockCard2);
    fulfillMap.remove(orderable1.getId());
    LocalDate asOfDate = LocalDate.now();
    List<StockCardSummaryV2Dto> result = builder.build(asList(orderable2, orderable3), stockCards, fulfillMap, asOfDate);
    StockCardSummaryV2Dto summary2 = new StockCardSummaryV2Dto(new ObjectReferenceDtoDataBuilder().withPath(ORDERABLES).withId(orderable2.getId()).build(), asSet(new CanFulfillForMeEntryDtoDataBuilder().buildWithStockCardAndOrderable(stockCard, orderable1, asOfDate)));
    StockCardSummaryV2Dto summary3 = new StockCardSummaryV2Dto(new ObjectReferenceDtoDataBuilder().withPath(ORDERABLES).withId(orderable3.getId()).build(), asSet(new CanFulfillForMeEntryDtoDataBuilder().buildWithStockCardAndOrderable(stockCard1, orderable3, asOfDate), new CanFulfillForMeEntryDtoDataBuilder().buildWithStockCardAndOrderable(stockCard2, orderable3, asOfDate)));
    assertEquals(2, result.size());
    assertEquals(result.get(0), summary3);
    assertEquals(result.get(1), summary2);
}
Also used : CanFulfillForMeEntryDtoDataBuilder(org.openlmis.stockmanagement.testutils.CanFulfillForMeEntryDtoDataBuilder) ObjectReferenceDtoDataBuilder(org.openlmis.stockmanagement.testutils.ObjectReferenceDtoDataBuilder) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 18 with StockCard

use of org.openlmis.stockmanagement.domain.card.StockCard in project openlmis-stockmanagement by OpenLMIS.

the class StockCardSummariesV2DtoBuilderTest method shouldBuildStockCardSummariesWithDateBeforeThereWereCards.

@Test
public void shouldBuildStockCardSummariesWithDateBeforeThereWereCards() throws Exception {
    List<StockCard> stockCards = asList(stockCard, stockCard1);
    LocalDate asOfDate = getBaseDate().minusDays(10);
    List<StockCardSummaryV2Dto> result = builder.build(Collections.singletonList(orderable1), stockCards, fulfillMap, asOfDate);
    StockCardSummaryV2Dto summary1 = new StockCardSummaryV2Dto(new ObjectReferenceDtoDataBuilder().withPath(ORDERABLES).withId(orderable1.getId()).build(), asSet(new CanFulfillForMeEntryDtoDataBuilder().buildWithStockCardAndOrderable(stockCard1, orderable3, asOfDate), new CanFulfillForMeEntryDtoDataBuilder().buildWithStockCardAndOrderable(stockCard, orderable1, asOfDate)));
    assertEquals(1, result.size());
    assertThat(result, hasItems(summary1));
}
Also used : CanFulfillForMeEntryDtoDataBuilder(org.openlmis.stockmanagement.testutils.CanFulfillForMeEntryDtoDataBuilder) ObjectReferenceDtoDataBuilder(org.openlmis.stockmanagement.testutils.ObjectReferenceDtoDataBuilder) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 19 with StockCard

use of org.openlmis.stockmanagement.domain.card.StockCard in project openlmis-stockmanagement by OpenLMIS.

the class StockCardDataBuilder method build.

/**
 * Creates stock card based on parameters from the builder.
 */
public StockCard build() {
    StockCard card = new StockCard(originalEvent, originalEvent.getFacilityId(), originalEvent.getProgramId(), orderableId, lotId, lineItems, stockOnHand);
    card.setId(id);
    return card;
}
Also used : StockCard(org.openlmis.stockmanagement.domain.card.StockCard)

Example 20 with StockCard

use of org.openlmis.stockmanagement.domain.card.StockCard 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)

Aggregations

StockCard (org.openlmis.stockmanagement.domain.card.StockCard)35 Test (org.junit.Test)20 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)12 UUID (java.util.UUID)11 StockCardLineItem (org.openlmis.stockmanagement.domain.card.StockCardLineItem)11 LocalDate (java.time.LocalDate)10 StockEventDtoDataBuilder.createStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto)9 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)6 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)6 StockCardDto (org.openlmis.stockmanagement.dto.StockCardDto)6 List (java.util.List)5 FacilityDto (org.openlmis.stockmanagement.dto.referencedata.FacilityDto)5 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)5 UUID.randomUUID (java.util.UUID.randomUUID)4 StockEventLineItemDto (org.openlmis.stockmanagement.dto.StockEventLineItemDto)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Node (org.openlmis.stockmanagement.domain.sourcedestination.Node)3 LotDto (org.openlmis.stockmanagement.dto.referencedata.LotDto)3 ProgramDto (org.openlmis.stockmanagement.dto.referencedata.ProgramDto)3