Search in sources :

Example 6 with MetaField

use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.

the class ReportBuilderService method processPanelRelated.

/**
 * Process panelRelated and update 'panels' or 'sidePanels' list with new table created for
 * panelRelated.
 *
 * @param panelRelated PanelRelated to process.
 * @param sidePanel Boolean to check if panelRelated is sidePanel.
 * @param colSpan Colspan to add in panel lists.
 */
public void processPanelRelated(PanelRelated panelRelated, Boolean sidePanel, String colSpan) {
    String title = panelRelated.getTitle();
    String name = panelRelated.getName();
    MetaField metaField = getMetaField(name, model);
    if (Strings.isNullOrEmpty(title) && metaField != null) {
        title = metaField.getLabel();
    }
    if (Strings.isNullOrEmpty(title)) {
        title = inflector.humanize(name);
    }
    String field = "<td colSpan=\"2\"><h4>" + title + "</h4></td>";
    String refModel = getRefModel(metaField.getTypeName());
    String itemTable = createTable(panelRelated, refModel);
    if (sidePanel != null && sidePanel) {
        sidePanels.add(new String[] { "12", field });
        sidePanels.add(new String[] { "12", itemTable });
    } else {
        panels.add(new String[] { colSpan, field });
        panels.add(new String[] { colSpan, itemTable });
    }
}
Also used : MetaField(com.axelor.meta.db.MetaField)

Example 7 with MetaField

use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.

the class WeightedAveragePriceServiceImpl method computeAvgPriceForProduct.

@Override
@Transactional
public void computeAvgPriceForProduct(Product product) throws AxelorException {
    Boolean avgPriceHandledByCompany = false;
    Set<MetaField> companySpecificFields = appBaseService.getAppBase().getCompanySpecificProductFieldsSet();
    for (MetaField field : companySpecificFields) {
        if (field.getName().equals("avgPrice")) {
            avgPriceHandledByCompany = true;
            break;
        }
    }
    if (avgPriceHandledByCompany && product.getProductCompanyList() != null && !product.getProductCompanyList().isEmpty()) {
        for (ProductCompany productCompany : product.getProductCompanyList()) {
            Company company = productCompany.getCompany();
            BigDecimal productAvgPrice = this.computeAvgPriceForCompany(product, company);
            if (productAvgPrice.compareTo(BigDecimal.ZERO) == 0) {
                continue;
            }
            productCompanyService.set(product, "avgPrice", productAvgPrice, company);
            if ((Integer) productCompanyService.get(product, "costTypeSelect", company) == ProductRepository.COST_TYPE_AVERAGE_PRICE) {
                productCompanyService.set(product, "costPrice", productAvgPrice, company);
                if ((Boolean) productCompanyService.get(product, "autoUpdateSalePrice", company)) {
                    Beans.get(ProductService.class).updateSalePrice(product, company);
                }
            }
        }
    } else {
        BigDecimal productAvgPrice = this.computeAvgPriceForCompany(product, null);
        if (productAvgPrice.compareTo(BigDecimal.ZERO) == 0) {
            return;
        }
        product.setAvgPrice(productAvgPrice);
        if (product.getCostTypeSelect() == ProductRepository.COST_TYPE_AVERAGE_PRICE) {
            product.setCostPrice(productAvgPrice);
            if (product.getAutoUpdateSalePrice()) {
                Beans.get(ProductService.class).updateSalePrice(product, null);
            }
        }
    }
    productRepo.save(product);
}
Also used : Company(com.axelor.apps.base.db.Company) ProductCompany(com.axelor.apps.base.db.ProductCompany) MetaField(com.axelor.meta.db.MetaField) ProductService(com.axelor.apps.base.service.ProductService) ProductCompany(com.axelor.apps.base.db.ProductCompany) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 8 with MetaField

use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.

the class PermissionAssistantService method writePermission.

private int writePermission(MetaModel object, MetaField userField, String[] row, int colIndex, String permName) {
    Permission perm = permissionRepository.findByName(permName);
    if (perm != null && perm.getObject().equals(object.getFullName())) {
        row[colIndex++] = !perm.getCanRead() ? "" : "x";
        row[colIndex++] = !perm.getCanWrite() ? "" : "x";
        row[colIndex++] = !perm.getCanCreate() ? "" : "x";
        row[colIndex++] = !perm.getCanRemove() ? "" : "x";
        row[colIndex++] = !perm.getCanExport() ? "" : "x";
        row[colIndex++] = Strings.isNullOrEmpty(perm.getCondition()) ? "" : perm.getCondition();
        row[colIndex++] = Strings.isNullOrEmpty(perm.getConditionParams()) ? "" : perm.getConditionParams();
        // readonly if
        row[colIndex++] = "";
        // hide if
        row[colIndex++] = "";
    } else if (userField != null) {
        MetaField objectField = fieldRepository.all().filter("self.typeName = ?1 and self.metaModel = ?2 and self.relationship = 'ManyToOne'", userField.getTypeName(), object).fetchOne();
        if (objectField != null) {
            String condition = "";
            String conditionParams = "__user__." + userField.getName();
            if (userField.getRelationship().contentEquals("ManyToOne")) {
                condition = "self." + objectField.getName() + " = ?";
            } else {
                condition = "self." + objectField.getName() + " in (?)";
            }
            row[colIndex++] = "x";
            row[colIndex++] = "x";
            row[colIndex++] = "x";
            row[colIndex++] = "x";
            row[colIndex++] = "x";
            row[colIndex++] = condition;
            row[colIndex++] = conditionParams;
            // readonly if
            row[colIndex++] = "";
            // hide if
            row[colIndex++] = "";
        }
    }
    return colIndex;
}
Also used : MetaField(com.axelor.meta.db.MetaField) MetaPermission(com.axelor.meta.db.MetaPermission) Permission(com.axelor.auth.db.Permission)

Example 9 with MetaField

use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.

the class PermissionAssistantService method writeObject.

private void writeObject(CSVWriter csvWriter, PermissionAssistant assistant, Integer size, ResourceBundle bundle) {
    MetaField userField = assistant.getMetaField();
    for (MetaModel object : assistant.getObjectSet()) {
        int colIndex = header.size() + 1;
        String[] row = new String[size];
        row[0] = object.getFullName();
        if (assistant.getTypeSelect() == PermissionAssistantRepository.TYPE_GROUPS) {
            for (Group group : assistant.getGroupSet()) {
                String permName = getPermissionName(userField, object.getName(), group.getCode());
                colIndex = writePermission(object, userField, row, colIndex, permName);
                colIndex++;
            }
        } else if (assistant.getTypeSelect() == PermissionAssistantRepository.TYPE_ROLES) {
            for (Role role : assistant.getRoleSet()) {
                String permName = getPermissionName(userField, object.getName(), role.getName());
                colIndex = writePermission(object, userField, row, colIndex, permName);
                colIndex++;
            }
        }
        csvWriter.writeNext(row);
        if (!assistant.getFieldPermission()) {
            continue;
        }
        List<MetaField> fieldList = object.getMetaFields();
        Collections.sort(fieldList, compareField());
        for (MetaField field : fieldList) {
            colIndex = header.size() + 1;
            row = new String[size];
            row[1] = field.getName();
            row[2] = getFieldTitle(field, bundle);
            if (assistant.getTypeSelect() == PermissionAssistantRepository.TYPE_GROUPS) {
                for (Group group : assistant.getGroupSet()) {
                    String permName = getPermissionName(null, object.getName(), group.getCode());
                    colIndex = writeFieldPermission(field, row, colIndex, permName);
                    colIndex++;
                }
            } else if (assistant.getTypeSelect() == PermissionAssistantRepository.TYPE_ROLES) {
                for (Role role : assistant.getRoleSet()) {
                    String permName = getPermissionName(null, object.getName(), role.getName());
                    colIndex = writeFieldPermission(field, row, colIndex, permName);
                    colIndex++;
                }
            }
            csvWriter.writeNext(row);
        }
    }
}
Also used : Role(com.axelor.auth.db.Role) Group(com.axelor.auth.db.Group) MetaModel(com.axelor.meta.db.MetaModel) MetaField(com.axelor.meta.db.MetaField)

Example 10 with MetaField

use of com.axelor.meta.db.MetaField in project axelor-open-suite by axelor.

the class PermissionAssistantController method fillObjects.

public void fillObjects(ActionRequest request, ActionResponse response) {
    try {
        PermissionAssistant assistant = request.getContext().asType(PermissionAssistant.class);
        MetaField metaField = assistant.getMetaField();
        if (metaField != null && (assistant.getObjectSet() == null || assistant.getObjectSet().isEmpty())) {
            List<MetaModel> models = Beans.get(MetaModelRepository.class).all().filter("self.metaFields.relationship = 'ManyToOne'" + " and self.metaFields.typeName = ?1", metaField.getTypeName()).fetch();
            Set<MetaModel> objectSet = new HashSet<>();
            objectSet.addAll(models);
            response.setValue("objectSet", objectSet);
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : MetaModel(com.axelor.meta.db.MetaModel) MetaModelRepository(com.axelor.meta.db.repo.MetaModelRepository) MetaField(com.axelor.meta.db.MetaField) PermissionAssistant(com.axelor.auth.db.PermissionAssistant) HashSet(java.util.HashSet)

Aggregations

MetaField (com.axelor.meta.db.MetaField)45 MetaJsonField (com.axelor.meta.db.MetaJsonField)15 MetaModel (com.axelor.meta.db.MetaModel)10 Mapper (com.axelor.db.mapper.Mapper)9 AxelorException (com.axelor.exception.AxelorException)8 ArrayList (java.util.ArrayList)6 Property (com.axelor.db.mapper.Property)5 Filter (com.axelor.studio.db.Filter)4 Model (com.axelor.db.Model)3 MetaFieldRepository (com.axelor.meta.db.repo.MetaFieldRepository)3 MetaModelRepository (com.axelor.meta.db.repo.MetaModelRepository)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Company (com.axelor.apps.base.db.Company)2 FileField (com.axelor.apps.base.db.FileField)2 ProductCompany (com.axelor.apps.base.db.ProductCompany)2 Context (com.axelor.rpc.Context)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Transactional (com.google.inject.persist.Transactional)2 BigInteger (java.math.BigInteger)2