use of com.axelor.apps.base.db.ProductCategory in project axelor-open-suite by axelor.
the class ProductCategoryServiceImpl method computeDiscountMessage.
@Override
public String computeDiscountMessage(ProductCategory productCategory) throws AxelorException {
BigDecimal maxDiscount = productCategory.getMaxDiscount();
if (maxDiscount.signum() <= 0) {
// field is empty: no messages required
return "";
}
List<ProductCategory> parentCategories = fetchParentCategoryListWithMaxDiscount(productCategory);
List<ProductCategory> childrenCategories = fetchChildrenCategoryListWithMaxDiscount(productCategory);
StringBuilder discountMessage = new StringBuilder();
if (!parentCategories.isEmpty() || !childrenCategories.isEmpty()) {
discountMessage.append(I18n.get("This maximal discount"));
discountMessage.append(" ");
}
if (!parentCategories.isEmpty()) {
discountMessage.append(I18n.get("will override discounts applied to parents categories"));
discountMessage.append(" ");
discountMessage.append(parentCategories.stream().map(pc -> String.format("%s (%s%%)", pc.getCode(), pc.getMaxDiscount())).collect(Collectors.joining(", ")));
if (!childrenCategories.isEmpty()) {
discountMessage.append(" ");
discountMessage.append(I18n.get("and"));
discountMessage.append(" ");
}
}
if (!childrenCategories.isEmpty()) {
discountMessage.append(I18n.get("will not be applied to following children categories"));
discountMessage.append(" ");
discountMessage.append(childrenCategories.stream().map(pc -> String.format("%s (%s%%)", pc.getCode(), pc.getMaxDiscount())).collect(Collectors.joining(", ")));
}
return discountMessage.toString();
}
use of com.axelor.apps.base.db.ProductCategory in project axelor-open-suite by axelor.
the class ProductCategoryServiceSaleImpl method hasDiscountBecameTooHigh.
protected boolean hasDiscountBecameTooHigh(ProductCategory productCategory, SaleOrderLine saleOrderLine) {
ProductCategory productCategoryIt = productCategory;
BigDecimal maxDiscount = productCategory.getMaxDiscount();
while (maxDiscount.signum() == 0 && productCategoryIt.getParentProductCategory() != null) {
productCategoryIt = productCategory.getParentProductCategory();
maxDiscount = productCategoryIt.getMaxDiscount();
}
if (maxDiscount.signum() == 0) {
return false;
}
// compute discount percent in sale order line
BigDecimal saleOrderLineDiscount;
switch(saleOrderLine.getDiscountTypeSelect()) {
case PriceListLineRepository.AMOUNT_TYPE_PERCENT:
saleOrderLineDiscount = saleOrderLine.getDiscountAmount();
break;
case PriceListLineRepository.AMOUNT_TYPE_FIXED:
saleOrderLineDiscount = saleOrderLine.getPrice().signum() != 0 ? saleOrderLine.getDiscountAmount().multiply(new BigDecimal("100")).divide(saleOrderLine.getPrice(), 2, RoundingMode.HALF_UP) : BigDecimal.ZERO;
break;
case PriceListLineRepository.AMOUNT_TYPE_NONE:
default:
saleOrderLineDiscount = BigDecimal.ZERO;
break;
}
return saleOrderLineDiscount.compareTo(maxDiscount) > 0;
}
Aggregations