Search in sources :

Example 31 with Context

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

the class TestStaticCompileGroovy method test.

@Test
public void test() {
    String script = "import com.axelor.auth.db.User\n" + "import groovy.transform.CompileStatic\n" + "@CompileStatic\n" + "void execute(){\n" + "User user = new User()\n" + "user.code = 'abc'\n" + "def x = user\n" + "println(x.code)\n" + "}\n" + "execute()";
    Context ctx = new Context(User.class);
    GroovyScriptHelper helper = new GroovyScriptHelper(ctx);
    helper.eval(script);
}
Also used : Context(com.axelor.rpc.Context) GroovyScriptHelper(com.axelor.script.GroovyScriptHelper) Test(org.junit.Test)

Example 32 with Context

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

the class ManufOrderController method cancel.

public void cancel(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        ManufOrder manufOrder = context.asType(ManufOrder.class);
        Beans.get(ManufOrderWorkflowService.class).cancel(Beans.get(ManufOrderRepository.class).find(manufOrder.getId()), manufOrder.getCancelReason(), manufOrder.getCancelReasonStr());
        response.setFlash(I18n.get(IExceptionMessage.MANUF_ORDER_CANCEL));
        response.setCanClose(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) ManufOrderWorkflowService(com.axelor.apps.production.service.manuforder.ManufOrderWorkflowService) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 33 with Context

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

the class MrpForecastController method computeTotalForecast.

public void computeTotalForecast(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    @SuppressWarnings("unchecked") ArrayList<LinkedHashMap<String, Object>> mrpForecastList = (ArrayList<LinkedHashMap<String, Object>>) context.get("mrpForecasts");
    BigDecimal totalForecast = BigDecimal.ZERO;
    BigDecimal sopSalesForecast = new BigDecimal(context.get("sopSalesForecast").toString());
    if (mrpForecastList != null) {
        for (LinkedHashMap<String, Object> mrpForecastItem : mrpForecastList) {
            BigDecimal qty = new BigDecimal(mrpForecastItem.get("qty").toString());
            if (qty.compareTo(BigDecimal.ZERO) == 0) {
                continue;
            }
            @SuppressWarnings("unchecked") LinkedHashMap<String, Object> productMap = (LinkedHashMap<String, Object>) mrpForecastItem.get("product");
            BigDecimal unitPrice = new BigDecimal(productMap.get("salePrice").toString());
            totalForecast = totalForecast.add(qty.multiply(unitPrice));
        }
    }
    response.setValue("$totalForecast", totalForecast);
    response.setValue("$difference", sopSalesForecast.subtract(totalForecast).setScale(Beans.get(AppBaseService.class).getNbDecimalDigitForUnitPrice()).abs());
}
Also used : Context(com.axelor.rpc.Context) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) LinkedHashMap(java.util.LinkedHashMap)

Example 34 with Context

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

the class AppraisalController method createAppraisals.

public void createAppraisals(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        Set<Map<String, Object>> employeeSet = new HashSet<Map<String, Object>>();
        employeeSet.addAll((Collection<? extends Map<String, Object>>) context.get("employeeSet"));
        Set<Employee> employees = new HashSet<Employee>();
        EmployeeRepository employeeRepo = Beans.get(EmployeeRepository.class);
        for (Map<String, Object> emp : employeeSet) {
            Long empId = Long.parseLong(emp.get("id").toString());
            employees.add(employeeRepo.find(empId));
        }
        Long templateId = Long.parseLong(context.get("templateId").toString());
        Appraisal appraisalTemplate = Beans.get(AppraisalRepository.class).find(templateId);
        Boolean send = (Boolean) context.get("sendAppraisals");
        Set<Long> createdIds = Beans.get(AppraisalService.class).createAppraisals(appraisalTemplate, employees, send);
        response.setView(ActionView.define("Appraisal").model(Appraisal.class.getName()).add("grid", "appraisal-grid").add("form", "appraisal-form").param("search-filters", "appraisal-fitlers").domain("self.id in :createdIds").context("createdIds", createdIds).map());
        response.setCanClose(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) Appraisal(com.axelor.apps.talent.db.Appraisal) EmployeeRepository(com.axelor.apps.hr.db.repo.EmployeeRepository) Employee(com.axelor.apps.hr.db.Employee) AppraisalRepository(com.axelor.apps.talent.db.repo.AppraisalRepository) Map(java.util.Map) AppraisalService(com.axelor.apps.talent.service.AppraisalService) HashSet(java.util.HashSet)

Example 35 with Context

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

the class InvoiceBatchController method run.

/**
 * Lancer le batch à travers un web service.
 *
 * @param request
 * @param response
 * @throws AxelorException
 */
public void run(ActionRequest request, ActionResponse response) throws AxelorException {
    Context context = request.getContext();
    Batch batch = Beans.get(InvoiceBatchService.class).run((String) context.get("code"));
    Map<String, Object> mapData = new HashMap<String, Object>();
    mapData.put("anomaly", batch.getAnomaly());
    response.setData(mapData);
}
Also used : Context(com.axelor.rpc.Context) InvoiceBatch(com.axelor.apps.account.db.InvoiceBatch) Batch(com.axelor.apps.base.db.Batch) HashMap(java.util.HashMap) InvoiceBatchService(com.axelor.apps.account.service.invoice.InvoiceBatchService)

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