Search in sources :

Example 11 with StockCardLineItem

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

the class QuantityValidator method calculateStockOnHand.

private void calculateStockOnHand(StockEventDto eventDto, List<StockEventLineItemDto> group, StockCard foundCard) {
    for (StockEventLineItemDto lineItem : group) {
        StockCardLineItem stockCardLineItem = StockCardLineItem.createLineItemFrom(eventDto, lineItem, foundCard, null);
        stockCardLineItem.setReason(eventDto.getContext().findEventReason(lineItem.getReasonId()));
    }
    foundCard.calculateStockOnHand();
}
Also used : StockEventLineItemDto(org.openlmis.stockmanagement.dto.StockEventLineItemDto) StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem)

Example 12 with StockCardLineItem

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

the class StockCardSummariesServiceTest method createStockCard.

private StockCard createStockCard(UUID orderableId, UUID cardId) {
    StockCard stockCard = new StockCard();
    stockCard.setOrderableId(orderableId);
    stockCard.setId(cardId);
    Map<String, String> oldExtraData = new HashMap<>();
    oldExtraData.put("vvmStatus", "STAGE_1");
    Map<String, String> newExtraData = new HashMap<>();
    newExtraData.put("vvmStatus", "STAGE_2");
    StockCardLineItem lineItem1 = StockCardLineItem.builder().occurredDate(LocalDate.of(2017, 3, 17)).processedDate(of(2017, 3, 17, 15, 10, 31, 100, UTC)).quantity(1).extraData(oldExtraData).build();
    StockCardLineItem lineItem2 = StockCardLineItem.builder().occurredDate(LocalDate.of(2017, 3, 18)).processedDate(of(2017, 3, 18, 15, 10, 31, 100, UTC)).quantity(1).extraData(newExtraData).build();
    stockCard.setLineItems(asList(lineItem1, lineItem2, lineItem1));
    return stockCard;
}
Also used : HashMap(java.util.HashMap) StockCardLineItem(org.openlmis.stockmanagement.domain.card.StockCardLineItem) StockCard(org.openlmis.stockmanagement.domain.card.StockCard) UUID.fromString(java.util.UUID.fromString)

Example 13 with StockCardLineItem

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

the class QuantityValidatorTest method shouldNotRejectWhenStockOnHandWithAdjustmentsMatchesQuantity.

@Test
public void shouldNotRejectWhenStockOnHandWithAdjustmentsMatchesQuantity() throws Exception {
    // given
    LocalDate firstDate = dateFromYear(2015);
    StockCardLineItem lineItem = createCreditLineItem(firstDate.plusDays(1), 10);
    StockCard card = new StockCard();
    card.setLineItems(newArrayList(lineItem));
    StockEventDto event = spy(createPhysicalInventoryEventDto(firstDate.plusDays(2), 5, singletonList(createDebitAdjustment(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 14 with StockCardLineItem

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

the class QuantityValidatorTest method shouldNotRejectWhenStockOnHandDoesNotMatchQuantityAndNoAdjustmentsProvided.

@Test
public void shouldNotRejectWhenStockOnHandDoesNotMatchQuantityAndNoAdjustmentsProvided() {
    // given
    LocalDate firstDate = dateFromYear(2015);
    StockCardLineItem lineItem = createCreditLineItem(firstDate.plusDays(1), 15);
    StockCard card = new StockCard();
    card.setLineItems(newArrayList(lineItem));
    StockEventDto event = createPhysicalInventoryEventDto(firstDate.plusDays(2), 5, null);
    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 15 with StockCardLineItem

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

the class StockCardLineItemDataBuilder method build.

/**
 * Creates new instance of {@link StockCardLineItem} with properties.
 *
 * @return created line item.
 */
public StockCardLineItem build() {
    StockCardLineItem lineItem = new StockCardLineItem(stockCard, originEvent, quantity, extraData, reason, sourceFreeText, destinationFreeText, documentNumber, reasonFreeText, signature, source, destination, occurredDate, processedDateTime, userId, stockOnHand, stockAdjustments);
    lineItem.setId(id);
    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