Search in sources :

Example 31 with StockLocationLine

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

the class ReservedQtyServiceImpl method allocateAll.

@Override
@Transactional(rollbackOn = { Exception.class })
public void allocateAll(StockMoveLine stockMoveLine) throws AxelorException {
    requestQty(stockMoveLine);
    SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
    if (saleOrderLine != null) {
        allocateAll(saleOrderLine);
    } else {
        // search for the maximum quantity that can be allocated in the stock move line.
        StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockMoveLine.getStockMove().getFromStockLocation(), stockMoveLine.getProduct());
        BigDecimal availableQtyToBeReserved = stockLocationLine.getCurrentQty().subtract(stockLocationLine.getReservedQty());
        Product product = stockMoveLine.getProduct();
        BigDecimal availableQtyToBeReservedStockMoveLine = convertUnitWithProduct(stockMoveLine.getUnit(), stockLocationLine.getUnit(), availableQtyToBeReserved, product).add(stockMoveLine.getReservedQty());
        BigDecimal qtyThatWillBeAllocated = stockMoveLine.getQty().min(availableQtyToBeReservedStockMoveLine);
        // allocate it
        if (qtyThatWillBeAllocated.compareTo(stockMoveLine.getReservedQty()) > 0) {
            updateReservedQty(stockLocationLine, stockMoveLine, qtyThatWillBeAllocated);
        }
    }
}
Also used : Product(com.axelor.apps.base.db.Product) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 32 with StockLocationLine

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

the class MrpServiceImpl method createAvailableStockMrpLine.

@Transactional(rollbackOn = { Exception.class })
protected MrpLine createAvailableStockMrpLine(Mrp mrp, Product product, StockLocation stockLocation, MrpLineType availableStockMrpLineType) throws AxelorException {
    BigDecimal qty = BigDecimal.ZERO;
    StockLocationLine stockLocationLine = this.getStockLocationLine(product, stockLocation);
    if (stockLocationLine != null) {
        qty = stockLocationLine.getCurrentQty();
    }
    return mrpLineRepository.save(this.createMrpLine(mrp, product, availableStockMrpLineType, qty, today, qty, stockLocation, null));
}
Also used : StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 33 with StockLocationLine

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

the class ReservedQtyServiceImpl method allocateAll.

@Override
public void allocateAll(SaleOrderLine saleOrderLine) throws AxelorException {
    if (saleOrderLine.getProduct() == null || !saleOrderLine.getProduct().getStockManaged()) {
        return;
    }
    // request the maximum quantity
    requestQty(saleOrderLine);
    StockMoveLine stockMoveLine = getPlannedStockMoveLine(saleOrderLine);
    if (stockMoveLine == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_NO_STOCK_MOVE));
    }
    // search for the maximum quantity that can be allocated.
    StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockMoveLine.getStockMove().getFromStockLocation(), stockMoveLine.getProduct());
    BigDecimal availableQtyToBeReserved = stockLocationLine.getCurrentQty().subtract(stockLocationLine.getReservedQty());
    Product product = stockMoveLine.getProduct();
    BigDecimal availableQtyToBeReservedSaleOrderLine = convertUnitWithProduct(saleOrderLine.getUnit(), stockLocationLine.getUnit(), availableQtyToBeReserved, product).add(saleOrderLine.getReservedQty());
    BigDecimal qtyThatWillBeAllocated = saleOrderLine.getQty().min(availableQtyToBeReservedSaleOrderLine);
    // allocate it
    if (qtyThatWillBeAllocated.compareTo(saleOrderLine.getReservedQty()) > 0) {
        updateReservedQty(saleOrderLine, qtyThatWillBeAllocated);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal)

Example 34 with StockLocationLine

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

the class ReservedQtyServiceImpl method updateReservedQty.

@Override
@Transactional(rollbackOn = { Exception.class })
public void updateReservedQty(SaleOrderLine saleOrderLine, BigDecimal newReservedQty) throws AxelorException {
    if (saleOrderLine.getProduct() == null || !saleOrderLine.getProduct().getStockManaged()) {
        return;
    }
    StockMoveLine stockMoveLine = getPlannedStockMoveLine(saleOrderLine);
    checkBeforeUpdatingQties(stockMoveLine, newReservedQty);
    if (Beans.get(AppSupplychainService.class).getAppSupplychain().getBlockDeallocationOnAvailabilityRequest()) {
        checkAvailabilityRequest(stockMoveLine, newReservedQty, false);
    }
    BigDecimal newRequestedReservedQty = newReservedQty.add(saleOrderLine.getDeliveredQty());
    // update requested reserved qty
    if (newRequestedReservedQty.compareTo(saleOrderLine.getRequestedReservedQty()) > 0 && newReservedQty.compareTo(BigDecimal.ZERO) > 0) {
        requestQty(saleOrderLine);
    }
    StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockMoveLine.getStockMove().getFromStockLocation(), stockMoveLine.getProduct());
    BigDecimal availableQtyToBeReserved = stockLocationLine.getCurrentQty().subtract(stockLocationLine.getReservedQty());
    BigDecimal diffReservedQuantity = newReservedQty.subtract(saleOrderLine.getReservedQty());
    Product product = stockMoveLine.getProduct();
    BigDecimal diffReservedQuantityLocation = convertUnitWithProduct(saleOrderLine.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));
    }
    // update in stock move line and sale order line
    updateReservedQuantityInStockMoveLineFromSaleOrderLine(saleOrderLine, stockMoveLine.getProduct(), newReservedQty);
    // update in stock location line
    updateReservedQty(stockLocationLine);
}
Also used : AxelorException(com.axelor.exception.AxelorException) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 35 with StockLocationLine

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

the class ProductStockLocationServiceImpl method getAvailableQty.

protected BigDecimal getAvailableQty(Product product, Company company, StockLocation stockLocation) throws AxelorException {
    if (product == null || product.getUnit() == null) {
        return BigDecimal.ZERO;
    }
    Long companyId = 0L;
    Long stockLocationId = 0L;
    if (company != null) {
        companyId = company.getId();
    }
    if (stockLocation != null) {
        stockLocationId = stockLocation.getId();
    }
    String query = stockLocationLineService.getAvailableStockForAProduct(product.getId(), companyId, stockLocationId);
    List<StockLocationLine> stockLocationLineList = stockLocationLineRepository.all().filter(query).fetch();
    // Compute
    BigDecimal sumAvailableQty = BigDecimal.ZERO;
    if (!stockLocationLineList.isEmpty()) {
        Unit unitConversion = product.getUnit();
        for (StockLocationLine stockLocationLine : stockLocationLineList) {
            BigDecimal productAvailableQty = stockLocationLine.getCurrentQty();
            unitConversionService.convert(stockLocationLine.getUnit(), unitConversion, productAvailableQty, productAvailableQty.scale(), product);
            sumAvailableQty = sumAvailableQty.add(productAvailableQty);
        }
    }
    return sumAvailableQty;
}
Also used : StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Aggregations

StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)42 BigDecimal (java.math.BigDecimal)25 Product (com.axelor.apps.base.db.Product)13 Transactional (com.google.inject.persist.Transactional)10 StockLocation (com.axelor.apps.stock.db.StockLocation)8 AxelorException (com.axelor.exception.AxelorException)8 Unit (com.axelor.apps.base.db.Unit)7 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)7 TrackingNumber (com.axelor.apps.stock.db.TrackingNumber)6 InventoryLine (com.axelor.apps.stock.db.InventoryLine)4 StockLocationLineRepository (com.axelor.apps.stock.db.repo.StockLocationLineRepository)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Company (com.axelor.apps.base.db.Company)3 StockMove (com.axelor.apps.stock.db.StockMove)3 Beans (com.axelor.inject.Beans)3 UnitConversionService (com.axelor.apps.base.service.UnitConversionService)2 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)2 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)2 Inventory (com.axelor.apps.stock.db.Inventory)2