use of com.axelor.apps.stock.db.StockLocation 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;
}
Aggregations