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);
}
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);
}
}
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());
}
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);
}
}
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);
}
Aggregations