Search in sources :

Example 1 with StockMoveLineRepository

use of com.axelor.apps.stock.db.repo.StockMoveLineRepository in project axelor-open-suite by axelor.

the class StockMoveController method splitStockMoveLinesUnit.

@SuppressWarnings("unchecked")
public void splitStockMoveLinesUnit(ActionRequest request, ActionResponse response) {
    try {
        StockMove stockMove = request.getContext().asType(StockMove.class);
        List<StockMoveLine> stockMoveLineContextList = (List<StockMoveLine>) request.getContext().get("stockMoveLineList");
        stockMove = Beans.get(StockMoveRepository.class).find(stockMove.getId());
        if (stockMoveLineContextList == null) {
            response.setFlash(I18n.get(IExceptionMessage.STOCK_MOVE_14));
            return;
        }
        List<StockMoveLine> stockMoveLineList = new ArrayList<>();
        StockMoveLineRepository stockMoveLineRepo = Beans.get(StockMoveLineRepository.class);
        for (StockMoveLine stockMoveLineContext : stockMoveLineContextList.stream().filter(StockMoveLine::isSelected).collect(Collectors.toList())) {
            StockMoveLine stockMoveLine = stockMoveLineRepo.find(stockMoveLineContext.getId());
            stockMoveLine.setSelected(true);
            stockMoveLineList.add(stockMoveLine);
        }
        boolean selected = Beans.get(StockMoveService.class).splitStockMoveLines(stockMove, stockMoveLineList, BigDecimal.ONE);
        if (!selected) {
            response.setFlash(I18n.get(IExceptionMessage.STOCK_MOVE_15));
        }
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) StockMoveService(com.axelor.apps.stock.service.StockMoveService) ArrayList(java.util.ArrayList) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) ArrayList(java.util.ArrayList) List(java.util.List) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) AxelorException(com.axelor.exception.AxelorException)

Example 2 with StockMoveLineRepository

use of com.axelor.apps.stock.db.repo.StockMoveLineRepository in project axelor-open-suite by axelor.

the class StockMoveController method splitStockMoveLinesSpecial.

@SuppressWarnings("unchecked")
public void splitStockMoveLinesSpecial(ActionRequest request, ActionResponse response) {
    try {
        List<HashMap<String, Object>> selectedStockMoveLineMapList = (List<HashMap<String, Object>>) request.getContext().get("stockMoveLineList");
        Map<String, Object> stockMoveMap = (Map<String, Object>) request.getContext().get("stockMove");
        if (selectedStockMoveLineMapList == null) {
            response.setFlash(I18n.get(IExceptionMessage.STOCK_MOVE_14));
            return;
        }
        List<StockMoveLine> stockMoveLineList = new ArrayList<>();
        StockMoveLineRepository stockMoveLineRepo = Beans.get(StockMoveLineRepository.class);
        for (HashMap<String, Object> map : selectedStockMoveLineMapList) {
            StockMoveLine stockMoveLine = Mapper.toBean(StockMoveLine.class, map);
            stockMoveLine = stockMoveLineRepo.find(stockMoveLine.getId());
            stockMoveLine.setSelected(true);
            stockMoveLineList.add(stockMoveLine);
        }
        if (stockMoveLineList.isEmpty()) {
            response.setFlash(I18n.get(IExceptionMessage.STOCK_MOVE_15));
            return;
        }
        BigDecimal splitQty = null;
        if (request.getContext().containsKey("splitQty")) {
            splitQty = new BigDecimal(request.getContext().get("splitQty").toString());
        }
        if (splitQty == null || splitQty.compareTo(BigDecimal.ZERO) < 1) {
            response.setFlash(I18n.get(IExceptionMessage.STOCK_MOVE_16));
            return;
        }
        StockMove stockMove = Mapper.toBean(StockMove.class, stockMoveMap);
        stockMove = Beans.get(StockMoveRepository.class).find(stockMove.getId());
        Beans.get(StockMoveService.class).splitStockMoveLines(stockMove, stockMoveLineList, splitQty);
        response.setCanClose(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) StockMoveService(com.axelor.apps.stock.service.StockMoveService) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) ArrayList(java.util.ArrayList) List(java.util.List) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

StockMove (com.axelor.apps.stock.db.StockMove)2 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)2 StockMoveLineRepository (com.axelor.apps.stock.db.repo.StockMoveLineRepository)2 StockMoveService (com.axelor.apps.stock.service.StockMoveService)2 AxelorException (com.axelor.exception.AxelorException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 BigDecimal (java.math.BigDecimal)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1