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);
}
}
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);
}
}
Aggregations