Search in sources :

Example 1 with ManufOrderPrintService

use of com.axelor.apps.production.service.manuforder.ManufOrderPrintService in project axelor-open-suite by axelor.

the class ManufOrderController method print.

/**
 * Method that generate a Pdf file for an manufacturing order
 *
 * @param request
 * @param response
 * @return
 * @throws BirtException
 * @throws IOException
 */
public void print(ActionRequest request, ActionResponse response) {
    try {
        ManufOrder manufOrder = request.getContext().asType(ManufOrder.class);
        ManufOrderPrintService manufOrderPrintService = Beans.get(ManufOrderPrintService.class);
        @SuppressWarnings("unchecked") List<Integer> selectedManufOrderList = (List<Integer>) request.getContext().get("_ids");
        if (selectedManufOrderList != null) {
            String name = manufOrderPrintService.getManufOrdersFilename();
            String fileLink = manufOrderPrintService.printManufOrders(selectedManufOrderList.stream().map(Integer::longValue).collect(Collectors.toList()));
            LOG.debug("Printing {}", name);
            response.setView(ActionView.define(name).add("html", fileLink).map());
        } else if (manufOrder != null) {
            String name = manufOrderPrintService.getFileName(manufOrder);
            String fileLink = manufOrderPrintService.printManufOrder(manufOrder);
            LOG.debug("Printing {}", name);
            response.setView(ActionView.define(name).add("html", fileLink).map());
        } else {
            response.setFlash(I18n.get(IExceptionMessage.MANUF_ORDER_1));
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : ManufOrderPrintService(com.axelor.apps.production.service.manuforder.ManufOrderPrintService) ArrayList(java.util.ArrayList) List(java.util.List) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Aggregations

ManufOrder (com.axelor.apps.production.db.ManufOrder)1 ManufOrderPrintService (com.axelor.apps.production.service.manuforder.ManufOrderPrintService)1 AxelorException (com.axelor.exception.AxelorException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BirtException (org.eclipse.birt.core.exception.BirtException)1