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);
}
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);
}
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));
}
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;
}
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");
}
Aggregations