Search in sources :

Example 1 with PurchaseOrderPrintService

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);
    }
}
Also used : Context(com.axelor.rpc.Context) AxelorException(com.axelor.exception.AxelorException) PurchaseOrderPrintService(com.axelor.apps.purchase.service.print.PurchaseOrderPrintService) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) Nullable(javax.annotation.Nullable) AxelorException(com.axelor.exception.AxelorException)

Aggregations

PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)1 PurchaseOrderPrintService (com.axelor.apps.purchase.service.print.PurchaseOrderPrintService)1 AxelorException (com.axelor.exception.AxelorException)1 Context (com.axelor.rpc.Context)1 Nullable (javax.annotation.Nullable)1