Search in sources :

Example 11 with ActionResponse

use of com.axelor.rpc.ActionResponse in project axelor-open-suite by axelor.

the class ProjectedStockController method showChartProjectedStock.

public void showChartProjectedStock(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    List<Map<String, Object>> dataList = new ArrayList<>();
    @SuppressWarnings("unchecked") Collection<Map<String, Object>> contextMrpLineList = (Collection<Map<String, Object>>) context.get("_mrpLineListToProject");
    List<MrpLine> mrpLineList = contextMrpLineList.stream().map(map -> Mapper.toBean(MrpLine.class, map)).collect(Collectors.toList());
    if (!mrpLineList.isEmpty()) {
        List<MrpLine> mrpLineLastList = new ArrayList<>();
        MrpLine lastMrpLine = mrpLineList.get(0);
        for (int i = 1; i < mrpLineList.size(); ++i) {
            MrpLine mrpLine = mrpLineList.get(i);
            if (mrpLine.getMaturityDate().isAfter(lastMrpLine.getMaturityDate())) {
                mrpLineLastList.add(lastMrpLine);
            }
            lastMrpLine = mrpLine;
        }
        mrpLineLastList.add(lastMrpLine);
        lastMrpLine = mrpLineList.get(0);
        LocalDate mrpDate = lastMrpLine.getMaturityDate();
        for (MrpLine mrpLine : mrpLineLastList) {
            mrpDate = addInterElementForProjectedStockChart(dataList, lastMrpLine, mrpDate, mrpLine);
            Map<String, Object> dataMap = new HashMap<>();
            dataMap.put("name", mrpLine.getMaturityDate());
            dataMap.put("cumulativeQty", mrpLine.getCumulativeQty());
            dataList.add(dataMap);
            lastMrpLine = mrpLine;
        }
    }
    response.setData(dataList);
}
Also used : Context(com.axelor.rpc.Context) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) ActionView(com.axelor.meta.schema.actions.ActionView) HashMap(java.util.HashMap) Mapper(com.axelor.db.mapper.Mapper) PurchaseOrderStockService(com.axelor.apps.supplychain.service.PurchaseOrderStockService) ArrayList(java.util.ArrayList) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) I18n(com.axelor.i18n.I18n) ActionRequest(com.axelor.rpc.ActionRequest) StockLocationLineService(com.axelor.apps.stock.service.StockLocationLineService) ProjectedStockService(com.axelor.apps.supplychain.service.ProjectedStockService) SaleOrderLineServiceSupplyChain(com.axelor.apps.supplychain.service.SaleOrderLineServiceSupplyChain) MrpLine(com.axelor.apps.supplychain.db.MrpLine) Collection(java.util.Collection) TraceBackService(com.axelor.exception.service.TraceBackService) Collectors(java.util.stream.Collectors) List(java.util.List) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) LocalDate(java.time.LocalDate) Context(com.axelor.rpc.Context) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MrpLine(com.axelor.apps.supplychain.db.MrpLine) LocalDate(java.time.LocalDate) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with ActionResponse

use of com.axelor.rpc.ActionResponse in project axelor-open-suite by axelor.

the class ManufOrderController method finish.

public void finish(ActionRequest request, ActionResponse response) {
    try {
        Long manufOrderId = (Long) request.getContext().get("id");
        ManufOrder manufOrder = Beans.get(ManufOrderRepository.class).find(manufOrderId);
        // we have to inject TraceBackService to use non static methods
        TraceBackService traceBackService = Beans.get(TraceBackService.class);
        long tracebackCount = traceBackService.countMessageTraceBack(manufOrder);
        if (!Beans.get(ManufOrderWorkflowService.class).finish(manufOrder)) {
            response.setNotify(I18n.get(IExceptionMessage.MANUF_ORDER_EMAIL_NOT_SENT));
        } else if (traceBackService.countMessageTraceBack(manufOrder) > tracebackCount) {
            traceBackService.findLastMessageTraceBack(manufOrder).ifPresent(traceback -> response.setNotify(String.format(I18n.get(com.axelor.apps.message.exception.IExceptionMessage.SEND_EMAIL_EXCEPTION), traceback.getMessage())));
        }
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : IExceptionMessage(com.axelor.apps.production.exceptions.IExceptionMessage) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) BirtException(org.eclipse.birt.core.exception.BirtException) CostSheetRepository(com.axelor.apps.production.db.repo.CostSheetRepository) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) ActionView(com.axelor.meta.schema.actions.ActionView) ProdProductRepository(com.axelor.apps.production.db.repo.ProdProductRepository) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) ActionResponse(com.axelor.rpc.ActionResponse) I18n(com.axelor.i18n.I18n) ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) ActionRequest(com.axelor.rpc.ActionRequest) ProdProductProductionRepository(com.axelor.apps.production.service.ProdProductProductionRepository) ProdProduct(com.axelor.apps.production.db.ProdProduct) StringTool(com.axelor.apps.tool.StringTool) ManufOrderPrintService(com.axelor.apps.production.service.manuforder.ManufOrderPrintService) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) MethodHandles(java.lang.invoke.MethodHandles) CostSheet(com.axelor.apps.production.db.CostSheet) TraceBackService(com.axelor.exception.service.TraceBackService) IOException(java.io.IOException) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Collectors(java.util.stream.Collectors) ManufOrderWorkflowService(com.axelor.apps.production.service.manuforder.ManufOrderWorkflowService) List(java.util.List) IReport(com.axelor.apps.production.report.IReport) CostSheetService(com.axelor.apps.production.service.costsheet.CostSheetService) ReportSettings(com.axelor.apps.report.engine.ReportSettings) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) ManufOrder(com.axelor.apps.production.db.ManufOrder) ReportFactory(com.axelor.apps.ReportFactory) LocalDate(java.time.LocalDate) ObjectUtils(com.axelor.common.ObjectUtils) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) Context(com.axelor.rpc.Context) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) Singleton(com.google.inject.Singleton) TraceBackService(com.axelor.exception.service.TraceBackService) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 13 with ActionResponse

use of com.axelor.rpc.ActionResponse in project axelor-open-suite by axelor.

the class SopLineController method fillMrpForecast.

public void fillMrpForecast(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    @SuppressWarnings("unchecked") LinkedHashMap<String, Object> productCategoryMap = (LinkedHashMap<String, Object>) context.get("_productCategory");
    @SuppressWarnings("unchecked") LinkedHashMap<String, Object> sopLineMap = (LinkedHashMap<String, Object>) context.get("_sopLine");
    @SuppressWarnings("unchecked") LinkedHashMap<String, Object> currencyMap = (LinkedHashMap<String, Object>) sopLineMap.get("currency");
    BigDecimal sopSalesForecast = new BigDecimal(sopLineMap.get("sopSalesForecast").toString());
    Long productCategoryId = Long.parseLong(productCategoryMap.get("id").toString());
    Currency currency = currencyRepo.find(Long.parseLong(currencyMap.get("id").toString()));
    BigDecimal totalForecast = BigDecimal.ZERO;
    SortedSet<Map<String, Object>> mrpForecastSet = new TreeSet<Map<String, Object>>(Comparator.comparing(m -> (String) m.get("code")));
    List<Product> productList = Beans.get(ProductRepository.class).all().filter("self.productCategory.id = ?1 ", productCategoryId).fetch();
    if (productList != null) {
        for (Product product : productList) {
            Map<String, Object> map = new HashMap<String, Object>();
            MrpForecast mrpForecast = mrpForecastRepo.all().filter("self.product.id = ?1 AND self.technicalOrigin = ?2", product.getId(), MrpForecastRepository.TECHNICAL_ORIGIN_CREATED_FROM_SOP).fetchOne();
            if (mrpForecast != null) {
                map = Mapper.toMap(mrpForecast);
                BigDecimal totalPrice = mrpForecast.getQty().multiply(product.getSalePrice());
                map.put("$totalPrice", totalPrice);
                map.put("$unitPrice", product.getSalePrice());
                map.put("code", product.getCode());
                totalForecast = totalForecast.add(totalPrice);
                mrpForecastSet.add(map);
                continue;
            }
            map.put("product", product);
            map.put("qty", BigDecimal.ZERO);
            map.put("$totalPrice", BigDecimal.ZERO);
            map.put("$unitPrice", product.getSalePrice());
            map.put("code", product.getCode());
            mrpForecastSet.add(map);
        }
    }
    response.setValue("$mrpForecasts", mrpForecastSet);
    response.setValue("$sopSalesForecast", sopSalesForecast);
    response.setValue("$totalForecast", totalForecast);
    response.setValue("$difference", sopSalesForecast.subtract(totalForecast).setScale(Beans.get(AppBaseService.class).getNbDecimalDigitForUnitPrice()));
    response.setValue("$currency", currency);
}
Also used : Context(com.axelor.rpc.Context) CurrencyRepository(com.axelor.apps.base.db.repo.CurrencyRepository) SortedSet(java.util.SortedSet) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Inject(com.google.inject.Inject) HashMap(java.util.HashMap) MrpForecastRepository(com.axelor.apps.supplychain.db.repo.MrpForecastRepository) Mapper(com.axelor.db.mapper.Mapper) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) MrpForecast(com.axelor.apps.supplychain.db.MrpForecast) Currency(com.axelor.apps.base.db.Currency) TreeSet(java.util.TreeSet) LinkedHashMap(java.util.LinkedHashMap) BigDecimal(java.math.BigDecimal) List(java.util.List) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) ActionRequest(com.axelor.rpc.ActionRequest) Comparator(java.util.Comparator) Context(com.axelor.rpc.Context) Singleton(com.google.inject.Singleton) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal) LinkedHashMap(java.util.LinkedHashMap) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) TreeSet(java.util.TreeSet) Currency(com.axelor.apps.base.db.Currency) MrpForecast(com.axelor.apps.supplychain.db.MrpForecast) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 14 with ActionResponse

use of com.axelor.rpc.ActionResponse in project axelor-open-suite by axelor.

the class ManufOrderController method multiLevelManufOrderOnLoad.

/**
 * Called from manuf order form, on clicking "Multi-level planning" button.
 *
 * @param request
 * @param response
 */
public void multiLevelManufOrderOnLoad(ActionRequest request, ActionResponse response) {
    try {
        Long moId = Long.valueOf(request.getContext().get("id").toString());
        ManufOrder mo = Beans.get(ManufOrderRepository.class).find(moId);
        boolean showOnlyMissingQty = request.getContext().get("_showOnlyMissingQty") != null && Boolean.parseBoolean(request.getContext().get("_showOnlyMissingQty").toString());
        ProdProductProductionRepository prodProductProductionRepository = Beans.get(ProdProductProductionRepository.class);
        List<ProdProduct> prodProducts = mo.getToConsumeProdProductList().stream().filter(prodProduct -> prodProduct.getProduct().getProductSubTypeSelect() == ProductRepository.PRODUCT_SUB_TYPE_FINISHED_PRODUCT || prodProduct.getProduct().getProductSubTypeSelect() == ProductRepository.PRODUCT_SUB_TYPE_SEMI_FINISHED_PRODUCT).filter(prodProduct -> !showOnlyMissingQty || prodProductProductionRepository.computeMissingQty(prodProduct.getProduct().getId(), prodProduct.getQty(), moId).compareTo(BigDecimal.ZERO) > 0).collect(Collectors.toList());
        response.setValue("$components", prodProducts);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : IExceptionMessage(com.axelor.apps.production.exceptions.IExceptionMessage) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) BirtException(org.eclipse.birt.core.exception.BirtException) CostSheetRepository(com.axelor.apps.production.db.repo.CostSheetRepository) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) ActionView(com.axelor.meta.schema.actions.ActionView) ProdProductRepository(com.axelor.apps.production.db.repo.ProdProductRepository) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) ActionResponse(com.axelor.rpc.ActionResponse) I18n(com.axelor.i18n.I18n) ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) ActionRequest(com.axelor.rpc.ActionRequest) ProdProductProductionRepository(com.axelor.apps.production.service.ProdProductProductionRepository) ProdProduct(com.axelor.apps.production.db.ProdProduct) StringTool(com.axelor.apps.tool.StringTool) ManufOrderPrintService(com.axelor.apps.production.service.manuforder.ManufOrderPrintService) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) MethodHandles(java.lang.invoke.MethodHandles) CostSheet(com.axelor.apps.production.db.CostSheet) TraceBackService(com.axelor.exception.service.TraceBackService) IOException(java.io.IOException) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Collectors(java.util.stream.Collectors) ManufOrderWorkflowService(com.axelor.apps.production.service.manuforder.ManufOrderWorkflowService) List(java.util.List) IReport(com.axelor.apps.production.report.IReport) CostSheetService(com.axelor.apps.production.service.costsheet.CostSheetService) ReportSettings(com.axelor.apps.report.engine.ReportSettings) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) ManufOrder(com.axelor.apps.production.db.ManufOrder) ReportFactory(com.axelor.apps.ReportFactory) LocalDate(java.time.LocalDate) ObjectUtils(com.axelor.common.ObjectUtils) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) Context(com.axelor.rpc.Context) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) Singleton(com.google.inject.Singleton) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) ProdProductProductionRepository(com.axelor.apps.production.service.ProdProductProductionRepository) ProdProduct(com.axelor.apps.production.db.ProdProduct) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 15 with ActionResponse

use of com.axelor.rpc.ActionResponse 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

ActionResponse (com.axelor.rpc.ActionResponse)19 Context (com.axelor.rpc.Context)17 List (java.util.List)17 Beans (com.axelor.inject.Beans)16 ActionRequest (com.axelor.rpc.ActionRequest)16 TraceBackService (com.axelor.exception.service.TraceBackService)15 Singleton (com.google.inject.Singleton)15 I18n (com.axelor.i18n.I18n)14 ArrayList (java.util.ArrayList)14 AxelorException (com.axelor.exception.AxelorException)13 ActionView (com.axelor.meta.schema.actions.ActionView)13 BigDecimal (java.math.BigDecimal)13 Map (java.util.Map)13 Product (com.axelor.apps.base.db.Product)12 Collectors (java.util.stream.Collectors)12 TraceBackRepository (com.axelor.exception.db.repo.TraceBackRepository)11 StringTool (com.axelor.apps.tool.StringTool)10 ObjectUtils (com.axelor.common.ObjectUtils)10 MethodHandles (java.lang.invoke.MethodHandles)10 Logger (org.slf4j.Logger)10