Search in sources :

Example 11 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class PurchaseOrderLineController method updateProductInformation.

public void updateProductInformation(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
    PurchaseOrder purchaseOrder = this.getPurchaseOrder(context);
    if (purchaseOrder == null || purchaseOrderLine.getProduct() == null) {
        return;
    }
    try {
        PurchaseOrderLineService purchaseOrderLineService = Beans.get(PurchaseOrderLineService.class);
        BigDecimal price = purchaseOrderLine.getProduct().getInAti() ? purchaseOrderLineService.getInTaxUnitPrice(purchaseOrder, purchaseOrderLine, purchaseOrderLine.getTaxLine()) : purchaseOrderLineService.getExTaxUnitPrice(purchaseOrder, purchaseOrderLine, purchaseOrderLine.getTaxLine());
        Map<String, Object> catalogInfo = purchaseOrderLineService.updateInfoFromCatalog(purchaseOrder, purchaseOrderLine);
        Product product = purchaseOrderLine.getProduct();
        String productName = null;
        String productCode = null;
        ProductCompanyService productCompanyService = Beans.get(ProductCompanyService.class);
        if (catalogInfo != null) {
            if (catalogInfo.get("price") != null) {
                price = (BigDecimal) catalogInfo.get("price");
            }
            productName = catalogInfo.get("productName") != null ? (String) catalogInfo.get("productName") : (String) productCompanyService.get(product, "name", purchaseOrder.getCompany());
            productCode = catalogInfo.get("productCode") != null ? (String) catalogInfo.get("productCode") : (String) productCompanyService.get(product, "code", purchaseOrder.getCompany());
        } else {
            productName = (String) productCompanyService.get(product, "name", purchaseOrder.getCompany());
            productCode = (String) productCompanyService.get(product, "code", purchaseOrder.getCompany());
        }
        if (purchaseOrderLine.getProductName() == null) {
            response.setValue("productName", productName);
        }
        if (purchaseOrderLine.getProductCode() == null) {
            response.setValue("productCode", productCode);
        }
        Map<String, Object> discounts = purchaseOrderLineService.getDiscountsFromPriceLists(purchaseOrder, purchaseOrderLine, price);
        if (discounts != null) {
            if (discounts.get("price") != null) {
                price = (BigDecimal) discounts.get("price");
            }
            if (purchaseOrderLine.getProduct().getInAti() != purchaseOrder.getInAti() && (Integer) discounts.get("discountTypeSelect") != PriceListLineRepository.AMOUNT_TYPE_PERCENT) {
                response.setValue("discountAmount", purchaseOrderLineService.convertUnitPrice(purchaseOrderLine.getProduct().getInAti(), purchaseOrderLine.getTaxLine(), (BigDecimal) discounts.get("discountAmount")));
            } else {
                response.setValue("discountAmount", discounts.get("discountAmount"));
            }
            response.setValue("discountTypeSelect", discounts.get("discountTypeSelect"));
        }
        if (price.compareTo(purchaseOrderLine.getProduct().getInAti() ? purchaseOrderLine.getInTaxPrice() : purchaseOrderLine.getPrice()) != 0) {
            if (purchaseOrderLine.getProduct().getInAti()) {
                response.setValue("inTaxPrice", price);
                response.setValue("price", purchaseOrderLineService.convertUnitPrice(true, purchaseOrderLine.getTaxLine(), price));
            } else {
                response.setValue("price", price);
                response.setValue("inTaxPrice", purchaseOrderLineService.convertUnitPrice(false, purchaseOrderLine.getTaxLine(), price));
            }
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) ProductCompanyService(com.axelor.apps.base.service.ProductCompanyService) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) Product(com.axelor.apps.base.db.Product) PurchaseOrderLineService(com.axelor.apps.purchase.service.PurchaseOrderLineService) BigDecimal(java.math.BigDecimal)

Example 12 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class PurchaseOrderLineController 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();
    PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
    try {
        BigDecimal exTaxPrice = purchaseOrderLine.getPrice();
        TaxLine taxLine = purchaseOrderLine.getTaxLine();
        response.setValue("inTaxPrice", Beans.get(PurchaseOrderLineService.class).convertUnitPrice(false, taxLine, exTaxPrice));
    } catch (Exception e) {
        response.setFlash(e.getMessage());
    }
}
Also used : Context(com.axelor.rpc.Context) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 13 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class PurchaseOrderLineController method updatePrice.

/**
 * Update the ex. tax unit price of an invoice line from its in. tax unit price.
 *
 * @param request
 * @param response
 */
public void updatePrice(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
    try {
        BigDecimal inTaxPrice = purchaseOrderLine.getInTaxPrice();
        TaxLine taxLine = purchaseOrderLine.getTaxLine();
        response.setValue("price", Beans.get(PurchaseOrderLineService.class).convertUnitPrice(true, taxLine, inTaxPrice));
    } catch (Exception e) {
        response.setFlash(e.getMessage());
    }
}
Also used : Context(com.axelor.rpc.Context) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) BigDecimal(java.math.BigDecimal) TaxLine(com.axelor.apps.account.db.TaxLine)

Example 14 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class PurchaseOrderLineController method convertUnitPrice.

public void convertUnitPrice(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
    PurchaseOrder purchaseOrder = this.getPurchaseOrder(context);
    if (purchaseOrder == null || purchaseOrderLine.getProduct() == null || purchaseOrderLine.getPrice() == null || purchaseOrderLine.getInTaxPrice() == null || purchaseOrderLine.getTaxLine() == null) {
        return;
    }
    try {
        BigDecimal price = purchaseOrderLine.getPrice();
        BigDecimal inTaxPrice = price.add(price.multiply(purchaseOrderLine.getTaxLine().getValue()));
        response.setValue("inTaxPrice", inTaxPrice);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) BigDecimal(java.math.BigDecimal)

Example 15 with PurchaseOrderLine

use of com.axelor.apps.purchase.db.PurchaseOrderLine in project axelor-open-suite by axelor.

the class PurchaseOrderLineController method getProductInformation.

public void getProductInformation(ActionRequest request, ActionResponse response) {
    try {
        PurchaseOrderLineService service = Beans.get(PurchaseOrderLineService.class);
        Context context = request.getContext();
        PurchaseOrderLine purchaseOrderLine = context.asType(PurchaseOrderLine.class);
        PurchaseOrder purchaseOrder = this.getPurchaseOrder(context);
        Product product = purchaseOrderLine.getProduct();
        this.resetProductInformation(response);
        response.setValues(service.reset(purchaseOrderLine));
        if (purchaseOrder == null || product == null) {
            return;
        }
        purchaseOrderLine.setPurchaseOrder(purchaseOrder);
        service.fill(purchaseOrderLine, purchaseOrder);
        response.setValues(purchaseOrderLine);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) Product(com.axelor.apps.base.db.Product) PurchaseOrderLineService(com.axelor.apps.purchase.service.PurchaseOrderLineService)

Aggregations

PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)76 BigDecimal (java.math.BigDecimal)28 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)26 Transactional (com.google.inject.persist.Transactional)18 Product (com.axelor.apps.base.db.Product)14 ArrayList (java.util.ArrayList)13 AxelorException (com.axelor.exception.AxelorException)11 Context (com.axelor.rpc.Context)10 Company (com.axelor.apps.base.db.Company)9 Unit (com.axelor.apps.base.db.Unit)9 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)9 PurchaseOrderLineService (com.axelor.apps.purchase.service.PurchaseOrderLineService)8 LocalDate (java.time.LocalDate)8 Partner (com.axelor.apps.base.db.Partner)7 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)7 HashMap (java.util.HashMap)7 BudgetDistribution (com.axelor.apps.account.db.BudgetDistribution)5 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)5 TaxLine (com.axelor.apps.account.db.TaxLine)5 List (java.util.List)5