Search in sources :

Example 1 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.

the class SaleOrderLineController method checkQty.

public void checkQty(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
    Beans.get(SaleOrderLineService.class).checkMultipleQty(saleOrderLine, response);
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLineService(com.axelor.apps.sale.service.saleorder.SaleOrderLineService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 2 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.

the class SaleOrderLineController method getDiscount.

public void getDiscount(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
    SaleOrderLineService saleOrderLineService = Beans.get(SaleOrderLineService.class);
    SaleOrder saleOrder = saleOrderLineService.getSaleOrder(context);
    if (saleOrder == null || saleOrderLine.getProduct() == null) {
        return;
    }
    try {
        Map<String, Object> discounts;
        if (saleOrderLine.getProduct().getInAti()) {
            discounts = saleOrderLineService.getDiscountsFromPriceLists(saleOrder, saleOrderLine, saleOrderLineService.getInTaxUnitPrice(saleOrder, saleOrderLine, saleOrderLine.getTaxLine()));
        } else {
            discounts = saleOrderLineService.getDiscountsFromPriceLists(saleOrder, saleOrderLine, saleOrderLineService.getExTaxUnitPrice(saleOrder, saleOrderLine, saleOrderLine.getTaxLine()));
        }
        if (discounts != null) {
            BigDecimal price = (BigDecimal) discounts.get("price");
            if (price != null && price.compareTo(saleOrderLine.getProduct().getInAti() ? saleOrderLine.getInTaxPrice() : saleOrderLine.getPrice()) != 0) {
                if (saleOrderLine.getProduct().getInAti()) {
                    response.setValue("inTaxPrice", price);
                    response.setValue("price", saleOrderLineService.convertUnitPrice(true, saleOrderLine.getTaxLine(), price));
                } else {
                    response.setValue("price", price);
                    response.setValue("inTaxPrice", saleOrderLineService.convertUnitPrice(false, saleOrderLine.getTaxLine(), price));
                }
            }
            if (saleOrderLine.getProduct().getInAti() != saleOrder.getInAti() && (Integer) discounts.get("discountTypeSelect") != PriceListLineRepository.AMOUNT_TYPE_PERCENT) {
                response.setValue("discountAmount", saleOrderLineService.convertUnitPrice(saleOrderLine.getProduct().getInAti(), saleOrderLine.getTaxLine(), (BigDecimal) discounts.get("discountAmount")));
            } else {
                response.setValue("discountAmount", discounts.get("discountAmount"));
            }
            response.setValue("discountTypeSelect", discounts.get("discountTypeSelect"));
        }
    } catch (Exception e) {
        response.setFlash(e.getMessage());
    }
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLineService(com.axelor.apps.sale.service.saleorder.SaleOrderLineService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

Example 3 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.

the class SaleOrderLineController method compute.

public void compute(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
    SaleOrder saleOrder = Beans.get(SaleOrderLineService.class).getSaleOrder(context);
    try {
        compute(response, saleOrder, saleOrderLine);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLineService(com.axelor.apps.sale.service.saleorder.SaleOrderLineService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) AxelorException(com.axelor.exception.AxelorException)

Example 4 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.

the class SaleOrderLineController method convertUnitPrice.

public void convertUnitPrice(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
    SaleOrder saleOrder = Beans.get(SaleOrderLineService.class).getSaleOrder(context);
    if (saleOrder == null || saleOrderLine.getProduct() == null || saleOrderLine.getPrice() == null || saleOrderLine.getInTaxPrice() == null) {
        return;
    }
    try {
        BigDecimal price = saleOrderLine.getPrice();
        BigDecimal inTaxPrice = price.add(price.multiply(saleOrderLine.getTaxLine().getValue()));
        response.setValue("inTaxPrice", inTaxPrice);
    } catch (Exception e) {
        response.setFlash(e.getMessage());
    }
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLineService(com.axelor.apps.sale.service.saleorder.SaleOrderLineService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

Example 5 with SaleOrderLine

use of com.axelor.apps.sale.db.SaleOrderLine in project axelor-open-suite by axelor.

the class SaleOrderLineController method updateInTaxPrice.

/**
 * Update the in. tax unit price of an invoice line from its ex. tax unit price.
 *
 * @param request
 * @param response
 */
public void updateInTaxPrice(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    SaleOrderLine saleOrderLine = context.asType(SaleOrderLine.class);
    try {
        BigDecimal exTaxPrice = saleOrderLine.getPrice();
        TaxLine taxLine = saleOrderLine.getTaxLine();
        response.setValue("inTaxPrice", Beans.get(SaleOrderLineService.class).convertUnitPrice(false, taxLine, exTaxPrice));
    } catch (Exception e) {
        response.setFlash(e.getMessage());
    }
}
Also used : Context(com.axelor.rpc.Context) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) TaxLine(com.axelor.apps.account.db.TaxLine)

Aggregations

SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)116 AxelorException (com.axelor.exception.AxelorException)41 BigDecimal (java.math.BigDecimal)39 SaleOrder (com.axelor.apps.sale.db.SaleOrder)33 ArrayList (java.util.ArrayList)24 Transactional (com.google.inject.persist.Transactional)23 Product (com.axelor.apps.base.db.Product)21 Context (com.axelor.rpc.Context)16 SaleOrderLineService (com.axelor.apps.sale.service.saleorder.SaleOrderLineService)14 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)9 Partner (com.axelor.apps.base.db.Partner)8 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)8 TaxLine (com.axelor.apps.account.db.TaxLine)7 Unit (com.axelor.apps.base.db.Unit)7 HashMap (java.util.HashMap)7 AnalyticMoveLine (com.axelor.apps.account.db.AnalyticMoveLine)6 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)6 SaleOrderLineRepository (com.axelor.apps.sale.db.repo.SaleOrderLineRepository)6 ReservedQtyService (com.axelor.apps.supplychain.service.ReservedQtyService)6 List (java.util.List)6