use of org.openlmis.stockmanagement.dto.StockCardLineItemDto in project openlmis-stockmanagement by OpenLMIS.
the class StockCardServiceIntegrationTest method shouldGetRefdataAndConvertOrganizationsWhenFindStockCard.
@Test
public void shouldGetRefdataAndConvertOrganizationsWhenFindStockCard() throws Exception {
// given
UUID userId = randomUUID();
StockEventDto stockEventDto = createStockEventDto();
stockEventDto.getLineItems().get(0).setLotId(randomUUID());
// 1. mock ref data service
FacilityDto cardFacility = new FacilityDto();
FacilityDto sourceFacility = new FacilityDto();
ProgramDto programDto = new ProgramDto();
OrderableDto orderableDto = new OrderableDto();
LotDto lotDto = new LotDto();
when(facilityReferenceDataService.findOne(stockEventDto.getFacilityId())).thenReturn(cardFacility);
when(facilityReferenceDataService.findOne(fromString("e6799d64-d10d-4011-b8c2-0e4d4a3f65ce"))).thenReturn(sourceFacility);
when(programReferenceDataService.findOne(stockEventDto.getProgramId())).thenReturn(programDto);
when(orderableReferenceDataService.findOne(stockEventDto.getLineItems().get(0).getOrderableId())).thenReturn(orderableDto);
when(lotReferenceDataService.findOne(stockEventDto.getLineItems().get(0).getLotId())).thenReturn(lotDto);
// 2. there is an existing stock card with line items
StockEvent savedEvent = save(stockEventDto, userId);
// when
StockCard savedCard = stockCardRepository.findByOriginEvent(savedEvent);
StockCardDto foundCardDto = stockCardService.findStockCardById(savedCard.getId());
// then
assertThat(foundCardDto.getFacility(), is(cardFacility));
assertThat(foundCardDto.getProgram(), is(programDto));
assertThat(foundCardDto.getOrderable(), is(orderableDto));
assertThat(foundCardDto.getLot(), is(lotDto));
StockCardLineItemDto lineItemDto = foundCardDto.getLineItems().get(0);
assertThat(lineItemDto.getSource(), is(sourceFacility));
assertThat(lineItemDto.getDestination().getName(), is("NGO"));
}
use of org.openlmis.stockmanagement.dto.StockCardLineItemDto in project openlmis-stockmanagement by OpenLMIS.
the class StockCardBaseService method cardToDto.
private StockCardDto cardToDto(FacilityDto facility, ProgramDto program, StockCard card) {
card.calculateStockOnHand();
StockCardDto cardDto = StockCardDto.createFrom(card);
cardDto.setFacility(facility);
cardDto.setProgram(program);
cardDto.setOrderable(OrderableDto.builder().id(card.getOrderableId()).build());
if (card.getLotId() != null) {
cardDto.setLot(LotDto.builder().id(card.getLotId()).build());
}
List<StockCardLineItemDto> lineItems = cardDto.getLineItems();
if (!isEmpty(lineItems)) {
cardDto.setLastUpdate(lineItems.get(lineItems.size() - 1).getLineItem().getOccurredDate());
cardDto.setExtraData(lineItems.get(lineItems.size() - 1).getLineItem().getExtraData());
}
return cardDto;
}
use of org.openlmis.stockmanagement.dto.StockCardLineItemDto in project openlmis-stockmanagement by OpenLMIS.
the class StockCardDtoDataBuilder method createStockCardDto.
/**
* Create stock card dto.
*
* @return stock card dto
*/
public static StockCardDto createStockCardDto() {
StockCardLineItemReason reason = StockCardLineItemReason.builder().name("Transfer In").reasonCategory(ReasonCategory.ADJUSTMENT).reasonType(ReasonType.CREDIT).build();
StockCardLineItem lineItem = StockCardLineItem.builder().stockOnHand(1).quantity(1).occurredDate(LocalDate.of(2017, 2, 13)).reason(reason).build();
StockCardLineItemDto lineItemDto = StockCardLineItemDto.builder().lineItem(lineItem).source(FacilityDto.builder().name("HF1").build()).build();
return StockCardDto.builder().stockOnHand(1).facility(FacilityDto.builder().name("HC01").build()).program(ProgramDto.builder().name("HIV").build()).orderable(OrderableDto.builder().productCode("ABC01").build()).lineItems(Arrays.asList(lineItemDto)).build();
}
Aggregations