Search in sources :

Example 1 with PriceListLine

use of com.axelor.apps.base.db.PriceListLine in project axelor-open-suite by axelor.

the class PriceListService method historizePriceList.

@Transactional
public PriceList historizePriceList(PriceList priceList) {
    PriceList historizedPriceList = priceListRepo.copy(priceList, false);
    historizedPriceList.setIsActive(false);
    List<PriceListLine> priceListLineList = priceList.getPriceListLineList();
    for (PriceListLine priceListLine : priceListLineList) {
        PriceListLine newPriceListLine = priceListLineRepo.copy(priceListLine, false);
        newPriceListLine.setPriceList(null);
        historizedPriceList.addPriceListLineListItem(newPriceListLine);
    }
    priceListRepo.save(historizedPriceList);
    priceList.addHistorizedPriceListItem(historizedPriceList);
    priceListRepo.save(priceList);
    return priceList;
}
Also used : PriceListLine(com.axelor.apps.base.db.PriceListLine) PriceList(com.axelor.apps.base.db.PriceList) Transactional(com.google.inject.persist.Transactional)

Example 2 with PriceListLine

use of com.axelor.apps.base.db.PriceListLine in project axelor-open-suite by axelor.

the class PriceListService method getPriceListLine.

public PriceListLine getPriceListLine(Product product, BigDecimal qty, PriceList priceList, BigDecimal price) {
    PriceListLine priceListLine = null;
    List<PriceListLine> priceListLineList = getPriceListLineList(product, qty, priceList);
    BigDecimal tempDiscountPrevious = null;
    BigDecimal tempDiscountCurrent;
    if (priceListLineList != null && !priceListLineList.isEmpty()) {
        if (priceListLineList.size() > 1) {
            for (PriceListLine tempPriceListLine : priceListLineList) {
                tempDiscountCurrent = this.getUnitPriceDiscounted(tempPriceListLine, price);
                if (tempDiscountPrevious == null || tempDiscountPrevious.compareTo(tempDiscountCurrent) > 0) {
                    tempDiscountPrevious = tempDiscountCurrent;
                    priceListLine = tempPriceListLine;
                }
            }
        } else {
            priceListLine = priceListLineList.get(0);
        }
    }
    return priceListLine;
}
Also used : PriceListLine(com.axelor.apps.base.db.PriceListLine) BigDecimal(java.math.BigDecimal)

Example 3 with PriceListLine

use of com.axelor.apps.base.db.PriceListLine in project axelor-open-suite by axelor.

the class TimesheetServiceImpl method createInvoiceLine.

@Override
public List<InvoiceLine> createInvoiceLine(Invoice invoice, Product product, User user, String date, BigDecimal hoursDuration, int priority, PriceList priceList) throws AxelorException {
    int discountMethodTypeSelect = PriceListLineRepository.TYPE_DISCOUNT;
    int discountTypeSelect = PriceListLineRepository.AMOUNT_TYPE_NONE;
    if (product == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_PRODUCT));
    }
    BigDecimal price = (BigDecimal) productCompanyService.get(product, "salePrice", invoice.getCompany());
    BigDecimal discountAmount = BigDecimal.ZERO;
    BigDecimal priceDiscounted = price;
    BigDecimal qtyConverted = Beans.get(UnitConversionService.class).convert(appHumanResourceService.getAppBase().getUnitHours(), (Unit) productCompanyService.get(product, "unit", invoice.getCompany()), hoursDuration, AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, product);
    if (priceList != null) {
        PriceListLine priceListLine = priceListService.getPriceListLine(product, qtyConverted, priceList, price);
        if (priceListLine != null) {
            discountMethodTypeSelect = priceListLine.getTypeSelect();
        }
        Map<String, Object> discounts = priceListService.getDiscounts(priceList, priceListLine, price);
        if (discounts != null) {
            discountAmount = (BigDecimal) discounts.get("discountAmount");
            discountTypeSelect = (int) discounts.get("discountTypeSelect");
            priceDiscounted = priceListService.computeDiscount(price, discountTypeSelect, discountAmount);
        }
        if ((appHumanResourceService.getAppBase().getComputeMethodDiscountSelect() == AppBaseRepository.INCLUDE_DISCOUNT_REPLACE_ONLY && discountMethodTypeSelect == PriceListLineRepository.TYPE_REPLACE) || appHumanResourceService.getAppBase().getComputeMethodDiscountSelect() == AppBaseRepository.INCLUDE_DISCOUNT) {
            discountTypeSelect = PriceListLineRepository.AMOUNT_TYPE_NONE;
            price = priceDiscounted;
        }
    }
    String description = user.getFullName();
    String productName = (String) productCompanyService.get(product, "name", invoice.getCompany());
    if (date != null) {
        productName += " " + "(" + date + ")";
    }
    InvoiceLineGenerator invoiceLineGenerator = new InvoiceLineGenerator(invoice, product, productName, price, price, priceDiscounted, description, qtyConverted, (Unit) productCompanyService.get(product, "unit", invoice.getCompany()), null, priority, discountAmount, discountTypeSelect, price.multiply(qtyConverted), null, false) {

        @Override
        public List<InvoiceLine> creates() throws AxelorException {
            InvoiceLine invoiceLine = this.createInvoiceLine();
            List<InvoiceLine> invoiceLines = new ArrayList<>();
            invoiceLines.add(invoiceLine);
            return invoiceLines;
        }
    };
    return invoiceLineGenerator.creates();
}
Also used : AxelorException(com.axelor.exception.AxelorException) UnitConversionService(com.axelor.apps.base.service.UnitConversionService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) PriceListLine(com.axelor.apps.base.db.PriceListLine) ArrayList(java.util.ArrayList) InvoiceLineGenerator(com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator) BigDecimal(java.math.BigDecimal)

Example 4 with PriceListLine

use of com.axelor.apps.base.db.PriceListLine in project axelor-open-suite by axelor.

the class SaleOrderLineServiceImpl method getDiscountsFromPriceLists.

@Override
public Map<String, Object> getDiscountsFromPriceLists(SaleOrder saleOrder, SaleOrderLine saleOrderLine, BigDecimal price) {
    Map<String, Object> discounts = null;
    PriceList priceList = saleOrder.getPriceList();
    if (priceList != null) {
        PriceListLine priceListLine = this.getPriceListLine(saleOrderLine, priceList, price);
        discounts = priceListService.getReplacedPriceAndDiscounts(priceList, priceListLine, price);
        if (saleOrder.getTemplate()) {
            Integer manualDiscountAmountType = saleOrderLine.getDiscountTypeSelect();
            BigDecimal manualDiscountAmount = saleOrderLine.getDiscountAmount();
            Integer priceListDiscountAmountType = (Integer) discounts.get("discountTypeSelect");
            BigDecimal priceListDiscountAmount = (BigDecimal) discounts.get("discountAmount");
            if (!manualDiscountAmountType.equals(priceListDiscountAmountType) && manualDiscountAmountType.equals(PriceListLineRepository.AMOUNT_TYPE_PERCENT) && priceListDiscountAmountType.equals(PriceListLineRepository.AMOUNT_TYPE_FIXED)) {
                priceListDiscountAmount = priceListDiscountAmount.multiply(new BigDecimal(100)).divide(price, 2, RoundingMode.HALF_UP);
            } else if (!manualDiscountAmountType.equals(priceListDiscountAmountType) && manualDiscountAmountType.equals(PriceListLineRepository.AMOUNT_TYPE_FIXED) && priceListDiscountAmountType.equals(PriceListLineRepository.AMOUNT_TYPE_PERCENT)) {
                priceListDiscountAmount = priceListDiscountAmount.multiply(price).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
            }
            if (manualDiscountAmount.compareTo(priceListDiscountAmount) > 0) {
                discounts.put("discountAmount", manualDiscountAmount);
                discounts.put("discountTypeSelect", manualDiscountAmountType);
            }
        }
    }
    return discounts;
}
Also used : PriceListLine(com.axelor.apps.base.db.PriceListLine) PriceList(com.axelor.apps.base.db.PriceList) BigDecimal(java.math.BigDecimal)

Example 5 with PriceListLine

use of com.axelor.apps.base.db.PriceListLine in project axelor-open-suite by axelor.

the class PurchaseOrderLineServiceImpl method getDiscountsFromPriceLists.

@Override
public Map<String, Object> getDiscountsFromPriceLists(PurchaseOrder purchaseOrder, PurchaseOrderLine purchaseOrderLine, BigDecimal price) {
    Map<String, Object> discounts = null;
    PriceList priceList = purchaseOrder.getPriceList();
    if (priceList != null) {
        PriceListLine priceListLine = this.getPriceListLine(purchaseOrderLine, priceList, price);
        discounts = priceListService.getReplacedPriceAndDiscounts(priceList, priceListLine, price);
    }
    return discounts;
}
Also used : PriceListLine(com.axelor.apps.base.db.PriceListLine) PriceList(com.axelor.apps.base.db.PriceList)

Aggregations

PriceListLine (com.axelor.apps.base.db.PriceListLine)10 PriceList (com.axelor.apps.base.db.PriceList)7 BigDecimal (java.math.BigDecimal)5 Company (com.axelor.apps.base.db.Company)3 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)2 InvoiceLineGenerator (com.axelor.apps.account.service.invoice.generator.InvoiceLineGenerator)2 Product (com.axelor.apps.base.db.Product)2 AxelorException (com.axelor.exception.AxelorException)2 ArrayList (java.util.ArrayList)2 PartnerPriceListService (com.axelor.apps.base.service.PartnerPriceListService)1 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)1 ProjectTask (com.axelor.apps.project.db.ProjectTask)1 InvoiceLineGeneratorSupplyChain (com.axelor.apps.supplychain.service.invoice.generator.InvoiceLineGeneratorSupplyChain)1 Transactional (com.google.inject.persist.Transactional)1 List (java.util.List)1