Search in sources :

Example 11 with PhysicalInventory

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

the class PhysicalInventoryDto method toPhysicalInventory.

private PhysicalInventory toPhysicalInventory(boolean isDraft) {
    PhysicalInventory inventory = new PhysicalInventory();
    inventory.setId(id);
    inventory.setProgramId(programId);
    inventory.setFacilityId(facilityId);
    inventory.setOccurredDate(occurredDate);
    inventory.setDocumentNumber(documentNumber);
    inventory.setSignature(signature);
    inventory.setIsDraft(isDraft);
    if (lineItems != null) {
        inventory.setLineItems(lineItems.stream().map(lineItemDto -> lineItemDto.toPhysicalInventoryLineItem(inventory)).collect(toList()));
    }
    return inventory;
}
Also used : PhysicalInventory(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory)

Example 12 with PhysicalInventory

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

the class PhysicalInventoryValidatorTest method testValidateBasedOnIfExistingIsDraft.

private void testValidateBasedOnIfExistingIsDraft(boolean isDraft) {
    PhysicalInventoryDto inventory = newInventory();
    PhysicalInventory existingInventory = mock(PhysicalInventory.class);
    when(existingInventory.getIsDraft()).thenReturn(isDraft);
    when(repository.findOne(inventory.getId())).thenReturn(existingInventory);
    validator.validateDraft(inventory, inventory.getId());
}
Also used : PhysicalInventory(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory) PhysicalInventoryDto(org.openlmis.stockmanagement.dto.PhysicalInventoryDto)

Example 13 with PhysicalInventory

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

the class PhysicalInventoryDto method toEmptyPhysicalInventory.

/**
 * Convert into physical inventory jpa model for create new draft.
 *
 * @return converted jpa model.
 */
public PhysicalInventory toEmptyPhysicalInventory() {
    PhysicalInventory inventory = new PhysicalInventory();
    inventory.setProgramId(programId);
    inventory.setFacilityId(facilityId);
    inventory.setIsDraft(true);
    return inventory;
}
Also used : PhysicalInventory(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory)

Example 14 with PhysicalInventory

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

the class PhysicalInventoryDtoTest method shouldConvertIntoInventoryJpaModelForSubmit.

@Test
public void shouldConvertIntoInventoryJpaModelForSubmit() throws Exception {
    // given
    PhysicalInventoryDto piDto = createInventoryDto();
    // when
    PhysicalInventory inventory = piDto.toPhysicalInventoryForSubmit();
    // then
    fieldsEqual(piDto, inventory);
    assertThat(inventory.getIsDraft(), is(false));
}
Also used : PhysicalInventory(org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory) Test(org.junit.Test)

Example 15 with PhysicalInventory

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

the class PhysicalInventoryServiceTest method shouldNotThrowExceptionWhenSaveDraftIfExistingDraftHasSameId.

@Test
public void shouldNotThrowExceptionWhenSaveDraftIfExistingDraftHasSameId() throws Exception {
    UUID programId = UUID.randomUUID();
    UUID facilityId = UUID.randomUUID();
    PhysicalInventoryDto piDto = createInventoryDto(programId, facilityId);
    PhysicalInventory mock = mock(PhysicalInventory.class);
    when(mock.getId()).thenReturn(piDto.getId());
    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)

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