use of com.axelor.apps.sale.db.ConfiguratorCreator in project axelor-open-suite by axelor.
the class ConfiguratorCreatorController method updateAttributes.
public void updateAttributes(ActionRequest request, ActionResponse response) {
try {
ConfiguratorCreator creator = request.getContext().asType(ConfiguratorCreator.class);
creator = Beans.get(ConfiguratorCreatorRepository.class).find(creator.getId());
Beans.get(ConfiguratorCreatorService.class).updateAttributes(creator);
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(e);
}
}
use of com.axelor.apps.sale.db.ConfiguratorCreator in project axelor-open-suite by axelor.
the class ConfiguratorCreatorController method updateAndActivate.
/**
* Called from the configurator creator form on formula changes
*
* @param request
* @param response
*/
public void updateAndActivate(ActionRequest request, ActionResponse response) {
try {
ConfiguratorCreator creator = request.getContext().asType(ConfiguratorCreator.class);
ConfiguratorCreatorService configuratorCreatorService = Beans.get(ConfiguratorCreatorService.class);
creator = Beans.get(ConfiguratorCreatorRepository.class).find(creator.getId());
configuratorCreatorService.updateIndicators(creator);
configuratorCreatorService.activate(creator);
response.setSignal("refresh-app", true);
} catch (Exception e) {
TraceBackService.trace(e);
}
}
use of com.axelor.apps.sale.db.ConfiguratorCreator in project axelor-open-suite by axelor.
the class ConfiguratorCreatorImportServiceImpl method updateOtherFieldsInAttribute.
/**
* Update the configurator id in other fields of the attribute.
*
* @param creator
* @param attribute attribute to update
*/
protected void updateOtherFieldsInAttribute(ConfiguratorCreator creator, MetaJsonField attribute) {
try {
List<Field> fieldsToUpdate = Arrays.stream(attribute.getClass().getDeclaredFields()).filter(field -> field.getType().equals(String.class)).collect(Collectors.toList());
for (Field field : fieldsToUpdate) {
Mapper mapper = Mapper.of(attribute.getClass());
Method getter = mapper.getGetter(field.getName());
String fieldString = (String) getter.invoke(attribute);
if (fieldString != null && fieldString.contains("_")) {
Method setter = mapper.getSetter(field.getName());
String updatedFieldString = fieldString.substring(0, fieldString.lastIndexOf('_')) + '_' + creator.getId();
setter.invoke(attribute, updatedFieldString);
}
}
} catch (Exception e) {
TraceBackService.trace(e);
}
}
use of com.axelor.apps.sale.db.ConfiguratorCreator in project axelor-open-suite by axelor.
the class ConfiguratorServiceImpl method fillOneToManyFields.
protected void fillOneToManyFields(Configurator configurator, Model model, JsonContext jsonAttributes) throws AxelorException {
try {
ConfiguratorCreator creator = configurator.getConfiguratorCreator();
List<? extends ConfiguratorFormula> configuratorFormulaList;
Class[] methodArg = new Class[1];
if (creator.getGenerateProduct()) {
configuratorFormulaList = creator.getConfiguratorProductFormulaList();
methodArg[0] = Product.class;
} else {
configuratorFormulaList = creator.getConfiguratorSOLineFormulaList();
methodArg[0] = SaleOrderLine.class;
}
configuratorFormulaList = configuratorFormulaList.stream().filter(configuratorFormula -> "OneToMany".equals(configuratorFormula.getMetaField().getRelationship())).collect(Collectors.toList());
for (ConfiguratorFormula formula : configuratorFormulaList) {
List<? extends Model> computedValue = (List<? extends Model>) computeFormula(formula.getFormula(), jsonAttributes);
if (computedValue == null) {
continue;
}
Method setMappedByMethod = computeMappedByMethod(formula);
for (Model listElement : computedValue) {
setMappedByMethod.invoke(listElement, model);
JPA.save(listElement);
}
}
} catch (InvocationTargetException | IllegalAccessException | ClassNotFoundException e) {
throw new AxelorException(e, TraceBackRepository.CATEGORY_INCONSISTENCY);
}
}
use of com.axelor.apps.sale.db.ConfiguratorCreator in project axelor-open-suite by axelor.
the class ConfiguratorFormulaController method checkGroovyFormula.
/**
* Check the groovy script in the context
*
* @param request
* @param response
*/
public void checkGroovyFormula(ActionRequest request, ActionResponse response) {
ConfiguratorFormula configuratorFormula = request.getContext().asType(ConfiguratorFormula.class);
ConfiguratorCreator creator = request.getContext().getParent().asType(ConfiguratorCreator.class);
try {
Beans.get(ConfiguratorFormulaService.class).checkFormula(configuratorFormula, creator);
response.setAlert(I18n.get(IExceptionMessage.CONFIGURATOR_CREATOR_SCRIPT_WORKING));
} catch (Exception e) {
response.setError(e.getMessage());
}
}
Aggregations