Search in sources :

Example 21 with Context

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

the class ProductStockController method displayStockMoveLine.

public void displayStockMoveLine(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    if (context.get("date") != null && context.getParent().get("locationId") != null) {
        LocalDate stockDate = LocalDate.parse(context.get("date").toString());
        Long locationId = Long.parseLong(context.getParent().get("locationId").toString());
        if (request.getContext().getParent().get("id") != null)
            response.setView(ActionView.define(I18n.get("Stock Move Lines")).model(StockMoveLine.class.getName()).add("grid", "stock-move-line-all-grid").add("form", "stock-move-line-all-form").param("search-filters", "stock-move-line-filters").domain("self.product.id = :id AND (self.stockMove.fromStockLocation.id = :locationId OR self.stockMove.toStockLocation.id = :locationId) AND self.stockMove.statusSelect != :status AND (self.stockMove.estimatedDate <= :stockDate OR self.stockMove.realDate <= :stockDate)").context("id", request.getContext().getParent().get("id")).context("locationId", locationId).context("status", StockMoveRepository.STATUS_CANCELED).context("stockDate", stockDate).map());
        response.setCanClose(true);
    }
}
Also used : Context(com.axelor.rpc.Context) LocalDate(java.time.LocalDate)

Example 22 with Context

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

the class StockMoveLineController method openTrackNumberWizard.

public void openTrackNumberWizard(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    StockMoveLine stockMoveLine = context.asType(StockMoveLine.class);
    StockMove stockMove = null;
    if (context.getParent() != null && context.getParent().get("_model").equals("com.axelor.apps.stock.db.StockMove")) {
        stockMove = context.getParent().asType(StockMove.class);
    } else if (stockMoveLine.getStockMove() != null && stockMoveLine.getStockMove().getId() != null) {
        stockMove = Beans.get(StockMoveRepository.class).find(stockMoveLine.getStockMove().getId());
    }
    boolean _hasWarranty = false, _isPerishable = false;
    if (stockMoveLine.getProduct() != null) {
        _hasWarranty = stockMoveLine.getProduct().getHasWarranty();
        _isPerishable = stockMoveLine.getProduct().getIsPerishable();
    }
    response.setView(ActionView.define(I18n.get(IExceptionMessage.TRACK_NUMBER_WIZARD_TITLE)).model(Wizard.class.getName()).add("form", "stock-move-line-track-number-wizard-form").param("popup", "reload").param("show-toolbar", "false").param("show-confirm", "false").param("width", "large").param("popup-save", "false").context("_stockMove", stockMove).context("_stockMoveLine", stockMoveLine).context("_hasWarranty", _hasWarranty).context("_isPerishable", _isPerishable).map());
}
Also used : Context(com.axelor.rpc.Context) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) Wizard(com.axelor.apps.base.db.Wizard)

Example 23 with Context

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

the class StockMoveLineController method splitStockMoveLineByTrackingNumber.

public void splitStockMoveLineByTrackingNumber(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    if (context.get("trackingNumbers") == null) {
        response.setAlert(I18n.get(IExceptionMessage.TRACK_NUMBER_WIZARD_NO_RECORD_ADDED_ERROR));
    } else {
        @SuppressWarnings("unchecked") LinkedHashMap<String, Object> stockMoveLineMap = (LinkedHashMap<String, Object>) context.get("_stockMoveLine");
        Integer stockMoveLineId = (Integer) stockMoveLineMap.get("id");
        StockMoveLine stockMoveLine = Beans.get(StockMoveLineRepository.class).find(new Long(stockMoveLineId));
        @SuppressWarnings("unchecked") ArrayList<LinkedHashMap<String, Object>> trackingNumbers = (ArrayList<LinkedHashMap<String, Object>>) context.get("trackingNumbers");
        Beans.get(StockMoveLineService.class).splitStockMoveLineByTrackingNumber(stockMoveLine, trackingNumbers);
        response.setCanClose(true);
    }
}
Also used : Context(com.axelor.rpc.Context) StockMoveLineService(com.axelor.apps.stock.service.StockMoveLineService) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) StockMoveLineRepository(com.axelor.apps.stock.db.repo.StockMoveLineRepository)

Example 24 with Context

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

the class AppController method configure.

public void configure(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    MetaView formView = null;
    String code = (String) context.get("code");
    String appName = Inflector.getInstance().camelize(code);
    Model config = (Model) context.get("app" + appName);
    String model = "com.axelor.apps.base.db.App" + appName;
    if (config != null) {
        formView = Beans.get(MetaViewRepository.class).all().filter("self.type = 'form' AND self.model = ? AND self.name like '%-config-form'", model).fetchOne();
    }
    if (formView == null) {
        response.setFlash(I18n.get(IExceptionMessages.NO_CONFIG_REQUIRED));
    } else {
        response.setView(ActionView.define(I18n.get("Configure") + ": " + context.get("name")).add("form", formView.getName()).model(model).context("_showRecord", config.getId()).param("forceEdit", "true").map());
    }
}
Also used : Context(com.axelor.rpc.Context) Model(com.axelor.db.Model) MetaView(com.axelor.meta.db.MetaView)

Example 25 with Context

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

the class WkfCommonServiceImpl method evalExpression.

@Override
public Object evalExpression(Map<String, Object> varMap, String expr) {
    if (Strings.isNullOrEmpty(expr)) {
        return null;
    }
    if (expr.startsWith("${") && expr.endsWith("}")) {
        expr = expr.replaceFirst("\\$\\{", "");
        expr = expr.substring(0, expr.length() - 1);
    }
    GroovyScriptHelper helper;
    if (varMap instanceof Context) {
        helper = new GroovyScriptHelper((Context) varMap);
    } else {
        SimpleBindings simpleBindings = new SimpleBindings();
        simpleBindings.putAll(varMap);
        helper = new GroovyScriptHelper(simpleBindings);
    }
    helper.getBindings().put("$ctx", WkfContextHelper.class);
    Object result = null;
    try {
        result = helper.eval(expr);
    } catch (Exception e) {
    }
    log.debug("Eval expr: {}, result: {}", expr, result);
    return result;
}
Also used : FullContext(com.axelor.apps.tool.context.FullContext) Context(com.axelor.rpc.Context) SimpleBindings(javax.script.SimpleBindings) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper) AxelorException(com.axelor.exception.AxelorException)

Aggregations

Context (com.axelor.rpc.Context)149 AxelorException (com.axelor.exception.AxelorException)52 BigDecimal (java.math.BigDecimal)37 Map (java.util.Map)37 HashMap (java.util.HashMap)26 ArrayList (java.util.ArrayList)23 SaleOrder (com.axelor.apps.sale.db.SaleOrder)19 List (java.util.List)18 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)17 Invoice (com.axelor.apps.account.db.Invoice)16 LinkedHashMap (java.util.LinkedHashMap)15 Product (com.axelor.apps.base.db.Product)14 Model (com.axelor.db.Model)13 StockMove (com.axelor.apps.stock.db.StockMove)12 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)12 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)11 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)11 LocalDate (java.time.LocalDate)11 Beans (com.axelor.inject.Beans)10 ActionRequest (com.axelor.rpc.ActionRequest)10