use of com.axelor.apps.purchase.service.print.PurchaseOrderPrintService in project axelor-open-suite by axelor.
the class PurchaseOrderController method showPurchaseOrder.
/**
* Called from grid or form purchase order view, print selected purchase order.
*
* @param request
* @param response
* @return
*/
@SuppressWarnings("unchecked")
public void showPurchaseOrder(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
String fileLink;
String title;
PurchaseOrderPrintService purchaseOrderPrintService = Beans.get(PurchaseOrderPrintService.class);
try {
if (!ObjectUtils.isEmpty(request.getContext().get("_ids"))) {
List<Long> ids = Lists.transform((List) request.getContext().get("_ids"), new Function<Object, Long>() {
@Nullable
@Override
public Long apply(@Nullable Object input) {
return Long.parseLong(input.toString());
}
});
fileLink = purchaseOrderPrintService.printPurchaseOrders(ids);
title = I18n.get("Purchase orders");
} else if (context.get("id") != null) {
PurchaseOrder purchaseOrder = Beans.get(PurchaseOrderRepository.class).find(Long.parseLong(context.get("id").toString()));
title = purchaseOrderPrintService.getFileName(purchaseOrder);
fileLink = purchaseOrderPrintService.printPurchaseOrder(purchaseOrder, ReportSettings.FORMAT_PDF);
logger.debug("Printing " + title);
} else {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.NO_PURCHASE_ORDER_SELECTED_FOR_PRINTING));
}
response.setView(ActionView.define(title).add("html", fileLink).map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations