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);
}
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;
}
Aggregations