Search in sources :

Example 11 with ActionRequest

use of com.axelor.rpc.ActionRequest 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 12 with ActionRequest

use of com.axelor.rpc.ActionRequest 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 13 with ActionRequest

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

the class ActionServiceImpl method createHandler.

protected ActionHandler createHandler(String action) {
    ActionRequest request = new ActionRequest();
    Map<String, Object> data = new HashMap<>();
    request.setData(data);
    request.setModel(modelName);
    request.setAction(action);
    data.put("context", context);
    return executor.newActionHandler(request);
}
Also used : ActionRequest(com.axelor.rpc.ActionRequest) HashMap(java.util.HashMap)

Example 14 with ActionRequest

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

Example 15 with ActionRequest

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

the class StockMoveController method openStockPerDay.

public void openStockPerDay(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        Long locationId = Long.parseLong(((Map<String, Object>) context.get("stockLocation")).get("id").toString());
        LocalDate fromDate = LocalDate.parse(context.get("stockFromDate").toString());
        LocalDate toDate = LocalDate.parse(context.get("stockToDate").toString());
        Collection<Map<String, Object>> products = (Collection<Map<String, Object>>) context.get("productSet");
        String domain = null;
        List<Object> productIds = null;
        if (products != null && !products.isEmpty()) {
            productIds = Arrays.asList(products.stream().map(p -> p.get("id")).toArray());
            domain = "self.id in (:productIds)";
        }
        response.setView(ActionView.define(I18n.get("Stocks")).model(Product.class.getName()).add("cards", "stock-product-cards").add("grid", "stock-product-grid").add("form", "stock-product-form").domain(domain).context("fromStockWizard", true).context("productIds", productIds).context("stockFromDate", fromDate).context("stockToDate", toDate).context("locationId", locationId).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) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) LocalDate(java.time.LocalDate) AxelorException(com.axelor.exception.AxelorException)

Aggregations

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