Search in sources :

Example 1 with PhysicalInventoryLineItemDto

use of org.openlmis.stockmanagement.dto.PhysicalInventoryLineItemDto 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 PhysicalInventoryLineItemDto

use of org.openlmis.stockmanagement.dto.PhysicalInventoryLineItemDto in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryServiceTest method shouldSearchBasedOnIsDraft.

private void shouldSearchBasedOnIsDraft(PhysicalInventory inventory, boolean isDraft) {
    // given
    inventory.setIsDraft(isDraft);
    when(physicalInventoryRepository.findByProgramIdAndFacilityIdAndIsDraft(programId, facilityId, isDraft)).thenReturn(Collections.singletonList(inventory));
    // when
    List<PhysicalInventoryDto> foundDraft = physicalInventoryService.findPhysicalInventory(programId, facilityId, isDraft);
    // then
    assertEquals(1, foundDraft.size());
    assertEquals(programId, foundDraft.get(0).getProgramId());
    assertEquals(facilityId, foundDraft.get(0).getFacilityId());
    assertEquals(isDraft, foundDraft.get(0).getIsDraft());
    PhysicalInventoryLineItemDto lineItemDto = foundDraft.get(0).getLineItems().get(0);
    assertEquals(orderableId, lineItemDto.getOrderableId());
    assertEquals(null, lineItemDto.getQuantity());
}
Also used : PhysicalInventoryLineItemDto(org.openlmis.stockmanagement.dto.PhysicalInventoryLineItemDto) PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto)

Example 3 with PhysicalInventoryLineItemDto

use of org.openlmis.stockmanagement.dto.PhysicalInventoryLineItemDto 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)

Example 4 with PhysicalInventoryLineItemDto

use of org.openlmis.stockmanagement.dto.PhysicalInventoryLineItemDto in project openlmis-stockmanagement by OpenLMIS.

the class PhysicalInventoryControllerIntegrationTest method generatePhysicalInventoryLineItem.

private PhysicalInventoryLineItemDto generatePhysicalInventoryLineItem() {
    PhysicalInventoryLineItemDto item = new PhysicalInventoryLineItemDto();
    item.setQuantity(10);
    item.setStockOnHand(5);
    item.setOrderableId(UUID.randomUUID());
    item.setStockAdjustments(new ArrayList<>());
    item.setLotId(UUID.randomUUID());
    item.setExtraData(new HashMap<>());
    return item;
}
Also used : PhysicalInventoryLineItemDto(org.openlmis.stockmanagement.dto.PhysicalInventoryLineItemDto)

Example 5 with PhysicalInventoryLineItemDto

use of org.openlmis.stockmanagement.dto.PhysicalInventoryLineItemDto in project openlmis-stockmanagement by OpenLMIS.

the class VvmValidatorTest method generateVvmApplicable.

private VvmApplicable generateVvmApplicable(OrderableDto orderable) {
    PhysicalInventoryLineItemDto lineItem = new PhysicalInventoryLineItemDto();
    lineItem.setOrderableId(orderable.getId());
    return lineItem;
}
Also used : PhysicalInventoryLineItemDto(org.openlmis.stockmanagement.dto.PhysicalInventoryLineItemDto)

Aggregations

PhysicalInventoryLineItemDto (org.openlmis.stockmanagement.dto.PhysicalInventoryLineItemDto)7 PhysicalInventoryDto (org.openlmis.stockmanagement.dto.PhysicalInventoryDto)3 Test (org.junit.Test)2 PhysicalInventory (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory)2 PhysicalInventoryLineItem (org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItem)1 ValidationMessageException (org.openlmis.stockmanagement.exception.ValidationMessageException)1