use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryDtoTest method shouldConvertIntoInventoryJpaModelForDraft.
@Test
public void shouldConvertIntoInventoryJpaModelForDraft() throws Exception {
// given
PhysicalInventoryDto piDto = createInventoryDto();
// when
PhysicalInventory inventory = piDto.toPhysicalInventoryForDraft();
// then
fieldsEqual(piDto, inventory);
assertThat(inventory.getIsDraft(), is(true));
}
use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryDtoTest method shouldCreateDtoFromJpaModel.
@Test
public void shouldCreateDtoFromJpaModel() throws Exception {
// given
PhysicalInventory inventory = createInventoryDto().toPhysicalInventoryForDraft();
// when
PhysicalInventoryDto dto = PhysicalInventoryDto.from(inventory);
// then
assertThat(dto.getProgramId(), is(inventory.getProgramId()));
assertThat(dto.getFacilityId(), is(inventory.getFacilityId()));
assertThat(dto.getOccurredDate(), is(inventory.getOccurredDate()));
assertThat(dto.getDocumentNumber(), is(inventory.getDocumentNumber()));
assertThat(dto.getSignature(), is(inventory.getSignature()));
assertThat(dto.getIsStarter(), is(false));
assertThat(dto.getLineItems().size(), is(1));
}
use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory 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);
}
use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryService method createNewDraft.
/**
* Create new draft.
*
* @param dto physical inventory dto.
* @return the saved inventory.
*/
public PhysicalInventoryDto createNewDraft(PhysicalInventoryDto dto) {
LOGGER.info("create physical inventory draft");
physicalInventoryValidator.validateEmptyDraft(dto);
checkPermission(dto.getProgramId(), dto.getFacilityId());
checkIfDraftExists(dto);
dto.setId(null);
PhysicalInventory save = physicalInventoriesRepository.save(dto.toEmptyPhysicalInventory());
dto.setId(save.getId());
return dto;
}
use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventory in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryService method deletePhysicalInventory.
/**
* Delete draft.
*
* @param id physical inventory id.
*/
public void deletePhysicalInventory(UUID id) {
PhysicalInventory foundInventory = physicalInventoriesRepository.findOne(id);
if (foundInventory != null) {
checkPermission(foundInventory.getProgramId(), foundInventory.getFacilityId());
if (!foundInventory.getIsDraft()) {
throw new ValidationMessageException(ERROR_PHYSICAL_INVENTORY_IS_SUBMITTED);
}
physicalInventoriesRepository.delete(foundInventory);
} else {
throw new ResourceNotFoundException(new Message(ERROR_PHYSICAL_INVENTORY_NOT_FOUND, id));
}
}
Aggregations