use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItem in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryLineItemDtoTest method shouldCreateDtoFromJpaModel.
@Test
public void shouldCreateDtoFromJpaModel() throws Exception {
// given
PhysicalInventoryLineItem lineItem = PhysicalInventoryLineItem.builder().quantity(123).orderableId(UUID.randomUUID()).lotId(UUID.randomUUID()).stockAdjustments(singletonList(createStockAdjustment())).build();
// when
PhysicalInventoryLineItemDto lineItemDto = PhysicalInventoryLineItemDto.from(lineItem);
// then
assertThat(lineItemDto.getQuantity(), is(lineItem.getQuantity()));
assertThat(lineItemDto.getOrderableId(), is(lineItem.getOrderableId()));
assertThat(lineItemDto.getLotId(), is(lineItem.getLotId()));
assertThat(lineItemDto.getStockAdjustments(), is(lineItem.getStockAdjustments()));
}
use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItem 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.PhysicalInventoryLineItem in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryDtoTest method fieldsEqual.
private void fieldsEqual(PhysicalInventoryDto piDto, PhysicalInventory inventory) {
assertThat(inventory.getOccurredDate(), is(piDto.getOccurredDate()));
assertThat(inventory.getProgramId(), is(piDto.getProgramId()));
assertThat(inventory.getFacilityId(), is(piDto.getFacilityId()));
assertThat(inventory.getSignature(), is(piDto.getSignature()));
assertThat(inventory.getDocumentNumber(), is(piDto.getDocumentNumber()));
assertThat(inventory.getLineItems().size(), is(1));
PhysicalInventoryLineItemDto piLineItemDto = piDto.getLineItems().get(0);
PhysicalInventoryLineItem piLineItem = inventory.getLineItems().get(0);
assertThat(piLineItem.getQuantity(), is(piLineItemDto.getQuantity()));
assertThat(piLineItem.getOrderableId(), is(piLineItemDto.getOrderableId()));
}
use of org.openlmis.stockmanagement.domain.physicalinventory.PhysicalInventoryLineItem in project openlmis-stockmanagement by OpenLMIS.
the class PhysicalInventoryServiceTest method verifyLineItems.
private void verifyLineItems(List<PhysicalInventoryLineItemDto> expected, List<PhysicalInventoryLineItem> actual) {
PhysicalInventoryLineItemDto lineItemDto = expected.get(0);
PhysicalInventoryLineItem lineItem = actual.get(0);
assertThat(lineItem.getQuantity(), is(lineItemDto.getQuantity()));
assertThat(lineItem.getOrderableId(), is(lineItemDto.getOrderableId()));
}
Aggregations