Search in sources :

Example 86 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class StockMoveServiceSupplychainImpl method updateSaleOrderLinesDeliveryState.

protected void updateSaleOrderLinesDeliveryState(StockMove stockMove, boolean qtyWasDelivered) throws AxelorException {
    for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
        if (stockMoveLine.getSaleOrderLine() != null) {
            SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
            BigDecimal realQty = unitConversionService.convert(stockMoveLine.getUnit(), saleOrderLine.getUnit(), stockMoveLine.getRealQty(), stockMoveLine.getRealQty().scale(), saleOrderLine.getProduct());
            if (stockMove.getTypeSelect() != StockMoveRepository.TYPE_INTERNAL) {
                if (qtyWasDelivered) {
                    saleOrderLine.setDeliveredQty(saleOrderLine.getDeliveredQty().add(realQty));
                } else {
                    saleOrderLine.setDeliveredQty(saleOrderLine.getDeliveredQty().subtract(realQty));
                }
            }
            if (saleOrderLine.getDeliveredQty().signum() == 0) {
                saleOrderLine.setDeliveryState(SaleOrderLineRepository.DELIVERY_STATE_NOT_DELIVERED);
            } else if (saleOrderLine.getDeliveredQty().compareTo(saleOrderLine.getQty()) < 0) {
                saleOrderLine.setDeliveryState(SaleOrderLineRepository.DELIVERY_STATE_PARTIALLY_DELIVERED);
            } else {
                saleOrderLine.setDeliveryState(SaleOrderLineRepository.DELIVERY_STATE_DELIVERED);
            }
        }
    }
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal)

Example 87 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class StockMoveServiceSupplychainImpl method createSplitStockMoveLine.

@Override
protected StockMoveLine createSplitStockMoveLine(StockMove originalStockMove, StockMoveLine originalStockMoveLine, StockMoveLine modifiedStockMoveLine) {
    StockMoveLine newStockMoveLine = super.createSplitStockMoveLine(originalStockMove, originalStockMoveLine, modifiedStockMoveLine);
    if (originalStockMoveLine.getQty().compareTo(originalStockMoveLine.getRequestedReservedQty()) < 0) {
        newStockMoveLine.setRequestedReservedQty(originalStockMoveLine.getRequestedReservedQty().subtract(originalStockMoveLine.getQty()));
        originalStockMoveLine.setRequestedReservedQty(originalStockMoveLine.getQty());
    }
    newStockMoveLine.setPurchaseOrderLine(originalStockMoveLine.getPurchaseOrderLine());
    newStockMoveLine.setSaleOrderLine(originalStockMoveLine.getSaleOrderLine());
    return newStockMoveLine;
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine)

Example 88 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class StockMoveServiceSupplychainImpl method isAllocatedStockMoveLineRemoved.

@Override
public boolean isAllocatedStockMoveLineRemoved(StockMove stockMove) {
    StockMove storedStockMove = Beans.get(StockMoveRepository.class).find(stockMove.getId());
    Boolean isAllocatedStockMoveLineRemoved = false;
    if (ObjectUtils.notEmpty(storedStockMove)) {
        List<StockMoveLine> stockMoveLineList = stockMove.getStockMoveLineList();
        List<StockMoveLine> storedStockMoveLineList = storedStockMove.getStockMoveLineList();
        if (stockMoveLineList != null && storedStockMoveLineList != null) {
            for (StockMoveLine stockMoveLine : storedStockMoveLineList) {
                if (Beans.get(StockMoveLineServiceSupplychain.class).isAllocatedStockMoveLine(stockMoveLine) && !stockMoveLineList.contains(stockMoveLine)) {
                    stockMoveLineList.add(stockMoveLine);
                    isAllocatedStockMoveLineRemoved = true;
                }
                if (isAllocatedStockMoveLineRemoved) {
                    stockMove.setStockMoveLineList(stockMoveLineList);
                }
            }
        }
    }
    return isAllocatedStockMoveLineRemoved;
}
Also used : StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine)

Example 89 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class StockMoveLineServiceSupplychainImpl method getMergedStockMoveLine.

@Override
public StockMoveLine getMergedStockMoveLine(List<StockMoveLine> stockMoveLineList) throws AxelorException {
    if (stockMoveLineList == null || stockMoveLineList.isEmpty()) {
        return null;
    }
    if (stockMoveLineList.size() == 1) {
        return stockMoveLineList.get(0);
    }
    StockMove stockMove = stockMoveLineList.get(0).getStockMove();
    SaleOrderLine saleOrderLine = stockMoveLineList.get(0).getSaleOrderLine();
    PurchaseOrderLine purchaseOrderLine = stockMoveLineList.get(0).getPurchaseOrderLine();
    Product product;
    String productName;
    String description;
    BigDecimal quantity = BigDecimal.ZERO;
    Unit unit;
    if (saleOrderLine != null) {
        product = saleOrderLine.getProduct();
        productName = saleOrderLine.getProductName();
        description = saleOrderLine.getDescription();
        unit = saleOrderLine.getUnit();
    } else if (purchaseOrderLine != null) {
        product = purchaseOrderLine.getProduct();
        productName = purchaseOrderLine.getProductName();
        description = purchaseOrderLine.getDescription();
        unit = purchaseOrderLine.getUnit();
    } else {
        // shouldn't ever happen or you misused this function
        return null;
    }
    for (StockMoveLine stockMoveLine : stockMoveLineList) {
        quantity = quantity.add(stockMoveLine.getRealQty());
    }
    StockMoveLine generatedStockMoveLine = createStockMoveLine(product, productName, description, quantity, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, BigDecimal.ZERO, unit, stockMove, null);
    generatedStockMoveLine.setSaleOrderLine(saleOrderLine);
    generatedStockMoveLine.setPurchaseOrderLine(purchaseOrderLine);
    generatedStockMoveLine.setIsMergedStockMoveLine(true);
    return generatedStockMoveLine;
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) StockMove(com.axelor.apps.stock.db.StockMove) Product(com.axelor.apps.base.db.Product) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 90 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class StockMoveLineServiceSupplychainImpl method splitStockMoveLine.

@Override
public StockMoveLine splitStockMoveLine(StockMoveLine stockMoveLine, BigDecimal qty, TrackingNumber trackingNumber) throws AxelorException {
    StockMoveLine newStockMoveLine = super.splitStockMoveLine(stockMoveLine, qty, trackingNumber);
    if (!Beans.get(AppBaseService.class).isApp("supplychain")) {
        return newStockMoveLine;
    }
    BigDecimal reservedQtyAfterSplit = BigDecimal.ZERO.max(stockMoveLine.getRequestedReservedQty().subtract(qty));
    BigDecimal reservedQtyInNewLine = stockMoveLine.getRequestedReservedQty().min(qty);
    stockMoveLine.setRequestedReservedQty(reservedQtyAfterSplit);
    newStockMoveLine.setRequestedReservedQty(reservedQtyInNewLine);
    newStockMoveLine.setSaleOrderLine(stockMoveLine.getSaleOrderLine());
    newStockMoveLine.setPurchaseOrderLine(stockMoveLine.getPurchaseOrderLine());
    return newStockMoveLine;
}
Also used : StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal)

Aggregations

StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)121 BigDecimal (java.math.BigDecimal)59 StockMove (com.axelor.apps.stock.db.StockMove)44 AxelorException (com.axelor.exception.AxelorException)41 Product (com.axelor.apps.base.db.Product)33 Transactional (com.google.inject.persist.Transactional)31 ArrayList (java.util.ArrayList)28 List (java.util.List)18 Company (com.axelor.apps.base.db.Company)16 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)16 StockLocation (com.axelor.apps.stock.db.StockLocation)14 StockMoveLineService (com.axelor.apps.stock.service.StockMoveLineService)14 Unit (com.axelor.apps.base.db.Unit)13 Beans (com.axelor.inject.Beans)13 ProdProduct (com.axelor.apps.production.db.ProdProduct)12 StockMoveService (com.axelor.apps.stock.service.StockMoveService)12 I18n (com.axelor.i18n.I18n)12 Inject (com.google.inject.Inject)12 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)10 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)10