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;
}
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;
}
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);
}
}
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);
}
}
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);
}
Aggregations