Search in sources :

Example 1 with ConfiguratorCreator

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);
    }
}
Also used : ConfiguratorCreator(com.axelor.apps.sale.db.ConfiguratorCreator) ConfiguratorCreatorService(com.axelor.apps.sale.service.configurator.ConfiguratorCreatorService)

Example 2 with ConfiguratorCreator

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);
    }
}
Also used : ConfiguratorCreator(com.axelor.apps.sale.db.ConfiguratorCreator) ConfiguratorCreatorService(com.axelor.apps.sale.service.configurator.ConfiguratorCreatorService)

Example 3 with ConfiguratorCreator

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);
    }
}
Also used : Arrays(java.util.Arrays) Inject(com.google.inject.Inject) Mapper(com.axelor.db.mapper.Mapper) ConfiguratorCreator(com.axelor.apps.sale.db.ConfiguratorCreator) Transactional(com.google.inject.persist.Transactional) AxelorException(com.axelor.exception.AxelorException) Files(com.google.common.io.Files) MetaJsonField(com.axelor.meta.db.MetaJsonField) Method(java.lang.reflect.Method) Path(java.nio.file.Path) XMLImporter(com.axelor.data.xml.XMLImporter) MetaFiles(com.axelor.meta.MetaFiles) IOUtil(org.apache.xmlbeans.impl.common.IOUtil) ConfiguratorFormula(com.axelor.apps.sale.db.ConfiguratorFormula) Model(com.axelor.db.Model) TraceBackService(com.axelor.exception.service.TraceBackService) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) FileInputStream(java.io.FileInputStream) Field(java.lang.reflect.Field) Listener(com.axelor.data.Listener) Collectors(java.util.stream.Collectors) File(java.io.File) List(java.util.List) InputStream(java.io.InputStream) MetaJsonField(com.axelor.meta.db.MetaJsonField) Field(java.lang.reflect.Field) Mapper(com.axelor.db.mapper.Mapper) Method(java.lang.reflect.Method) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException)

Example 4 with ConfiguratorCreator

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);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ConfiguratorCreator(com.axelor.apps.sale.db.ConfiguratorCreator) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) ConfiguratorFormula(com.axelor.apps.sale.db.ConfiguratorFormula) Model(com.axelor.db.Model) List(java.util.List)

Example 5 with ConfiguratorCreator

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());
    }
}
Also used : ConfiguratorCreator(com.axelor.apps.sale.db.ConfiguratorCreator) ConfiguratorFormula(com.axelor.apps.sale.db.ConfiguratorFormula) ConfiguratorFormulaService(com.axelor.apps.sale.service.configurator.ConfiguratorFormulaService)

Aggregations

ConfiguratorCreator (com.axelor.apps.sale.db.ConfiguratorCreator)8 ConfiguratorFormula (com.axelor.apps.sale.db.ConfiguratorFormula)4 ConfiguratorCreatorService (com.axelor.apps.sale.service.configurator.ConfiguratorCreatorService)2 Model (com.axelor.db.Model)2 AxelorException (com.axelor.exception.AxelorException)2 Method (java.lang.reflect.Method)2 List (java.util.List)2 ConfiguratorFormulaService (com.axelor.apps.sale.service.configurator.ConfiguratorFormulaService)1 Group (com.axelor.auth.db.Group)1 User (com.axelor.auth.db.User)1 Listener (com.axelor.data.Listener)1 XMLImporter (com.axelor.data.xml.XMLImporter)1 Mapper (com.axelor.db.mapper.Mapper)1 TraceBackService (com.axelor.exception.service.TraceBackService)1 MetaFiles (com.axelor.meta.MetaFiles)1 MetaField (com.axelor.meta.db.MetaField)1 MetaJsonField (com.axelor.meta.db.MetaJsonField)1 Files (com.google.common.io.Files)1 Inject (com.google.inject.Inject)1 Transactional (com.google.inject.persist.Transactional)1