use of com.axelor.apps.stock.db.repo.InventoryLineRepository in project axelor-open-suite by axelor.
the class StockMoveServiceImpl method checkOngoingInventory.
/**
* Check and raise an exception if the provided stock move is involved in an ongoing inventory.
*
* @param stockMove
* @throws AxelorException
*/
private void checkOngoingInventory(StockMove stockMove) throws AxelorException {
List<StockLocation> stockLocationList = new ArrayList<>();
if (stockMove.getFromStockLocation().getTypeSelect() != StockLocationRepository.TYPE_VIRTUAL) {
stockLocationList.add(stockMove.getFromStockLocation());
}
if (stockMove.getToStockLocation().getTypeSelect() != StockLocationRepository.TYPE_VIRTUAL) {
stockLocationList.add(stockMove.getToStockLocation());
}
if (stockLocationList.isEmpty()) {
return;
}
List<Product> productList = stockMove.getStockMoveLineList().stream().map(StockMoveLine::getProduct).filter(Objects::nonNull).collect(Collectors.toList());
if (productList.isEmpty()) {
return;
}
InventoryLineRepository inventoryLineRepo = Beans.get(InventoryLineRepository.class);
InventoryLine inventoryLine = inventoryLineRepo.all().filter("self.inventory.statusSelect BETWEEN :startStatus AND :endStatus\n" + "AND self.inventory.stockLocation IN (:stockLocationList)\n" + "AND self.product IN (:productList)").bind("startStatus", InventoryRepository.STATUS_IN_PROGRESS).bind("endStatus", InventoryRepository.STATUS_COMPLETED).bind("stockLocationList", stockLocationList).bind("productList", productList).fetchOne();
if (inventoryLine != null) {
throw new AxelorException(inventoryLine, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.STOCK_MOVE_19), inventoryLine.getInventory().getInventorySeq());
}
}
Aggregations