use of com.axelor.apps.sale.service.saleorder.print.SaleOrderPrintService in project axelor-open-suite by axelor.
the class SaleOrderController method exportSaleOrder.
@SuppressWarnings("unchecked")
public void exportSaleOrder(ActionRequest request, ActionResponse response, boolean proforma, String format) {
Context context = request.getContext();
String fileLink;
String title;
SaleOrderPrintService saleOrderPrintService = Beans.get(SaleOrderPrintService.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 = saleOrderPrintService.printSaleOrders(ids);
title = I18n.get("Sale orders");
} else if (context.get("id") != null) {
SaleOrder saleOrder = Beans.get(SaleOrderRepository.class).find(Long.parseLong(context.get("id").toString()));
title = Beans.get(SaleOrderService.class).getFileName(saleOrder);
fileLink = saleOrderPrintService.printSaleOrder(saleOrder, proforma, format);
response.setCanClose(true);
logger.debug("Printing " + title);
} else {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.SALE_ORDER_PRINT));
}
response.setView(ActionView.define(title).add("html", fileLink).map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations