use of com.axelor.script.ScriptHelper in project axelor-open-suite by axelor.
the class LogisticalFormServiceImpl method computeTotals.
@Override
public void computeTotals(LogisticalForm logisticalForm) throws LogisticalFormError {
BigDecimal totalNetMass = BigDecimal.ZERO;
BigDecimal totalGrossMass = BigDecimal.ZERO;
BigDecimal totalVolume = BigDecimal.ZERO;
if (logisticalForm.getLogisticalFormLineList() != null) {
ScriptHelper scriptHelper = getScriptHelper(logisticalForm);
LogisticalFormLineService logisticalFormLineService = Beans.get(LogisticalFormLineService.class);
for (LogisticalFormLine logisticalFormLine : logisticalForm.getLogisticalFormLineList()) {
StockMoveLine stockMoveLine = logisticalFormLine.getStockMoveLine();
if (logisticalFormLine.getTypeSelect() != LogisticalFormLineRepository.TYPE_DETAIL) {
if (logisticalFormLine.getGrossMass() != null) {
totalGrossMass = totalGrossMass.add(logisticalFormLine.getGrossMass());
}
BigDecimal toAdd = logisticalFormLineService.evalVolume(logisticalFormLine, scriptHelper);
if (toAdd == null) {
throw new LogisticalFormError(logisticalForm, I18n.get(IExceptionMessage.LOGISTICAL_FORM_INVALID_DIMENSIONS));
} else {
totalVolume = totalVolume.add(toAdd);
}
} else if (stockMoveLine != null) {
totalNetMass = totalNetMass.add(logisticalFormLine.getQty().multiply(stockMoveLine.getNetMass()));
}
}
totalVolume = totalVolume.divide(new BigDecimal(1_000_000), 10, RoundingMode.HALF_UP);
logisticalForm.setTotalNetMass(totalNetMass.setScale(3, RoundingMode.HALF_UP));
logisticalForm.setTotalGrossMass(totalGrossMass.setScale(3, RoundingMode.HALF_UP));
logisticalForm.setTotalVolume(totalVolume.setScale(3, RoundingMode.HALF_UP));
}
}
use of com.axelor.script.ScriptHelper in project axelor-open-suite by axelor.
the class BatchJob method applyBeanPropertiesWithScriptHelper.
private Map<String, Object> applyBeanPropertiesWithScriptHelper(Object bean, Map<String, Object> properties) {
Context scriptContext = new Context(Mapper.toMap(bean), bean.getClass());
ScriptHelper scriptHelper = new GroovyScriptHelper(scriptContext);
return applyBeanProperties(bean, properties, value -> scriptHelper.eval(value.toString()));
}
use of com.axelor.script.ScriptHelper in project axelor-open-suite by axelor.
the class ImportAdvancedImport method importGeneral.
@SuppressWarnings("unchecked")
public Object importGeneral(Object bean, Map<String, Object> values) throws ClassNotFoundException {
if (bean == null) {
return bean;
}
FileTab fileTab = fileTabRepo.find(Long.valueOf(values.get("fileTabId").toString()));
ScriptHelper scriptHelper = new GroovyScriptHelper(new ScriptBindings(values));
List<String> exprs = (List<String>) values.get("ifConditions" + fileTab.getId());
if (!CollectionUtils.isEmpty(exprs)) {
if ((boolean) scriptHelper.eval(String.join(" || ", exprs))) {
return null;
}
}
if (((Model) bean).getId() == null) {
List<Property> propList = this.getProperties(bean);
JPA.save((Model) bean);
this.addJsonObjectRecord(bean, fileTab, fileTab.getMetaModel().getName(), values);
int fieldSeq = 2;
int btnSeq = 3;
for (Property prop : propList) {
validatorService.createCustomObjectSet(fileTab.getClass().getName(), prop.getTarget().getName(), fieldSeq);
validatorService.createCustomButton(fileTab.getClass().getName(), prop.getTarget().getName(), btnSeq);
this.addJsonObjectRecord(prop.get(bean), fileTab, StringUtils.substringAfterLast(prop.getTarget().getName(), "."), values);
fieldSeq++;
btnSeq++;
}
}
final String ACTIONS_TO_APPLY = "actionsToApply" + fileTab.getId();
if (!ObjectUtils.isEmpty(values.get(ACTIONS_TO_APPLY))) {
bean = actionService.apply(values.get(ACTIONS_TO_APPLY).toString(), bean);
}
return bean;
}
use of com.axelor.script.ScriptHelper in project axelor-open-suite by axelor.
the class ConfiguratorServiceImpl method computeFormula.
@Override
public Object computeFormula(String groovyFormula, JsonContext values) {
User currentUser = AuthUtils.getUser();
Company company = currentUser != null ? currentUser.getActiveCompany() : null;
values.put("__user__", currentUser);
values.put("__date__", appBaseService.getTodayDate(company));
values.put("__datetime__", appBaseService.getTodayDateTime(company));
ScriptHelper scriptHelper = new GroovyScriptHelper(values);
return scriptHelper.eval(groovyFormula);
}
Aggregations