Search in sources :

Example 1 with PhysicalInventoryLineItem

use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItem in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryLineItemDtoTest method shouldCreateDtoFromJpaModel.

@Test
public void shouldCreateDtoFromJpaModel() throws Exception {
    // given
    PhysicalInventoryLineItem lineItem = PhysicalInventoryLineItem.builder().quantity(123).orderableId(UUID.randomUUID()).lotId(UUID.randomUUID()).stockAdjustments(singletonList(createStockAdjustment())).build();
    // when
    PhysicalInventoryLineItemDto lineItemDto = PhysicalInventoryLineItemDto.from(lineItem);
    // then
    assertThat(lineItemDto.getQuantity(), is(lineItem.getQuantity()));
    assertThat(lineItemDto.getOrderableId(), is(lineItem.getOrderableId()));
    assertThat(lineItemDto.getLotId(), is(lineItem.getLotId()));
    assertThat(lineItemDto.getStockAdjustments(), is(lineItem.getStockAdjustments()));
}
Also used : PhysicalInventoryLineItem(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItem) Test(org.junit.Test)

Example 2 with PhysicalInventoryLineItem

use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItem in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryService method submitPhysicalInventory.

/**
 * Persist physical inventory, with an event id.
 *
 * @param inventoryDto inventoryDto.
 * @param eventId      eventId.
 */
void submitPhysicalInventory(PhysicalInventoryDto inventoryDto, UUID eventId) {
    LOGGER.info("submit physical inventory");
    PhysicalInventory inventory = inventoryDto.toPhysicalInventoryForSubmit();
    if (null != eventId) {
        StockEvent event = new StockEvent();
        event.setId(eventId);
        inventory.setStockEvent(event);
    }
    Map<OrderableLotIdentity, StockCard> cards = stockCardRepository.findByProgramIdAndFacilityId(inventory.getProgramId(), inventory.getFacilityId()).stream().collect(toMap(OrderableLotIdentity::identityOf, card -> card));
    for (PhysicalInventoryLineItem line : inventory.getLineItems()) {
        StockCard foundCard = cards.get(OrderableLotIdentity.identityOf(line));
        // modified during recalculation, this will avoid persistence of those modified models
        if (foundCard != null) {
            StockCard stockCard = foundCard.shallowCopy();
            stockCard.calculateStockOnHand();
            line.setPreviousStockOnHandWhenSubmitted(stockCard.getStockOnHand());
        }
    }
    physicalInventoriesRepository.save(inventory);
}
Also used : StockCard(org.openlmis.stockmanagement.domain.card.StockCard) PhysicalInventoryValidator(org.openlmis.stockmanagement.validators.PhysicalInventoryValidator) Logger(org.slf4j.Logger) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) PhysicalInventoryLineItem(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItem) ERROR_PHYSICAL_INVENTORY_NOT_FOUND(org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_PHYSICAL_INVENTORY_NOT_FOUND) PhysicalInventoriesRepository(org.openlmis.stockmanagement.repository.PhysicalInventoriesRepository) UUID(java.util.UUID) PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto) StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) OrderableLotIdentity(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity) Message(org.openlmis.stockmanagement.util.Message) List(java.util.List) PhysicalInventory(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory) Collectors.toMap(java.util.stream.Collectors.toMap) ERROR_PHYSICAL_INVENTORY_IS_SUBMITTED(org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_PHYSICAL_INVENTORY_IS_SUBMITTED) Service(org.springframework.stereotype.Service) ERROR_PHYSICAL_INVENTORY_DRAFT_EXISTS(org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_PHYSICAL_INVENTORY_DRAFT_EXISTS) Map(java.util.Map) ResourceNotFoundException(org.openlmis.stockmanagement.exception.ResourceNotFoundException) StockCardRepository(org.openlmis.stockmanagement.repository.StockCardRepository) Collections(java.util.Collections) PhysicalInventory(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory) PhysicalInventoryLineItem(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItem) StockEvent(org.openlmis.stockmanagement.domain.event.StockEvent) OrderableLotIdentity(org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity) StockCard(org.openlmis.stockmanagement.domain.card.StockCard)

Example 3 with PhysicalInventoryLineItem

use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItem in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryDtoTest method fieldsEqual.

private void fieldsEqual(PhysicalInventoryDto piDto, PhysicalInventory inventory) {
    assertThat(inventory.getOccurredDate(), is(piDto.getOccurredDate()));
    assertThat(inventory.getProgramId(), is(piDto.getProgramId()));
    assertThat(inventory.getFacilityId(), is(piDto.getFacilityId()));
    assertThat(inventory.getSignature(), is(piDto.getSignature()));
    assertThat(inventory.getDocumentNumber(), is(piDto.getDocumentNumber()));
    assertThat(inventory.getLineItems().size(), is(1));
    PhysicalInventoryLineItemDto piLineItemDto = piDto.getLineItems().get(0);
    PhysicalInventoryLineItem piLineItem = inventory.getLineItems().get(0);
    assertThat(piLineItem.getQuantity(), is(piLineItemDto.getQuantity()));
    assertThat(piLineItem.getOrderableId(), is(piLineItemDto.getOrderableId()));
}
Also used : PhysicalInventoryLineItem(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItem)

Example 4 with PhysicalInventoryLineItem

use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItem in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryServiceTest method verifyLineItems.

private void verifyLineItems(List<PhysicalInventoryLineItemDto> expected, List<PhysicalInventoryLineItem> actual) {
    PhysicalInventoryLineItemDto lineItemDto = expected.get(0);
    PhysicalInventoryLineItem lineItem = actual.get(0);
    assertThat(lineItem.getQuantity(), is(lineItemDto.getQuantity()));
    assertThat(lineItem.getOrderableId(), is(lineItemDto.getOrderableId()));
}
Also used : PhysicalInventoryLineItem(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItem) PhysicalInventoryLineItemDto(org.openlmis.stockmanagement.dto.PhysicalInventoryLineItemDto)

Aggregations

PhysicalInventoryLineItem (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItem)4 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Collectors.toMap (java.util.stream.Collectors.toMap)1 Test (org.junit.Test)1 StockCard (org.openlmis.stockmanagement.domain.card.StockCard)1 StockEvent (org.openlmis.stockmanagement.domain.event.StockEvent)1 OrderableLotIdentity (org.openlmis.stockmanagement.domain.identity.OrderableLotIdentity)1 PhysicalInventory (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory)1 PhysicalInventoryDto (org.openlmis.stockmanagement.dto.PhysicalInventoryDto)1 PhysicalInventoryLineItemDto (org.openlmis.stockmanagement.dto.PhysicalInventoryLineItemDto)1 ResourceNotFoundException (org.openlmis.stockmanagement.exception.ResourceNotFoundException)1 ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)1 ERROR_PHYSICAL_INVENTORY_DRAFT_EXISTS (org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_PHYSICAL_INVENTORY_DRAFT_EXISTS)1 ERROR_PHYSICAL_INVENTORY_IS_SUBMITTED (org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_PHYSICAL_INVENTORY_IS_SUBMITTED)1 ERROR_PHYSICAL_INVENTORY_NOT_FOUND (org.openlmis.stockmanagement.i18n.MessageKeys.ERROR_PHYSICAL_INVENTORY_NOT_FOUND)1 PhysicalInventoriesRepository (org.openlmis.stockmanagement.repository.PhysicalInventoriesRepository)1 StockCardRepository (org.openlmis.stockmanagement.repository.StockCardRepository)1