Search in sources :

Example 1 with PhysicalInventory

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

the class PhysicalInventoryServiceTest method shouldReturnAllSavedInventories.

@Test
public void shouldReturnAllSavedInventories() throws Exception {
    PhysicalInventory inventory = createInventoryDraft(orderableId, programId, facilityId);
    // given
    when(physicalInventoryRepository.findByProgramIdAndFacilityId(programId, facilityId)).thenReturn(Collections.singletonList(inventory));
    // when
    List<PhysicalInventoryDto> foundDraft = physicalInventoryService.findPhysicalInventory(programId, facilityId, null);
    // then
    assertEquals(1, foundDraft.size());
    assertEquals(programId, foundDraft.get(0).getProgramId());
    assertEquals(facilityId, foundDraft.get(0).getFacilityId());
    PhysicalInventoryLineItemDto lineItemDto = foundDraft.get(0).getLineItems().get(0);
    assertEquals(orderableId, lineItemDto.getOrderableId());
    assertEquals(null, lineItemDto.getQuantity());
}
Also used : PhysicalInventory(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory) PhysicalInventoryLineItemDto(org.openlmis.stockmanagement.dto.PhysicalInventoryLineItemDto) PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto) Test(org.junit.Test)

Example 2 with PhysicalInventory

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

the class PhysicalInventoryServiceTest method shouldThrowExceptionWhenDeleteIfInventoryIsNotDraft.

@Test(expected = ValidationMessageException.class)
public void shouldThrowExceptionWhenDeleteIfInventoryIsNotDraft() throws Exception {
    UUID physicalInventoryId = UUID.randomUUID();
    PhysicalInventory physicalInventory = mock(PhysicalInventory.class);
    when(physicalInventory.getIsDraft()).thenReturn(false);
    when(physicalInventoryRepository.findOne(physicalInventoryId)).thenReturn(physicalInventory);
    physicalInventoryService.deletePhysicalInventory(physicalInventoryId);
}
Also used : PhysicalInventory(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 3 with PhysicalInventory

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

the class PhysicalInventoryServiceTest method shouldThrowExceptionWhenSaveDraftIfExistsAlready.

@Test(expected = ValidationMessageException.class)
public void shouldThrowExceptionWhenSaveDraftIfExistsAlready() throws Exception {
    UUID programId = UUID.randomUUID();
    UUID facilityId = UUID.randomUUID();
    PhysicalInventoryDto piDto = createInventoryDto(programId, facilityId);
    PhysicalInventory mock = mock(PhysicalInventory.class);
    when(mock.getId()).thenReturn(UUID.randomUUID());
    when(physicalInventoryRepository.findByProgramIdAndFacilityIdAndIsDraft(programId, facilityId, true)).thenReturn(Collections.singletonList(mock));
    physicalInventoryService.saveDraft(piDto, piDto.getId());
}
Also used : PhysicalInventory(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory) PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) Test(org.junit.Test)

Example 4 with PhysicalInventory

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

the class PhysicalInventoryController method checkPermission.

private void checkPermission(UUID id) {
    PhysicalInventory pi = repository.findOne(id);
    if (pi == null) {
        throw new ResourceNotFoundException(new Message(ERROR_PHYSICAL_INVENTORY_NOT_FOUND, id));
    }
    permissionService.canEditPhysicalInventory(pi.getProgramId(), pi.getFacilityId());
}
Also used : PhysicalInventory(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory) Message(org.openlmis.stockmanagement.util.Message) ResourceNotFoundException(org.openlmis.stockmanagement.exception.ResourceNotFoundException)

Example 5 with PhysicalInventory

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

the class PhysicalInventoryValidator method validateDraft.

/**
 * Check for physical inventory dto's validity.
 * Throws {@link ValidationMessageException} if an error found.
 * @param inventory physical inventory to validate.
 */
public void validateDraft(PhysicalInventoryDto inventory, UUID id) {
    if (!inventory.getId().equals(id)) {
        throw new ValidationMessageException(ERROR_PHYSICAL_INVENTORY_ID_MISMATCH);
    }
    PhysicalInventory foundInventory = physicalInventoriesRepository.findOne(id);
    if (foundInventory != null && !foundInventory.getIsDraft()) {
        throw new ValidationMessageException(ERROR_PHYSICAL_INVENTORY_IS_SUBMITTED);
    }
    List<PhysicalInventoryLineItemDto> lineItems = inventory.getLineItems();
    validateLineItems(lineItems);
    vvmValidator.validate(lineItems, ERROR_PHYSICAL_INVENTORY_ORDERABLE_DISABLED_VVM, false);
}
Also used : PhysicalInventory(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory) PhysicalInventoryLineItemDto(org.openlmis.stockmanagement.dto.PhysicalInventoryLineItemDto) ValidationMessageException(org.openlmis.stockmanagement.exception.ValidationMessageException)

Aggregations

PhysicalInventory (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory)23 Test (org.junit.Test)12 UUID (java.util.UUID)7 PhysicalInventoryDto (org.openlmis.stockmanagement.dto.PhysicalInventoryDto)7 UUID.randomUUID (java.util.UUID.randomUUID)6 ResourceNotFoundException (org.openlmis.stockmanagement.exception.ResourceNotFoundException)3 ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)3 Message (org.openlmis.stockmanagement.util.Message)3 PhysicalInventoryLineItemDto (org.openlmis.stockmanagement.dto.PhysicalInventoryLineItemDto)2 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Collectors.toMap (java.util.stream.Collectors.toMap)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 PhysicalInventoryLineItem (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItem)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