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;
}
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());
}
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;
}
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));
}
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());
}
Aggregations