Search in sources :

Example 6 with ConfiguratorCreator

use of com.axelor.apps.sale.db.ConfiguratorCreator in project axelor-open-suite by axelor.

the class ConfiguratorCreatorSaleRepository method copy.

@Override
public ConfiguratorCreator copy(ConfiguratorCreator entity, boolean deep) {
    ConfiguratorCreator copy = super.copy(entity, deep);
    copy.setCopyNeedingUpdate(true);
    copy.setName(copy.getName() + " (" + I18n.get(IExceptionMessage.COPY) + ")");
    return copy;
}
Also used : ConfiguratorCreator(com.axelor.apps.sale.db.ConfiguratorCreator)

Example 7 with ConfiguratorCreator

use of com.axelor.apps.sale.db.ConfiguratorCreator in project axelor-open-suite by axelor.

the class ConfiguratorServiceImpl method computeIndicatorValue.

/**
 * Compute the value of one indicator. Using the corresponding formula and the values in {@link
 * Configurator#attributes}
 *
 * @param configurator
 * @param indicatorName
 * @param jsonAttributes
 * @return
 */
protected Object computeIndicatorValue(Configurator configurator, String indicatorName, JsonContext jsonAttributes) {
    ConfiguratorCreator creator = configurator.getConfiguratorCreator();
    List<? extends ConfiguratorFormula> formulas;
    if (creator.getGenerateProduct()) {
        formulas = creator.getConfiguratorProductFormulaList();
    } else {
        formulas = creator.getConfiguratorSOLineFormulaList();
    }
    String groovyFormula = null;
    for (ConfiguratorFormula formula : formulas) {
        String fieldName = indicatorName;
        fieldName = fieldName.substring(0, fieldName.indexOf('_'));
        MetaField metaField = formula.getMetaField();
        if (metaField.getName().equals(fieldName)) {
            groovyFormula = formula.getFormula();
            break;
        }
    }
    if (groovyFormula == null || jsonAttributes == null) {
        return null;
    }
    return computeFormula(groovyFormula, jsonAttributes);
}
Also used : ConfiguratorCreator(com.axelor.apps.sale.db.ConfiguratorCreator) ConfiguratorFormula(com.axelor.apps.sale.db.ConfiguratorFormula) MetaField(com.axelor.meta.db.MetaField)

Example 8 with ConfiguratorCreator

use of com.axelor.apps.sale.db.ConfiguratorCreator in project axelor-open-suite by axelor.

the class ConfiguratorCreatorServiceImpl method getConfiguratorCreatorDomain.

public String getConfiguratorCreatorDomain() {
    User user = AuthUtils.getUser();
    Group group = user.getGroup();
    List<ConfiguratorCreator> configuratorCreatorList = configuratorCreatorRepo.all().filter("self.isActive = true").fetch();
    if (configuratorCreatorList == null || configuratorCreatorList.isEmpty()) {
        return "self.id in (0)";
    }
    configuratorCreatorList.removeIf(creator -> !creator.getAuthorizedUserSet().contains(user) && !creator.getAuthorizedGroupSet().contains(group));
    return "self.id in (" + StringTool.getIdListString(configuratorCreatorList) + ")";
}
Also used : Group(com.axelor.auth.db.Group) User(com.axelor.auth.db.User) ConfiguratorCreator(com.axelor.apps.sale.db.ConfiguratorCreator)

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