Search in sources :

Example 1 with InventoryLineRepository

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());
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) StockLocation(com.axelor.apps.stock.db.StockLocation) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) InventoryLineRepository(com.axelor.apps.stock.db.repo.InventoryLineRepository) InventoryLine(com.axelor.apps.stock.db.InventoryLine)

Aggregations

Product (com.axelor.apps.base.db.Product)1 InventoryLine (com.axelor.apps.stock.db.InventoryLine)1 StockLocation (com.axelor.apps.stock.db.StockLocation)1 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)1 InventoryLineRepository (com.axelor.apps.stock.db.repo.InventoryLineRepository)1 AxelorException (com.axelor.exception.AxelorException)1 ArrayList (java.util.ArrayList)1