Search in sources :

Example 56 with Product

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

the class SaleOrderLineServiceImpl method computeMaxDiscount.

@Override
public BigDecimal computeMaxDiscount(SaleOrder saleOrder, SaleOrderLine saleOrderLine) throws AxelorException {
    Optional<BigDecimal> maxDiscount = Optional.empty();
    Product product = saleOrderLine.getProduct();
    if (product != null && product.getProductCategory() != null) {
        maxDiscount = productCategoryService.computeMaxDiscount(product.getProductCategory());
    }
    if (!maxDiscount.isPresent() || saleOrderLine.getDiscountTypeSelect() == PriceListLineRepository.AMOUNT_TYPE_NONE || saleOrder == null || (saleOrder.getStatusSelect() != SaleOrderRepository.STATUS_DRAFT_QUOTATION && (saleOrder.getStatusSelect() != SaleOrderRepository.STATUS_ORDER_CONFIRMED || !saleOrder.getOrderBeingEdited()))) {
        return null;
    } else {
        return maxDiscount.get();
    }
}
Also used : Product(com.axelor.apps.base.db.Product) ComplementaryProduct(com.axelor.apps.sale.db.ComplementaryProduct) BigDecimal(java.math.BigDecimal)

Example 57 with Product

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

the class SaleOrderLineServiceImpl method getUnitPriceFromPackLine.

/**
 * A method used to get the unit price of a sale order line from pack line, either in ati or wt
 *
 * @param saleOrder the sale order containing the sale order line
 * @param saleOrderLine
 * @param taxLine the tax applied to the unit price
 * @param resultInAti whether you want the result in ati or not
 * @return the unit price of the sale order line
 * @throws AxelorException
 */
protected BigDecimal getUnitPriceFromPackLine(SaleOrder saleOrder, SaleOrderLine saleOrderLine, TaxLine taxLine, boolean resultInAti) throws AxelorException {
    Product product = saleOrderLine.getProduct();
    Boolean productInAti = (Boolean) productCompanyService.get(product, "inAti", saleOrder.getCompany());
    BigDecimal productSalePrice = saleOrderLine.getPrice();
    BigDecimal price = (productInAti == resultInAti) ? productSalePrice : this.convertUnitPrice(productInAti, taxLine, productSalePrice);
    return currencyService.getAmountCurrencyConvertedAtDate((Currency) productCompanyService.get(product, "saleCurrency", saleOrder.getCompany()), saleOrder.getCurrency(), price, saleOrder.getCreationDate()).setScale(appSaleService.getNbDecimalDigitForUnitPrice(), RoundingMode.HALF_UP);
}
Also used : Currency(com.axelor.apps.base.db.Currency) Product(com.axelor.apps.base.db.Product) ComplementaryProduct(com.axelor.apps.sale.db.ComplementaryProduct) BigDecimal(java.math.BigDecimal)

Example 58 with Product

use of com.axelor.apps.base.db.Product 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 59 with Product

use of com.axelor.apps.base.db.Product 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)

Example 60 with Product

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

the class PurchaseProductController method fillShippingCoeff.

/**
 * Called from product form view, on {@link Product#defShipCoefByPartner} change. Call {@link
 * PurchaseProductService#getLastShippingCoef(Product)}.
 *
 * @param request
 * @param response
 */
public void fillShippingCoeff(ActionRequest request, ActionResponse response) {
    try {
        Product product = request.getContext().asType(Product.class);
        if (!product.getDefShipCoefByPartner()) {
            return;
        }
        response.setValue("shippingCoef", Beans.get(PurchaseProductService.class).getLastShippingCoef(product));
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Product(com.axelor.apps.base.db.Product)

Aggregations

Product (com.axelor.apps.base.db.Product)189 BigDecimal (java.math.BigDecimal)91 AxelorException (com.axelor.exception.AxelorException)70 Transactional (com.google.inject.persist.Transactional)45 ArrayList (java.util.ArrayList)38 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)33 Company (com.axelor.apps.base.db.Company)24 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)24 Unit (com.axelor.apps.base.db.Unit)23 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)23 HashMap (java.util.HashMap)20 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)19 StockLocation (com.axelor.apps.stock.db.StockLocation)19 List (java.util.List)19 ProdProduct (com.axelor.apps.production.db.ProdProduct)18 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)18 LocalDate (java.time.LocalDate)18 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)16 StockMove (com.axelor.apps.stock.db.StockMove)16 Map (java.util.Map)16