use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class ReservedQtyServiceImpl method allocateAll.
@Override
@Transactional(rollbackOn = { Exception.class })
public void allocateAll(StockMoveLine stockMoveLine) throws AxelorException {
requestQty(stockMoveLine);
SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
if (saleOrderLine != null) {
allocateAll(saleOrderLine);
} else {
// search for the maximum quantity that can be allocated in the stock move line.
StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockMoveLine.getStockMove().getFromStockLocation(), stockMoveLine.getProduct());
BigDecimal availableQtyToBeReserved = stockLocationLine.getCurrentQty().subtract(stockLocationLine.getReservedQty());
Product product = stockMoveLine.getProduct();
BigDecimal availableQtyToBeReservedStockMoveLine = convertUnitWithProduct(stockMoveLine.getUnit(), stockLocationLine.getUnit(), availableQtyToBeReserved, product).add(stockMoveLine.getReservedQty());
BigDecimal qtyThatWillBeAllocated = stockMoveLine.getQty().min(availableQtyToBeReservedStockMoveLine);
// allocate it
if (qtyThatWillBeAllocated.compareTo(stockMoveLine.getReservedQty()) > 0) {
updateReservedQty(stockLocationLine, stockMoveLine, qtyThatWillBeAllocated);
}
}
}
use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class MrpServiceImpl method createAvailableStockMrpLine.
@Transactional(rollbackOn = { Exception.class })
protected MrpLine createAvailableStockMrpLine(Mrp mrp, Product product, StockLocation stockLocation, MrpLineType availableStockMrpLineType) throws AxelorException {
BigDecimal qty = BigDecimal.ZERO;
StockLocationLine stockLocationLine = this.getStockLocationLine(product, stockLocation);
if (stockLocationLine != null) {
qty = stockLocationLine.getCurrentQty();
}
return mrpLineRepository.save(this.createMrpLine(mrp, product, availableStockMrpLineType, qty, today, qty, stockLocation, null));
}
use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class ReservedQtyServiceImpl method allocateAll.
@Override
public void allocateAll(SaleOrderLine saleOrderLine) throws AxelorException {
if (saleOrderLine.getProduct() == null || !saleOrderLine.getProduct().getStockManaged()) {
return;
}
// request the maximum quantity
requestQty(saleOrderLine);
StockMoveLine stockMoveLine = getPlannedStockMoveLine(saleOrderLine);
if (stockMoveLine == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_NO_STOCK_MOVE));
}
// search for the maximum quantity that can be allocated.
StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockMoveLine.getStockMove().getFromStockLocation(), stockMoveLine.getProduct());
BigDecimal availableQtyToBeReserved = stockLocationLine.getCurrentQty().subtract(stockLocationLine.getReservedQty());
Product product = stockMoveLine.getProduct();
BigDecimal availableQtyToBeReservedSaleOrderLine = convertUnitWithProduct(saleOrderLine.getUnit(), stockLocationLine.getUnit(), availableQtyToBeReserved, product).add(saleOrderLine.getReservedQty());
BigDecimal qtyThatWillBeAllocated = saleOrderLine.getQty().min(availableQtyToBeReservedSaleOrderLine);
// allocate it
if (qtyThatWillBeAllocated.compareTo(saleOrderLine.getReservedQty()) > 0) {
updateReservedQty(saleOrderLine, qtyThatWillBeAllocated);
}
}
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(SaleOrderLine saleOrderLine, BigDecimal newReservedQty) throws AxelorException {
if (saleOrderLine.getProduct() == null || !saleOrderLine.getProduct().getStockManaged()) {
return;
}
StockMoveLine stockMoveLine = getPlannedStockMoveLine(saleOrderLine);
checkBeforeUpdatingQties(stockMoveLine, newReservedQty);
if (Beans.get(AppSupplychainService.class).getAppSupplychain().getBlockDeallocationOnAvailabilityRequest()) {
checkAvailabilityRequest(stockMoveLine, newReservedQty, false);
}
BigDecimal newRequestedReservedQty = newReservedQty.add(saleOrderLine.getDeliveredQty());
// update requested reserved qty
if (newRequestedReservedQty.compareTo(saleOrderLine.getRequestedReservedQty()) > 0 && newReservedQty.compareTo(BigDecimal.ZERO) > 0) {
requestQty(saleOrderLine);
}
StockLocationLine stockLocationLine = stockLocationLineService.getOrCreateStockLocationLine(stockMoveLine.getStockMove().getFromStockLocation(), stockMoveLine.getProduct());
BigDecimal availableQtyToBeReserved = stockLocationLine.getCurrentQty().subtract(stockLocationLine.getReservedQty());
BigDecimal diffReservedQuantity = newReservedQty.subtract(saleOrderLine.getReservedQty());
Product product = stockMoveLine.getProduct();
BigDecimal diffReservedQuantityLocation = convertUnitWithProduct(saleOrderLine.getUnit(), stockLocationLine.getUnit(), diffReservedQuantity, product);
if (availableQtyToBeReserved.compareTo(diffReservedQuantityLocation) < 0) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_QTY_NOT_AVAILABLE));
}
// update in stock move line and sale order line
updateReservedQuantityInStockMoveLineFromSaleOrderLine(saleOrderLine, stockMoveLine.getProduct(), newReservedQty);
// update in stock location line
updateReservedQty(stockLocationLine);
}
use of com.axelor.apps.stock.db.StockLocationLine in project axelor-open-suite by axelor.
the class ProductStockLocationServiceImpl method getAvailableQty.
protected BigDecimal getAvailableQty(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.getAvailableStockForAProduct(product.getId(), companyId, stockLocationId);
List<StockLocationLine> stockLocationLineList = stockLocationLineRepository.all().filter(query).fetch();
// Compute
BigDecimal sumAvailableQty = BigDecimal.ZERO;
if (!stockLocationLineList.isEmpty()) {
Unit unitConversion = product.getUnit();
for (StockLocationLine stockLocationLine : stockLocationLineList) {
BigDecimal productAvailableQty = stockLocationLine.getCurrentQty();
unitConversionService.convert(stockLocationLine.getUnit(), unitConversion, productAvailableQty, productAvailableQty.scale(), product);
sumAvailableQty = sumAvailableQty.add(productAvailableQty);
}
}
return sumAvailableQty;
}
Aggregations