Search in sources :

Example 1 with StockMovePrintService

use of com.axelor.apps.stock.service.stockmove.print.StockMovePrintService in project axelor-open-suite by axelor.

the class StockMoveController method printStockMove.

/**
 * Method called from stock move form and grid view. Print one or more stock move as PDF
 *
 * @param request
 * @param response
 */
@SuppressWarnings("unchecked")
public void printStockMove(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        String fileLink;
        String title;
        StockMovePrintService stockMovePrintService = Beans.get(StockMovePrintService.class);
        if (!ObjectUtils.isEmpty(request.getContext().get("_ids"))) {
            List<Long> ids = (List) (((List) context.get("_ids")).stream().filter(ObjectUtils::notEmpty).map(input -> Long.parseLong(input.toString())).collect(Collectors.toList()));
            fileLink = stockMovePrintService.printStockMoves(ids);
            title = I18n.get("Stock Moves");
        } else if (context.get("id") != null) {
            StockMove stockMove = Beans.get(StockMoveRepository.class).find(Long.parseLong(context.get("id").toString()));
            title = stockMovePrintService.getFileName(stockMove);
            fileLink = stockMovePrintService.printStockMove(stockMove, ReportSettings.FORMAT_PDF);
            logger.debug("Printing " + title);
        } else {
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.STOCK_MOVE_PRINT));
        }
        response.setView(ActionView.define(title).add("html", fileLink).map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository) Arrays(java.util.Arrays) IExceptionMessage(com.axelor.apps.stock.exception.IExceptionMessage) StockMoveToolService(com.axelor.apps.stock.service.StockMoveToolService) ActionView(com.axelor.meta.schema.actions.ActionView) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) StockMoveService(com.axelor.apps.stock.service.StockMoveService) Mapper(com.axelor.db.mapper.Mapper) PrintingSettings(com.axelor.apps.base.db.PrintingSettings) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) I18n(com.axelor.i18n.I18n) ActionRequest(com.axelor.rpc.ActionRequest) PickingStockMovePrintService(com.axelor.apps.stock.service.stockmove.print.PickingStockMovePrintService) StringTool(com.axelor.apps.tool.StringTool) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) ConformityCertificatePrintService(com.axelor.apps.stock.service.stockmove.print.ConformityCertificatePrintService) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) StockMovePrintService(com.axelor.apps.stock.service.stockmove.print.StockMovePrintService) TraceBackService(com.axelor.exception.service.TraceBackService) TradingNameService(com.axelor.apps.base.service.TradingNameService) Collectors(java.util.stream.Collectors) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) List(java.util.List) ReportSettings(com.axelor.apps.report.engine.ReportSettings) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) LocalDate(java.time.LocalDate) ObjectUtils(com.axelor.common.ObjectUtils) Optional(java.util.Optional) Context(com.axelor.rpc.Context) Singleton(com.google.inject.Singleton) AxelorException(com.axelor.exception.AxelorException) PickingStockMovePrintService(com.axelor.apps.stock.service.stockmove.print.PickingStockMovePrintService) StockMovePrintService(com.axelor.apps.stock.service.stockmove.print.StockMovePrintService) StockMove(com.axelor.apps.stock.db.StockMove) ArrayList(java.util.ArrayList) List(java.util.List) ObjectUtils(com.axelor.common.ObjectUtils) AxelorException(com.axelor.exception.AxelorException)

Aggregations

PrintingSettings (com.axelor.apps.base.db.PrintingSettings)1 Product (com.axelor.apps.base.db.Product)1 TradingNameService (com.axelor.apps.base.service.TradingNameService)1 ReportSettings (com.axelor.apps.report.engine.ReportSettings)1 StockMove (com.axelor.apps.stock.db.StockMove)1 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)1 StockMoveLineRepository (com.axelor.apps.stock.db.repo.StockMoveLineRepository)1 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)1 IExceptionMessage (com.axelor.apps.stock.exception.IExceptionMessage)1 StockMoveService (com.axelor.apps.stock.service.StockMoveService)1 StockMoveToolService (com.axelor.apps.stock.service.StockMoveToolService)1 ConformityCertificatePrintService (com.axelor.apps.stock.service.stockmove.print.ConformityCertificatePrintService)1 PickingStockMovePrintService (com.axelor.apps.stock.service.stockmove.print.PickingStockMovePrintService)1 StockMovePrintService (com.axelor.apps.stock.service.stockmove.print.StockMovePrintService)1 StringTool (com.axelor.apps.tool.StringTool)1 ObjectUtils (com.axelor.common.ObjectUtils)1 Mapper (com.axelor.db.mapper.Mapper)1 AxelorException (com.axelor.exception.AxelorException)1 TraceBackRepository (com.axelor.exception.db.repo.TraceBackRepository)1 TraceBackService (com.axelor.exception.service.TraceBackService)1