Search in sources :

Example 1 with SaleOrderPrintService

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);
    }
}
Also used : Context(com.axelor.rpc.Context) SaleOrderPrintService(com.axelor.apps.sale.service.saleorder.print.SaleOrderPrintService) AxelorException(com.axelor.exception.AxelorException) SaleOrderService(com.axelor.apps.sale.service.saleorder.SaleOrderService) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Aggregations

SaleOrder (com.axelor.apps.sale.db.SaleOrder)1 SaleOrderService (com.axelor.apps.sale.service.saleorder.SaleOrderService)1 SaleOrderPrintService (com.axelor.apps.sale.service.saleorder.print.SaleOrderPrintService)1 AxelorException (com.axelor.exception.AxelorException)1 Context (com.axelor.rpc.Context)1 IOException (java.io.IOException)1 Nullable (javax.annotation.Nullable)1 BirtException (org.eclipse.birt.core.exception.BirtException)1