Search in sources :

Example 21 with StockLocationLine

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

the class ReservedQtyServiceImpl method updateRequestedQuantityInToStockLocation.

@Override
public void updateRequestedQuantityInToStockLocation(StockMoveLine stockMoveLine, StockLocation stockLocation, Product product, int toStatus, BigDecimal qty) throws AxelorException {
    if (product == null || !product.getStockManaged()) {
        return;
    }
    StockLocationLine stockLocationLine = stockLocationLineService.getStockLocationLine(stockLocation, product);
    if (stockLocationLine == null) {
        return;
    }
    Company company = stockLocationLine.getStockLocation().getCompany();
    SupplyChainConfig supplyChainConfig = supplychainConfigService.getSupplyChainConfig(company);
    if (toStatus == StockMoveRepository.STATUS_REALIZED && supplyChainConfig.getAutoAllocateOnReceipt()) {
        reallocateQty(stockMoveLine, stockLocation, stockLocationLine, product, qty);
    }
    updateRequestedReservedQty(stockLocationLine);
    checkReservedQtyStocks(stockLocationLine, stockMoveLine, toStatus);
}
Also used : Company(com.axelor.apps.base.db.Company) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig)

Example 22 with StockLocationLine

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

the class ProductStockLocationServiceImpl method getRequestedReservedQty.

protected BigDecimal getRequestedReservedQty(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.getStockLocationLineListForAProduct(product.getId(), companyId, stockLocationId);
    List<StockLocationLine> stockLocationLineList = stockLocationLineRepository.all().filter(query).fetch();
    // Compute
    BigDecimal sumRequestedReservedQty = BigDecimal.ZERO;
    if (!stockLocationLineList.isEmpty()) {
        Unit unitConversion = product.getUnit();
        for (StockLocationLine stockLocationLine : stockLocationLineList) {
            BigDecimal requestedReservedQty = stockLocationLine.getRequestedReservedQty();
            requestedReservedQty = unitConversionService.convert(stockLocationLine.getUnit(), unitConversion, requestedReservedQty, requestedReservedQty.scale(), product);
            sumRequestedReservedQty = sumRequestedReservedQty.add(requestedReservedQty);
        }
    }
    return sumRequestedReservedQty;
}
Also used : StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Unit(com.axelor.apps.base.db.Unit) BigDecimal(java.math.BigDecimal)

Example 23 with StockLocationLine

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

the class StockLocationLineController method deallocateAll.

/**
 * Called from stock location line form view, on deallocateAll button click. Call {@link
 * StockLocationLineReservationService#deallocateAll(StockLocationLine)}
 *
 * @param request
 * @param response
 */
public void deallocateAll(ActionRequest request, ActionResponse response) {
    try {
        StockLocationLine stockLocationLine = request.getContext().asType(StockLocationLine.class);
        stockLocationLine = Beans.get(StockLocationLineRepository.class).find(stockLocationLine.getId());
        Beans.get(StockLocationLineReservationService.class).deallocateAll(stockLocationLine);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : StockLocationLineReservationService(com.axelor.apps.supplychain.service.StockLocationLineReservationService) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine)

Example 24 with StockLocationLine

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

the class StockMoveLineServiceSupplychainImpl method updateAvailableQty.

@Override
public void updateAvailableQty(StockMoveLine stockMoveLine, StockLocation stockLocation) {
    if (!Beans.get(AppBaseService.class).isApp("supplychain")) {
        super.updateAvailableQty(stockMoveLine, stockLocation);
        return;
    }
    BigDecimal availableQty = BigDecimal.ZERO;
    BigDecimal availableQtyForProduct = BigDecimal.ZERO;
    if (stockMoveLine.getProduct() != null) {
        if (stockMoveLine.getProduct().getTrackingNumberConfiguration() != null) {
            if (stockMoveLine.getTrackingNumber() != null) {
                StockLocationLine stockLocationLine = stockLocationLineService.getDetailLocationLine(stockLocation, stockMoveLine.getProduct(), stockMoveLine.getTrackingNumber());
                if (stockLocationLine != null) {
                    availableQty = stockLocationLine.getCurrentQty().add(stockMoveLine.getReservedQty()).subtract(stockLocationLine.getReservedQty());
                }
            }
            if (availableQty.compareTo(stockMoveLine.getRealQty()) < 0) {
                StockLocationLine stockLocationLineForProduct = stockLocationLineService.getStockLocationLine(stockLocation, stockMoveLine.getProduct());
                if (stockLocationLineForProduct != null) {
                    availableQtyForProduct = stockLocationLineForProduct.getCurrentQty().add(stockMoveLine.getReservedQty()).subtract(stockLocationLineForProduct.getReservedQty());
                }
            }
        } else {
            StockLocationLine stockLocationLine = stockLocationLineService.getStockLocationLine(stockLocation, stockMoveLine.getProduct());
            if (stockLocationLine != null) {
                availableQty = stockLocationLine.getCurrentQty().add(stockMoveLine.getReservedQty()).subtract(stockLocationLine.getReservedQty());
            }
        }
    }
    stockMoveLine.setAvailableQty(availableQty);
    stockMoveLine.setAvailableQtyForProduct(availableQtyForProduct);
}
Also used : StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal)

Example 25 with StockLocationLine

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

the class StockLocationLineServiceSupplychainImpl method getTrackingNumberAvailableQty.

@Override
public BigDecimal getTrackingNumberAvailableQty(StockLocation stockLocation, TrackingNumber trackingNumber) {
    if (!appSupplychainService.isApp("supplychain") || !appSupplychainService.getAppSupplychain().getManageStockReservation()) {
        return super.getTrackingNumberAvailableQty(stockLocation, trackingNumber);
    }
    StockLocationLine detailStockLocationLine = getDetailLocationLine(stockLocation, trackingNumber.getProduct(), trackingNumber);
    BigDecimal availableQty = BigDecimal.ZERO;
    if (detailStockLocationLine != null) {
        availableQty = detailStockLocationLine.getCurrentQty().subtract(detailStockLocationLine.getReservedQty());
    }
    return availableQty;
}
Also used : StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) 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