use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class StockMoveServiceSupplychainImpl method updatePurchaseOrderLines.
protected void updatePurchaseOrderLines(StockMove stockMove, boolean qtyWasReceived) throws AxelorException {
for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
if (stockMoveLine.getPurchaseOrderLine() != null) {
PurchaseOrderLine purchaseOrderLine = stockMoveLine.getPurchaseOrderLine();
BigDecimal realQty = unitConversionService.convert(stockMoveLine.getUnit(), purchaseOrderLine.getUnit(), stockMoveLine.getRealQty(), stockMoveLine.getRealQty().scale(), purchaseOrderLine.getProduct());
if (qtyWasReceived) {
purchaseOrderLine.setReceivedQty(purchaseOrderLine.getReceivedQty().add(realQty));
} else {
purchaseOrderLine.setReceivedQty(purchaseOrderLine.getReceivedQty().subtract(realQty));
}
if (purchaseOrderLine.getReceivedQty().signum() == 0) {
purchaseOrderLine.setReceiptState(PurchaseOrderRepository.STATE_NOT_RECEIVED);
} else if (purchaseOrderLine.getReceivedQty().compareTo(purchaseOrderLine.getQty()) < 0) {
purchaseOrderLine.setReceiptState(PurchaseOrderRepository.STATE_PARTIALLY_RECEIVED);
} else {
purchaseOrderLine.setReceiptState(PurchaseOrderRepository.STATE_RECEIVED);
}
}
}
}
use of com.axelor.apps.stock.db.StockMoveLine 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.StockMoveLine in project axelor-open-suite by axelor.
the class ReservedQtyServiceImpl method updateRequestedReservedQty.
@Override
public void updateRequestedReservedQty(StockLocationLine stockLocationLine) throws AxelorException {
// compute from stock move lines
List<StockMoveLine> stockMoveLineList = stockMoveLineRepository.all().filter("self.product.id = :productId " + "AND self.stockMove.fromStockLocation.id = :stockLocationId " + "AND self.stockMove.statusSelect = :planned").bind("productId", stockLocationLine.getProduct().getId()).bind("stockLocationId", stockLocationLine.getStockLocation().getId()).bind("planned", StockMoveRepository.STATUS_PLANNED).fetch();
BigDecimal requestedReservedQty = BigDecimal.ZERO;
for (StockMoveLine stockMoveLine : stockMoveLineList) {
requestedReservedQty = requestedReservedQty.add(convertUnitWithProduct(stockMoveLine.getUnit(), stockLocationLine.getUnit(), stockMoveLine.getRequestedReservedQty(), stockLocationLine.getProduct()));
}
stockLocationLine.setRequestedReservedQty(requestedReservedQty);
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class ReservedQtyServiceImpl method consolidateReservedQtyInStockMoveLineByProduct.
@Override
public void consolidateReservedQtyInStockMoveLineByProduct(StockMove stockMove) {
if (stockMove.getStockMoveLineList() == null) {
return;
}
List<Product> productList = stockMove.getStockMoveLineList().stream().map(StockMoveLine::getProduct).filter(Objects::nonNull).filter(Product::getStockManaged).distinct().collect(Collectors.toList());
for (Product product : productList) {
if (product != null) {
List<StockMoveLine> stockMoveLineListToConsolidate = stockMove.getStockMoveLineList().stream().filter(stockMoveLine1 -> product.equals(stockMoveLine1.getProduct())).collect(Collectors.toList());
if (stockMoveLineListToConsolidate.size() > 1) {
stockMoveLineListToConsolidate.sort(Comparator.comparing(StockMoveLine::getId));
BigDecimal reservedQtySum = stockMoveLineListToConsolidate.stream().map(StockMoveLine::getReservedQty).reduce(BigDecimal::add).orElse(BigDecimal.ZERO);
stockMoveLineListToConsolidate.forEach(toConsolidateStockMoveLine -> toConsolidateStockMoveLine.setReservedQty(BigDecimal.ZERO));
stockMoveLineListToConsolidate.get(0).setReservedQty(reservedQtySum);
}
}
}
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class AccountingCutOffServiceImpl method generateMoveLines.
protected List<MoveLine> generateMoveLines(Move move, List<StockMoveLine> stockMoveLineList, String origin, boolean isPurchase, boolean recoveredTax, boolean ati, String moveDescription, boolean isReverse, LocalDate originDate, boolean includeNotStockManagedProduct) throws AxelorException {
if (stockMoveLineList != null) {
for (StockMoveLine stockMoveLine : stockMoveLineList) {
Product product = stockMoveLine.getProduct();
if (checkStockMoveLine(stockMoveLine, product, includeNotStockManagedProduct)) {
continue;
}
generateProductMoveLine(move, stockMoveLine, origin, isPurchase, recoveredTax, ati, moveDescription, isReverse, originDate);
}
}
return move.getMoveLineList();
}
Aggregations