use of com.axelor.apps.base.db.ProductCategory in project axelor-open-suite by axelor.
the class ProductCategoryServiceImpl method fetchParentCategoryList.
public List<ProductCategory> fetchParentCategoryList(ProductCategory productCategory) throws AxelorException {
// security in case of code error to avoid infinite loop
int i = 0;
List<ProductCategory> parentProductCategoryList = new ArrayList<>();
if (productCategory.getId() != null) {
productCategory = productCategoryRepository.find(productCategory.getId());
}
ProductCategory parentProductCategory = productCategory.getParentProductCategory();
while (parentProductCategory != null && i < MAX_ITERATION) {
if (parentProductCategoryList.contains(parentProductCategory) || parentProductCategory.equals(productCategory)) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PRODUCT_CATEGORY_PARENTS_CIRCULAR_DEPENDENCY), parentProductCategory.getCode());
}
parentProductCategoryList.add(parentProductCategory);
parentProductCategory = parentProductCategory.getParentProductCategory();
i++;
}
return parentProductCategoryList;
}
use of com.axelor.apps.base.db.ProductCategory in project axelor-open-suite by axelor.
the class ProductCategoryServiceImpl method fetchChildrenCategoryList.
public List<ProductCategory> fetchChildrenCategoryList(ProductCategory productCategory) throws AxelorException {
// security in case of code error to avoid infinite loop
int i = 0;
List<ProductCategory> descendantsProductCategoryList = new ArrayList<>();
if (productCategory.getId() == null) {
// if product category is not saved, then it cannot have children
return descendantsProductCategoryList;
}
List<ProductCategory> childrenProductCategoryList = fetchChildren(productCategory);
while (!childrenProductCategoryList.isEmpty() && i < MAX_ITERATION) {
List<ProductCategory> nextChildrenProductCategoryList = new ArrayList<>();
for (ProductCategory childProductCategory : childrenProductCategoryList) {
if (descendantsProductCategoryList.contains(childProductCategory) || childProductCategory.equals(productCategory)) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PRODUCT_CATEGORY_CHILDREN_CIRCULAR_DEPENDENCY), childProductCategory.getCode());
}
descendantsProductCategoryList.add(childProductCategory);
nextChildrenProductCategoryList.addAll(fetchChildren(childProductCategory));
}
childrenProductCategoryList.clear();
childrenProductCategoryList.addAll(nextChildrenProductCategoryList);
nextChildrenProductCategoryList.clear();
i++;
}
return descendantsProductCategoryList;
}
use of com.axelor.apps.base.db.ProductCategory in project axelor-open-suite by axelor.
the class ProductCategoryServiceSaleImpl method fetchImpactedChildrenProductCategories.
/**
* Fetch impacted children product categories on a category change. To find impacted product
* categories, we fetch children of given product category. If these children do not have a max
* discount, they are impacted and their own children can be impacted following the same pattern.
*
* @param productCategory a product category
* @return the computed list of children impacted by a max discount change in given category.
* @throws AxelorException if there is a configuration error
*/
protected List<ProductCategory> fetchImpactedChildrenProductCategories(ProductCategory productCategory) throws AxelorException {
// security in case of code error to avoid infinite loop
int i = 0;
List<ProductCategory> descendantsProductCategoryList = new ArrayList<>();
if (productCategory.getId() == null) {
// if product category is not saved, then it cannot have children
return descendantsProductCategoryList;
}
// product categories with max discounts are not be impacted
List<ProductCategory> childrenProductCategoryList = fetchChildrenWitNoMaxDiscount(productCategory);
while (!childrenProductCategoryList.isEmpty() && i < MAX_ITERATION) {
List<ProductCategory> nextChildrenProductCategoryList = new ArrayList<>();
for (ProductCategory childProductCategory : childrenProductCategoryList) {
if (descendantsProductCategoryList.contains(childProductCategory) || childProductCategory.equals(productCategory)) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PRODUCT_CATEGORY_CHILDREN_CIRCULAR_DEPENDENCY), childProductCategory.getCode());
}
descendantsProductCategoryList.add(childProductCategory);
nextChildrenProductCategoryList.addAll(fetchChildrenWitNoMaxDiscount(childProductCategory));
}
childrenProductCategoryList.clear();
childrenProductCategoryList.addAll(nextChildrenProductCategoryList);
nextChildrenProductCategoryList.clear();
i++;
}
return descendantsProductCategoryList;
}
use of com.axelor.apps.base.db.ProductCategory in project axelor-open-suite by axelor.
the class ProductCategoryController method filterParentCategory.
public void filterParentCategory(ActionRequest request, ActionResponse response) {
try {
ProductCategory productCategory = request.getContext().asType(ProductCategory.class);
String domain = Beans.get(ProductCategoryDomainCreatorService.class).createProductCategoryDomainFilteringChildren(productCategory);
response.setAttr("parentProductCategory", "domain", domain);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.base.db.ProductCategory in project axelor-open-suite by axelor.
the class ProductCategoryController method showExistingDiscounts.
/**
* Called from product category view on maxDiscount change. Call {@link
* ProductCategoryService#computeDiscountMessage(ProductCategory)}.
*
* @param request
* @param response
*/
public void showExistingDiscounts(ActionRequest request, ActionResponse response) {
try {
ProductCategory productCategory = request.getContext().asType(ProductCategory.class);
String discountsMessage = Beans.get(ProductCategoryService.class).computeDiscountMessage(productCategory);
if (!"".equals(discountsMessage)) {
response.setFlash(discountsMessage);
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations