Search in sources :

Example 56 with SaleOrderLine

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

the class WorkflowVentilationServiceSupplychainImpl method saleOrderLineProcess.

private SaleOrder saleOrderLineProcess(Invoice invoice, InvoiceLine invoiceLine) throws AxelorException {
    SaleOrderLine saleOrderLine = invoiceLine.getSaleOrderLine();
    if (saleOrderLine == null) {
        return null;
    }
    SaleOrder saleOrder = saleOrderLine.getSaleOrder();
    // Update invoiced amount on sale order line
    BigDecimal invoicedAmountToAdd = invoiceLine.getExTaxTotal();
    // If is it a refund invoice, so we negate the amount invoiced
    if (InvoiceToolService.isRefund(invoiceLine.getInvoice())) {
        invoicedAmountToAdd = invoicedAmountToAdd.negate();
    }
    if (!invoice.getCurrency().equals(saleOrder.getCurrency()) && saleOrderLine.getCompanyExTaxTotal().compareTo(BigDecimal.ZERO) != 0) {
        // If the sale order currency is different from the invoice currency, use company currency to
        // calculate a rate. This rate will be applied to sale order line
        BigDecimal currentCompanyInvoicedAmount = invoiceLine.getCompanyExTaxTotal();
        BigDecimal rate = currentCompanyInvoicedAmount.divide(saleOrderLine.getCompanyExTaxTotal(), 4, RoundingMode.HALF_UP);
        invoicedAmountToAdd = rate.multiply(saleOrderLine.getExTaxTotal());
    }
    saleOrderLine.setAmountInvoiced(saleOrderLine.getAmountInvoiced().add(invoicedAmountToAdd));
    return saleOrder;
}
Also used : SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) SaleOrder(com.axelor.apps.sale.db.SaleOrder) BigDecimal(java.math.BigDecimal)

Example 57 with SaleOrderLine

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

the class IntercoServiceImpl method createIntercoSaleLineFromPurchaseLine.

/**
 * @param purchaseOrderLine the purchase order line needed to create the sale order line
 * @param saleOrder the sale order line belongs to this purchase order
 * @return the created purchase order line
 */
protected SaleOrderLine createIntercoSaleLineFromPurchaseLine(PurchaseOrderLine purchaseOrderLine, SaleOrder saleOrder) {
    SaleOrderLine saleOrderLine = new SaleOrderLine();
    saleOrderLine.setSaleOrder(saleOrder);
    saleOrderLine.setProduct(purchaseOrderLine.getProduct());
    saleOrderLine.setProductName(purchaseOrderLine.getProductName());
    saleOrderLine.setDescription(purchaseOrderLine.getDescription());
    saleOrderLine.setQty(purchaseOrderLine.getQty());
    saleOrderLine.setUnit(purchaseOrderLine.getUnit());
    // compute amount
    saleOrderLine.setPrice(purchaseOrderLine.getPrice());
    saleOrderLine.setInTaxPrice(purchaseOrderLine.getInTaxPrice());
    saleOrderLine.setExTaxTotal(purchaseOrderLine.getExTaxTotal());
    saleOrderLine.setDiscountTypeSelect(purchaseOrderLine.getDiscountTypeSelect());
    saleOrderLine.setDiscountAmount(purchaseOrderLine.getDiscountAmount());
    // compute price discounted
    BigDecimal priceDiscounted = Beans.get(SaleOrderLineService.class).computeDiscount(saleOrderLine, saleOrder.getInAti());
    saleOrderLine.setPriceDiscounted(priceDiscounted);
    // delivery
    saleOrderLine.setEstimatedDelivDate(purchaseOrderLine.getEstimatedDelivDate());
    // tax
    saleOrderLine.setTaxLine(purchaseOrderLine.getTaxLine());
    // analyticDistribution
    saleOrderLine = Beans.get(SaleOrderLineServiceSupplyChainImpl.class).getAndComputeAnalyticDistribution(saleOrderLine, saleOrder);
    for (AnalyticMoveLine obj : saleOrderLine.getAnalyticMoveLineList()) {
        obj.setSaleOrderLine(saleOrderLine);
    }
    saleOrder.addSaleOrderLineListItem(saleOrderLine);
    return saleOrderLine;
}
Also used : SaleOrderLineService(com.axelor.apps.sale.service.saleorder.SaleOrderLineService) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal) AnalyticMoveLine(com.axelor.apps.account.db.AnalyticMoveLine)

Example 58 with SaleOrderLine

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

the class ReservedQtyServiceImpl method updateReservedQty.

protected void updateReservedQty(StockLocationLine stockLocationLine, StockMoveLine stockMoveLine, BigDecimal newReservedQty) throws AxelorException {
    if (stockMoveLine.getProduct() == null || !stockMoveLine.getProduct().getStockManaged()) {
        return;
    }
    SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
    if (saleOrderLine != null) {
        updateReservedQty(saleOrderLine, newReservedQty);
    } else {
        checkBeforeUpdatingQties(stockMoveLine, newReservedQty);
        if (Beans.get(AppSupplychainService.class).getAppSupplychain().getBlockDeallocationOnAvailabilityRequest()) {
            checkAvailabilityRequest(stockMoveLine, newReservedQty, false);
        }
        if (stockMoveLine.getRequestedReservedQty().compareTo(newReservedQty) < 0 && newReservedQty.compareTo(BigDecimal.ZERO) > 0) {
            updateRequestedReservedQty(stockLocationLine, stockMoveLine, newReservedQty);
            requestQty(stockMoveLine);
        }
        BigDecimal availableQtyToBeReserved = stockLocationLine.getCurrentQty().subtract(stockLocationLine.getReservedQty());
        BigDecimal diffReservedQuantity = newReservedQty.subtract(stockMoveLine.getReservedQty());
        Product product = stockMoveLine.getProduct();
        BigDecimal diffReservedQuantityLocation = convertUnitWithProduct(stockMoveLine.getUnit(), stockLocationLine.getUnit(), diffReservedQuantity, product);
        if (availableQtyToBeReserved.compareTo(diffReservedQuantityLocation) < 0) {
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_QTY_NOT_AVAILABLE));
        }
        stockMoveLine.setReservedQty(newReservedQty);
        // update in stock location line
        updateReservedQty(stockLocationLine);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Product(com.axelor.apps.base.db.Product) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal)

Example 59 with SaleOrderLine

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

the class ReservedQtyServiceImpl method cancelReservation.

@Override
@Transactional(rollbackOn = { Exception.class })
public void cancelReservation(StockMoveLine stockMoveLine) throws AxelorException {
    if (stockMoveLine.getProduct() == null || !stockMoveLine.getProduct().getStockManaged()) {
        return;
    }
    SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
    if (saleOrderLine != null) {
        cancelReservation(saleOrderLine);
    } else {
        stockMoveLine.setIsQtyRequested(false);
        stockMoveLine.setReservationDateTime(null);
        this.updateRequestedReservedQty(stockMoveLine, BigDecimal.ZERO);
    }
}
Also used : SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Transactional(com.google.inject.persist.Transactional)

Example 60 with SaleOrderLine

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

the class ReservedQtyServiceImpl method updateRequestedQuantityInFromStockLocation.

@Override
public void updateRequestedQuantityInFromStockLocation(StockMoveLine stockMoveLine, StockLocation stockLocation, Product product, int toStatus, BigDecimal requestedReservedQty) throws AxelorException {
    if (product == null || !product.getStockManaged()) {
        return;
    }
    Unit stockMoveLineUnit = stockMoveLine.getUnit();
    StockLocationLine stockLocationLine = stockLocationLineService.getStockLocationLine(stockLocation, product);
    if (stockLocationLine == null) {
        return;
    }
    Unit stockLocationLineUnit = stockLocationLine.getUnit();
    // the quantity that will be allocated in stock location line
    BigDecimal realReservedQty;
    // the quantity that will be allocated in stock move line
    BigDecimal realReservedStockMoveQty;
    // if we cancel, subtract the quantity using the previously allocated quantity.
    if (toStatus == StockMoveRepository.STATUS_CANCELED || toStatus == StockMoveRepository.STATUS_REALIZED) {
        realReservedStockMoveQty = stockMoveLine.getReservedQty();
        // convert the quantity for stock location line
        realReservedQty = convertUnitWithProduct(stockMoveLineUnit, stockLocationLineUnit, realReservedStockMoveQty, stockMoveLine.getProduct());
        // reallocate quantity in other stock move lines
        if (isReallocatingQtyOnCancel(stockMoveLine)) {
            reallocateQty(stockMoveLine, stockLocation, stockLocationLine, product, realReservedQty);
        }
        // no more reserved qty in stock move and sale order lines
        updateReservedQuantityFromStockMoveLine(stockMoveLine, product, stockMoveLine.getReservedQty().negate());
        // update requested quantity in sale order line
        SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
        if (saleOrderLine != null) {
            // requested quantity should never be below delivered quantity.
            if (toStatus == StockMoveRepository.STATUS_REALIZED) {
                saleOrderLine.setRequestedReservedQty(saleOrderLine.getRequestedReservedQty().max(saleOrderLine.getDeliveredQty()));
            } else if (!saleOrderLine.getIsQtyRequested()) {
                // if we cancel and do not want to request quantity, the requested quantity become the new
                // delivered quantity.
                saleOrderLine.setRequestedReservedQty(saleOrderLine.getDeliveredQty());
            }
        }
    } else {
        BigDecimal requestedReservedQtyInLocation = convertUnitWithProduct(stockMoveLineUnit, stockLocationLine.getUnit(), requestedReservedQty, product);
        realReservedQty = computeRealReservedQty(stockLocationLine, requestedReservedQtyInLocation);
        // convert back the quantity for the stock move line
        realReservedStockMoveQty = convertUnitWithProduct(stockLocationLineUnit, stockMoveLineUnit, realReservedQty, stockMoveLine.getProduct());
        updateReservedQuantityFromStockMoveLine(stockMoveLine, product, realReservedStockMoveQty);
        // reallocate quantity in other stock move lines
        if (supplychainConfigService.getSupplyChainConfig(stockLocation.getCompany()).getAutoAllocateOnAllocation()) {
            BigDecimal availableQuantityInLocation = stockLocationLine.getCurrentQty().subtract(stockLocationLine.getReservedQty());
            availableQuantityInLocation = convertUnitWithProduct(stockLocationLineUnit, stockMoveLineUnit, availableQuantityInLocation, product);
            BigDecimal qtyRemainingToAllocate = availableQuantityInLocation.subtract(realReservedStockMoveQty);
            reallocateQty(stockMoveLine, stockLocation, stockLocationLine, product, qtyRemainingToAllocate);
        }
    }
    updateReservedQty(stockLocationLine);
    updateRequestedReservedQty(stockLocationLine);
    checkReservedQtyStocks(stockLocationLine, stockMoveLine, toStatus);
}
Also used : StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Unit(com.axelor.apps.base.db.Unit) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal)

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