Search in sources :

Example 41 with StockLocationLine

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

the class StockMoveLineServiceImpl method updateAvailableQty.

@Override
public void updateAvailableQty(StockMoveLine stockMoveLine, StockLocation stockLocation) {
    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();
                }
            }
            if (availableQty.compareTo(stockMoveLine.getRealQty()) < 0) {
                StockLocationLine stockLocationLineForProduct = stockLocationLineService.getStockLocationLine(stockLocation, stockMoveLine.getProduct());
                if (stockLocationLineForProduct != null) {
                    availableQtyForProduct = stockLocationLineForProduct.getCurrentQty();
                }
            }
        } else {
            StockLocationLine stockLocationLine = stockLocationLineService.getStockLocationLine(stockLocation, stockMoveLine.getProduct());
            if (stockLocationLine != null) {
                availableQty = stockLocationLine.getCurrentQty();
            }
        }
    }
    stockMoveLine.setAvailableQty(availableQty);
    stockMoveLine.setAvailableQtyForProduct(availableQtyForProduct);
}
Also used : StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal)

Example 42 with StockLocationLine

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

the class StockLocationServiceImpl method getQty.

@Override
public BigDecimal getQty(Long productId, Long locationId, Long companyId, String qtyType) throws AxelorException {
    if (productId != null) {
        Product product = productRepo.find(productId);
        Unit productUnit = product.getUnit();
        UnitConversionService unitConversionService = Beans.get(UnitConversionService.class);
        int scale = Beans.get(AppBaseService.class).getNbDecimalDigitForQty();
        if (locationId == null || locationId == 0L) {
            List<StockLocation> stockLocations = getNonVirtualStockLocations(companyId);
            if (!stockLocations.isEmpty()) {
                BigDecimal qty = BigDecimal.ZERO;
                for (StockLocation stockLocation : stockLocations) {
                    StockLocationLine stockLocationLine = stockLocationLineService.getStockLocationLine(stockLocationRepo.find(stockLocation.getId()), productRepo.find(productId));
                    if (stockLocationLine != null) {
                        Unit stockLocationLineUnit = stockLocationLine.getUnit();
                        qty = qty.add(qtyType.equals("real") ? stockLocationLine.getCurrentQty() : stockLocationLine.getFutureQty());
                        if (productUnit != null && !productUnit.equals(stockLocationLineUnit)) {
                            qty = unitConversionService.convert(stockLocationLineUnit, productUnit, qty, qty.scale(), product);
                        }
                    }
                }
                return qty.setScale(scale, RoundingMode.HALF_UP);
            }
        } else {
            StockLocationLine stockLocationLine = stockLocationLineService.getStockLocationLine(stockLocationRepo.find(locationId), productRepo.find(productId));
            if (stockLocationLine != null) {
                Unit stockLocationLineUnit = stockLocationLine.getUnit();
                BigDecimal qty = BigDecimal.ZERO;
                qty = qtyType.equals("real") ? stockLocationLine.getCurrentQty() : stockLocationLine.getFutureQty();
                if (productUnit != null && !productUnit.equals(stockLocationLineUnit)) {
                    qty = unitConversionService.convert(stockLocationLineUnit, productUnit, qty, qty.scale(), product);
                }
                return qty.setScale(scale, RoundingMode.HALF_UP);
            }
        }
    }
    return BigDecimal.ZERO;
}
Also used : UnitConversionService(com.axelor.apps.base.service.UnitConversionService) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StockLocation(com.axelor.apps.stock.db.StockLocation) Product(com.axelor.apps.base.db.Product) 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