use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class StockLocationLineServiceSupplychainImpl method getAvailableQty.
@Override
public BigDecimal getAvailableQty(StockLocation stockLocation, Product product) {
if (!appSupplychainService.isApp("supplychain")) {
return super.getAvailableQty(stockLocation, product);
}
StockLocationLine stockLocationLine = getStockLocationLine(stockLocation, product);
BigDecimal availableQty = BigDecimal.ZERO;
if (stockLocationLine != null) {
availableQty = stockLocationLine.getCurrentQty().subtract(stockLocationLine.getReservedQty());
}
return availableQty;
}
use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class StockLocationServiceSupplychainImpl method getReservedQty.
@Override
public BigDecimal getReservedQty(Long productId, Long locationId, Long companyId) throws AxelorException {
if (productId != null) {
Product product = productRepo.find(productId);
Unit productUnit = product.getUnit();
UnitConversionService unitConversionService = Beans.get(UnitConversionService.class);
if (locationId == null || locationId == 0L) {
List<StockLocation> stockLocations = getNonVirtualStockLocations(companyId);
if (!stockLocations.isEmpty()) {
BigDecimal reservedQty = BigDecimal.ZERO;
for (StockLocation stockLocation : stockLocations) {
StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockLocationRepo.find(stockLocation.getId()), productRepo.find(productId));
if (stockLocationLine != null) {
Unit stockLocationLineUnit = stockLocationLine.getUnit();
reservedQty = reservedQty.add(stockLocationLine.getReservedQty());
if (productUnit != null && !productUnit.equals(stockLocationLineUnit)) {
reservedQty = unitConversionService.convert(stockLocationLineUnit, productUnit, reservedQty, reservedQty.scale(), product);
}
}
}
return reservedQty;
}
} else {
StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockLocationRepo.find(locationId), productRepo.find(productId));
if (stockLocationLine != null) {
Unit stockLocationLineUnit = stockLocationLine.getUnit();
if (productUnit != null && !productUnit.equals(stockLocationLineUnit)) {
return unitConversionService.convert(stockLocationLineUnit, productUnit, stockLocationLine.getReservedQty(), stockLocationLine.getReservedQty().scale(), product);
}
return stockLocationLine.getReservedQty();
}
}
}
return BigDecimal.ZERO;
}
use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class ReservedQtyServiceImpl method updateRequestedReservedQty.
@Override
@Transactional(rollbackOn = { Exception.class })
public void updateRequestedReservedQty(SaleOrderLine saleOrderLine, BigDecimal newReservedQty) throws AxelorException {
if (saleOrderLine.getProduct() == null || !saleOrderLine.getProduct().getStockManaged()) {
return;
}
StockMoveLine stockMoveLine = getPlannedStockMoveLine(saleOrderLine);
if (stockMoveLine == null) {
// only change requested quantity in sale order line
saleOrderLine.setRequestedReservedQty(newReservedQty);
return;
}
checkBeforeUpdatingQties(stockMoveLine, newReservedQty);
if (Beans.get(AppSupplychainService.class).getAppSupplychain().getBlockDeallocationOnAvailabilityRequest()) {
checkAvailabilityRequest(stockMoveLine, newReservedQty, true);
}
BigDecimal diffReservedQuantity = newReservedQty.subtract(saleOrderLine.getRequestedReservedQty());
// update in stock move line and sale order line
BigDecimal newAllocatedQty = updateRequestedReservedQuantityInStockMoveLines(saleOrderLine, stockMoveLine.getProduct(), newReservedQty);
StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockMoveLine.getStockMove().getFromStockLocation(), stockMoveLine.getProduct());
Product product = stockMoveLine.getProduct();
// update in stock location line
BigDecimal diffReservedQuantityLocation = convertUnitWithProduct(stockMoveLine.getUnit(), stockLocationLine.getUnit(), diffReservedQuantity, product);
stockLocationLine.setRequestedReservedQty(stockLocationLine.getRequestedReservedQty().add(diffReservedQuantityLocation));
// update reserved qty
if (newAllocatedQty.compareTo(saleOrderLine.getReservedQty()) < 0) {
updateReservedQty(saleOrderLine, newAllocatedQty);
}
}
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(StockMoveLine stockMoveLine, BigDecimal newReservedQty) throws AxelorException {
StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockMoveLine.getStockMove().getFromStockLocation(), stockMoveLine.getProduct());
updateReservedQty(stockLocationLine, stockMoveLine, newReservedQty);
}
use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class ReservedQtyServiceImpl method updateRequestedQuantityInFromStockLocation.
@Override
public void updateRequestedQuantityInFromStockLocation(StockMoveLine stockMoveLine, StockLocation stockLocation, Product product, int toStatus, BigDecimal requestedReservedQty) throws AxelorException {
if (product == null || !product.getStockManaged()) {
return;
}
Unit stockMoveLineUnit = stockMoveLine.getUnit();
StockLocationLine stockLocationLine = stockLocationLineService.getStockLocationLine(stockLocation, product);
if (stockLocationLine == null) {
return;
}
Unit stockLocationLineUnit = stockLocationLine.getUnit();
// the quantity that will be allocated in stock location line
BigDecimal realReservedQty;
// the quantity that will be allocated in stock move line
BigDecimal realReservedStockMoveQty;
// if we cancel, subtract the quantity using the previously allocated quantity.
if (toStatus == StockMoveRepository.STATUS_CANCELED || toStatus == StockMoveRepository.STATUS_REALIZED) {
realReservedStockMoveQty = stockMoveLine.getReservedQty();
// convert the quantity for stock location line
realReservedQty = convertUnitWithProduct(stockMoveLineUnit, stockLocationLineUnit, realReservedStockMoveQty, stockMoveLine.getProduct());
// reallocate quantity in other stock move lines
if (isReallocatingQtyOnCancel(stockMoveLine)) {
reallocateQty(stockMoveLine, stockLocation, stockLocationLine, product, realReservedQty);
}
// no more reserved qty in stock move and sale order lines
updateReservedQuantityFromStockMoveLine(stockMoveLine, product, stockMoveLine.getReservedQty().negate());
// update requested quantity in sale order line
SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
if (saleOrderLine != null) {
// requested quantity should never be below delivered quantity.
if (toStatus == StockMoveRepository.STATUS_REALIZED) {
saleOrderLine.setRequestedReservedQty(saleOrderLine.getRequestedReservedQty().max(saleOrderLine.getDeliveredQty()));
} else if (!saleOrderLine.getIsQtyRequested()) {
// if we cancel and do not want to request quantity, the requested quantity become the new
// delivered quantity.
saleOrderLine.setRequestedReservedQty(saleOrderLine.getDeliveredQty());
}
}
} else {
BigDecimal requestedReservedQtyInLocation = convertUnitWithProduct(stockMoveLineUnit, stockLocationLine.getUnit(), requestedReservedQty, product);
realReservedQty = computeRealReservedQty(stockLocationLine, requestedReservedQtyInLocation);
// convert back the quantity for the stock move line
realReservedStockMoveQty = convertUnitWithProduct(stockLocationLineUnit, stockMoveLineUnit, realReservedQty, stockMoveLine.getProduct());
updateReservedQuantityFromStockMoveLine(stockMoveLine, product, realReservedStockMoveQty);
// reallocate quantity in other stock move lines
if (supplychainConfigService.getSupplyChainConfig(stockLocation.getCompany()).getAutoAllocateOnAllocation()) {
BigDecimal availableQuantityInLocation = stockLocationLine.getCurrentQty().subtract(stockLocationLine.getReservedQty());
availableQuantityInLocation = convertUnitWithProduct(stockLocationLineUnit, stockMoveLineUnit, availableQuantityInLocation, product);
BigDecimal qtyRemainingToAllocate = availableQuantityInLocation.subtract(realReservedStockMoveQty);
reallocateQty(stockMoveLine, stockLocation, stockLocationLine, product, qtyRemainingToAllocate);
}
}
updateReservedQty(stockLocationLine);
updateRequestedReservedQty(stockLocationLine);
checkReservedQtyStocks(stockLocationLine, stockMoveLine, toStatus);
}
Aggregations