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