Search in sources :

Example 1 with StockCardLineItem

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

the class StockCardRepositoryIntegrationTest method generateInstance.

private StockCard generateInstance(UUID facility, UUID program, UUID product, UUID lot) {
    StockEvent event = new StockEventDataBuilder().withoutId().withFacility(facility).withProgram(program).build();
    event = stockEventsRepository.save(event);
    StockCardLineItem lineItem = new StockCardLineItemDataBuilder().withoutId().withOriginEvent(event).build();
    StockCard stockCard = new StockCardDataBuilder(event).withoutId().withOrderable(product).withLot(lot).withLineItem(lineItem).build();
    lineItem.setStockCard(stockCard);
    return stockCard;
}
Also used : StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) StockCardDataBuilder(org.openlmis.stockmanagement.testutils.StockCardDataBuilder) StockEventDataBuilder(org.openlmis.stockmanagement.testutils.StockEventDataBuilder) StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) StockCardLineItemDataBuilder(org.openlmis.stockmanagement.testutils.StockCardLineItemDataBuilder)

Example 2 with StockCardLineItem

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

the class QuantityValidatorTest method shouldRejectWhenAnyAdjustmentHasNegativeQuantity.

@Test
public void shouldRejectWhenAnyAdjustmentHasNegativeQuantity() throws Exception {
    // expect
    expectedException.expect(ValidationMessageException.class);
    expectedException.expectMessage(ERROR_EVENT_ADJUSTMENT_QUANITITY_INVALID);
    // given
    LocalDate firstDate = dateFromYear(2015);
    StockCardLineItem lineItem = createCreditLineItem(firstDate.plusDays(1), 15);
    StockCard card = new StockCard();
    card.setLineItems(singletonList(lineItem));
    StockEventDto event = spy(createPhysicalInventoryEventDto(firstDate.plusDays(2), 5, singletonList(createCreditAdjustment(-2))));
    mockCardFound(event, card);
    // when
    quantityValidator.validate(event);
}
Also used : StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 3 with StockCardLineItem

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

the class QuantityValidatorTest method shouldNotRejectWhenStockOnHandWithAdjustmentsDoesNotMatchQuantity.

@Test
public void shouldNotRejectWhenStockOnHandWithAdjustmentsDoesNotMatchQuantity() {
    // given
    LocalDate firstDate = dateFromYear(2015);
    StockCardLineItem lineItem = createCreditLineItem(firstDate.plusDays(1), 15);
    StockCard card = new StockCard();
    card.setLineItems(newArrayList(lineItem));
    StockEventDto event = spy(createPhysicalInventoryEventDto(firstDate.plusDays(2), 5, singletonList(createCreditAdjustment(5))));
    mockCardFound(event, card);
    // when
    quantityValidator.validate(event);
}
Also used : StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) StockEventDtoDataBuilder.createStockEventDto(org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto) StockEventDto(org.openlmis.stockmanagement.dto.StockEventDto) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 4 with StockCardLineItem

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

Example 5 with StockCardLineItem

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

the class StockCardLineItemDataBuilder method buildMock.

/**
 * Creates new mock instance of {@link StockCardLineItem} with properties.
 *
 * @return created mock.
 */
public StockCardLineItem buildMock() {
    StockCardLineItem lineItem = mock(StockCardLineItem.class);
    when(lineItem.getId()).thenReturn(id);
    when(lineItem.getStockCard()).thenReturn(stockCard);
    when(lineItem.getOriginEvent()).thenReturn(originEvent);
    when(lineItem.getQuantity()).thenReturn(quantity);
    when(lineItem.getExtraData()).thenReturn(extraData);
    when(lineItem.getReason()).thenReturn(reason);
    when(lineItem.getSourceFreeText()).thenReturn(sourceFreeText);
    when(lineItem.getDestinationFreeText()).thenReturn(destinationFreeText);
    when(lineItem.getDocumentNumber()).thenReturn(documentNumber);
    when(lineItem.getReasonFreeText()).thenReturn(reasonFreeText);
    when(lineItem.getSignature()).thenReturn(signature);
    when(lineItem.getSource()).thenReturn(source);
    when(lineItem.getDestination()).thenReturn(destination);
    when(lineItem.getOccurredDate()).thenReturn(occurredDate);
    when(lineItem.getProcessedDate()).thenReturn(processedDateTime);
    when(lineItem.getUserId()).thenReturn(userId);
    when(lineItem.getStockOnHand()).thenReturn(stockOnHand);
    when(lineItem.getStockAdjustments()).thenReturn(stockAdjustments);
    return lineItem;
}
Also used : StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem)

Aggregations

StockCardLineItem (org.openlmis.stockmanagement.domain.card.StockCardLineItem)15 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)9 Test (org.junit.Test)6 StockEventDto (org.openlmis.stockmanagement.dto.StockEventDto)6 StockEventDtoDataBuilder.createStockEventDto (org.openlmis.stockmanagement.testutils.StockEventDtoDataBuilder.createStockEventDto)6 LocalDate (java.time.LocalDate)5 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)3 HashMap (java.util.HashMap)2 UUID (java.util.UUID)2 UUID.randomUUID (java.util.UUID.randomUUID)2 BaseIntegrationTest (org.openlmis.stockmanagement.BaseIntegrationTest)2 StockCardLineItemReason (org.openlmis.stockmanagement.domain.reason.StockCardLineItemReason)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 UUID.fromString (java.util.UUID.fromString)1 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)1 StockCardLineItemDto (org.openlmis.stockmanagement.dto.StockCardLineItemDto)1 StockEventLineItemDto (org.openlmis.stockmanagement.dto.StockEventLineItemDto)1 StockCardDataBuilder (org.openlmis.stockmanagement.testutils.StockCardDataBuilder)1 StockCardLineItemDataBuilder (org.openlmis.stockmanagement.testutils.StockCardLineItemDataBuilder)1 StockEventDataBuilder (org.openlmis.stockmanagement.testutils.StockEventDataBuilder)1