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 });
}
}
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);
}
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;
}
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);
}
}
}
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);
}
}
Aggregations