use of com.axelor.apps.stock.service.stockmove.print.StockMovePrintService in project axelor-open-suite by axelor.
the class StockMoveController method printStockMove.
/**
* Method called from stock move form and grid view. Print one or more stock move as PDF
*
* @param request
* @param response
*/
@SuppressWarnings("unchecked")
public void printStockMove(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
String fileLink;
String title;
StockMovePrintService stockMovePrintService = Beans.get(StockMovePrintService.class);
if (!ObjectUtils.isEmpty(request.getContext().get("_ids"))) {
List<Long> ids = (List) (((List) context.get("_ids")).stream().filter(ObjectUtils::notEmpty).map(input -> Long.parseLong(input.toString())).collect(Collectors.toList()));
fileLink = stockMovePrintService.printStockMoves(ids);
title = I18n.get("Stock Moves");
} else if (context.get("id") != null) {
StockMove stockMove = Beans.get(StockMoveRepository.class).find(Long.parseLong(context.get("id").toString()));
title = stockMovePrintService.getFileName(stockMove);
fileLink = stockMovePrintService.printStockMove(stockMove, ReportSettings.FORMAT_PDF);
logger.debug("Printing " + title);
} else {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.STOCK_MOVE_PRINT));
}
response.setView(ActionView.define(title).add("html", fileLink).map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations