Search in sources :

Example 1 with StockCardLineItemDto

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"));
}
Also used : OrderableDto(org.openlmis.stockmanagement.dto.referencedata.OrderableDto) StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) StockCardLineItemDto(org.openlmis.stockmanagement.dto.StockCardLineItemDto) ProgramDto(org.openlmis.stockmanagement.dto.referencedata.ProgramDto) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) FacilityDto(org.openlmis.stockmanagement.dto.referencedata.FacilityDto) StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) LotDto(org.openlmis.stockmanagement.dto.referencedata.LotDto) BaseIntegrationTest(org.openlmis.stockmanagement.BaseIntegrationTest) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with StockCardLineItemDto

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;
}
Also used : StockCardLineItemDto(org.openlmis.stockmanagement.dto.StockCardLineItemDto) StockCardDto(org.openlmis.stockmanagement.dto.StockCardDto)

Example 3 with StockCardLineItemDto

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();
}
Also used : StockCardLineItemReason(org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason) StockCardLineItemDto(org.openlmis.stockmanagement.dto.StockCardLineItemDto) StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem)

Aggregations

StockCardLineItemDto (org.openlmis.stockmanagement.dto.StockCardLineItemDto)3 StockCardDto (org.openlmis.stockmanagement.dto.StockCardDto)2 UUID (java.util.UUID)1 UUID.randomUUID (java.util.UUID.randomUUID)1 Test (org.junit.Test)1 BaseIntegrationTest (org.openlmis.stockmanagement.BaseIntegrationTest)1 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)1 StockCardLineItem (org.openlmis.stockmanagement.domain.card.StockCardLineItem)1 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)1 StockCardLineItemReason (org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason)1 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)1 FacilityDto (org.openlmis.stockmanagement.dto.referencedata.FacilityDto)1 LotDto (org.openlmis.stockmanagement.dto.referencedata.LotDto)1 OrderableDto (org.openlmis.stockmanagement.dto.referencedata.OrderableDto)1 ProgramDto (org.openlmis.stockmanagement.dto.referencedata.ProgramDto)1 StockEventDtoDataBuilder.createStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1