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