use of com.axelor.apps.stock.service.stockmove.print.PickingStockMovePrintService in project axelor-open-suite by axelor.
the class StockMoveController method printPickingStockMove.
/**
* 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 printPickingStockMove(ActionRequest request, ActionResponse response) {
try {
Context context = request.getContext();
String fileLink;
String title;
String userType = (String) context.get("_userType");
PickingStockMovePrintService pickingstockMovePrintService = Beans.get(PickingStockMovePrintService.class);
if (!ObjectUtils.isEmpty(context.get("_ids"))) {
List<Long> ids = (List) (((List) context.get("_ids")).stream().filter(ObjectUtils::notEmpty).map(input -> Long.parseLong(input.toString())).collect(Collectors.toList()));
fileLink = pickingstockMovePrintService.printStockMoves(ids, userType);
title = I18n.get("Stock Moves");
} else if (context.get("id") != null) {
StockMove stockMove = context.asType(StockMove.class);
stockMove = Beans.get(StockMoveRepository.class).find(stockMove.getId());
title = pickingstockMovePrintService.getFileName(stockMove);
fileLink = pickingstockMovePrintService.printStockMove(stockMove, ReportSettings.FORMAT_PDF, userType);
logger.debug("Printing " + title);
} else {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.STOCK_MOVE_PRINT));
}
response.setReload(true);
response.setView(ActionView.define(title).add("html", fileLink).map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations