use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class ManufOrderServiceImpl method updateConsumedStockMoveFromManufOrder.
@Override
@Transactional(rollbackOn = { Exception.class })
public void updateConsumedStockMoveFromManufOrder(ManufOrder manufOrder) throws AxelorException {
this.updateDiffProdProductList(manufOrder);
List<StockMoveLine> consumedStockMoveLineList = manufOrder.getConsumedStockMoveLineList();
if (consumedStockMoveLineList == null) {
return;
}
ManufOrderStockMoveService manufOrderStockMoveService = Beans.get(ManufOrderStockMoveService.class);
Optional<StockMove> stockMoveOpt = manufOrderStockMoveService.getPlannedStockMove(manufOrder.getInStockMoveList());
StockMove stockMove;
if (stockMoveOpt.isPresent()) {
stockMove = stockMoveOpt.get();
} else {
stockMove = manufOrderStockMoveService._createToConsumeStockMove(manufOrder, manufOrder.getCompany());
manufOrder.addInStockMoveListItem(stockMove);
Beans.get(StockMoveService.class).plan(stockMove);
}
updateStockMoveFromManufOrder(consumedStockMoveLineList, stockMove);
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class ManufOrderServiceImpl method createDiffProdProductList.
@Override
public List<ProdProduct> createDiffProdProductList(List<ProdProduct> prodProductList, List<StockMoveLine> stockMoveLineList) throws AxelorException {
List<ProdProduct> diffConsumeList = new ArrayList<>();
for (ProdProduct prodProduct : prodProductList) {
Product product = prodProduct.getProduct();
Unit newUnit = prodProduct.getUnit();
List<StockMoveLine> stockMoveLineProductList = stockMoveLineList.stream().filter(stockMoveLine1 -> stockMoveLine1.getProduct() != null).filter(stockMoveLine1 -> stockMoveLine1.getProduct().equals(product)).collect(Collectors.toList());
if (stockMoveLineProductList.isEmpty()) {
StockMoveLine stockMoveLine = new StockMoveLine();
stockMoveLineProductList.add(stockMoveLine);
}
BigDecimal diffQty = computeDiffQty(prodProduct, stockMoveLineProductList, product);
BigDecimal plannedQty = prodProduct.getQty();
BigDecimal realQty = diffQty.add(plannedQty);
if (diffQty.compareTo(BigDecimal.ZERO) != 0) {
ProdProduct diffProdProduct = new ProdProduct();
diffProdProduct.setQty(diffQty);
diffProdProduct.setPlannedQty(plannedQty);
diffProdProduct.setRealQty(realQty);
diffProdProduct.setProduct(product);
diffProdProduct.setUnit(newUnit);
diffConsumeList.add(diffProdProduct);
}
}
// There are stock move lines with products that are not available in
// prod product list. It needs to appear in the prod product list
List<StockMoveLine> stockMoveLineMissingProductList = stockMoveLineList.stream().filter(stockMoveLine1 -> stockMoveLine1.getProduct() != null).filter(stockMoveLine1 -> !prodProductList.stream().map(ProdProduct::getProduct).collect(Collectors.toList()).contains(stockMoveLine1.getProduct())).collect(Collectors.toList());
for (StockMoveLine stockMoveLine : stockMoveLineMissingProductList) {
if (stockMoveLine.getQty().compareTo(BigDecimal.ZERO) != 0) {
ProdProduct diffProdProduct = new ProdProduct();
diffProdProduct.setQty(stockMoveLine.getQty());
diffProdProduct.setPlannedQty(BigDecimal.ZERO);
diffProdProduct.setRealQty(stockMoveLine.getQty());
diffProdProduct.setProduct(stockMoveLine.getProduct());
diffProdProduct.setUnit(stockMoveLine.getUnit());
diffConsumeList.add(diffProdProduct);
}
}
return diffConsumeList;
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class CostSheetServiceImpl method computeRealResidualProduct.
protected void computeRealResidualProduct(ManufOrder manufOrder) throws AxelorException {
for (StockMoveLine stockMoveLine : manufOrder.getProducedStockMoveLineList()) {
if (stockMoveLine.getProduct() != null && manufOrder.getProduct() != null && (!stockMoveLine.getProduct().equals(manufOrder.getProduct()))) {
CostSheetLine costSheetLine = costSheetLineService.createResidualProductCostSheetLine(stockMoveLine.getProduct(), stockMoveLine.getUnit(), stockMoveLine.getRealQty(), manufOrder.getCompany());
costSheet.addCostSheetLineListItem(costSheetLine);
}
}
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class ReservedQtyServiceImpl method updateReservedQuantity.
@Override
public void updateReservedQuantity(StockMove stockMove, int status) throws AxelorException {
List<StockMoveLine> stockMoveLineList = stockMove.getStockMoveLineList();
if (stockMoveLineList != null) {
stockMoveLineList = stockMoveLineList.stream().filter(smLine -> smLine.getProduct() != null && smLine.getProduct().getStockManaged()).collect(Collectors.toList());
// check quantities in stock move lines
for (StockMoveLine stockMoveLine : stockMoveLineList) {
if (status == StockMoveRepository.STATUS_PLANNED) {
changeRequestedQtyLowerThanQty(stockMoveLine);
}
checkRequestedAndReservedQty(stockMoveLine);
}
if (status == StockMoveRepository.STATUS_REALIZED) {
consolidateReservedQtyInStockMoveLineByProduct(stockMove);
}
stockMoveLineList.sort(Comparator.comparing(StockMoveLine::getId));
for (StockMoveLine stockMoveLine : stockMoveLineList) {
BigDecimal qty = stockMoveLine.getRealQty();
// requested quantity is quantity requested is the line subtracted by the quantity already
// allocated
BigDecimal requestedReservedQty = stockMoveLine.getRequestedReservedQty().subtract(stockMoveLine.getReservedQty());
updateRequestedQuantityInLocations(stockMoveLine, stockMove.getFromStockLocation(), stockMove.getToStockLocation(), stockMoveLine.getProduct(), qty, requestedReservedQty, status);
}
}
}
use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.
the class ReservedQtyServiceImpl method allocateReservedQuantityInSaleOrderLines.
/**
* The new parameter allocated stock move line is used if we are allocating a stock move line.
* This method will reallocate the lines with the same stock move (and the same product) before
* other stock move lines.
*
* <p>We are using an optional because in the basic use of the method, the argument is empty.
*/
protected BigDecimal allocateReservedQuantityInSaleOrderLines(BigDecimal qtyToAllocate, StockLocation stockLocation, Product product, Unit stockLocationLineUnit, Optional<StockMoveLine> allocatedStockMoveLine) throws AxelorException {
List<StockMoveLine> stockMoveLineListToAllocate = stockMoveLineRepository.all().filter("self.stockMove.fromStockLocation.id = :stockLocationId " + "AND self.product.id = :productId " + "AND self.stockMove.statusSelect = :planned " + "AND self.reservationDateTime IS NOT NULL " + "AND self.reservedQty < self.requestedReservedQty").bind("stockLocationId", stockLocation.getId()).bind("productId", product.getId()).bind("planned", StockMoveRepository.STATUS_PLANNED).order("reservationDateTime").order("stockMove.estimatedDate").fetch();
// put stock move lines with the same stock move on the beginning of the list.
allocatedStockMoveLine.ifPresent(stockMoveLine -> stockMoveLineListToAllocate.sort(// Note: this comparator imposes orderings that are inconsistent with equals.
(sml1, sml2) -> {
if (sml1.getStockMove().equals(sml2.getStockMove())) {
return 0;
} else if (sml1.getStockMove().equals(stockMoveLine.getStockMove())) {
return -1;
} else if (sml2.getStockMove().equals(stockMoveLine.getStockMove())) {
return 1;
} else {
return 0;
}
}));
BigDecimal leftQtyToAllocate = qtyToAllocate;
for (StockMoveLine stockMoveLine : stockMoveLineListToAllocate) {
BigDecimal leftQtyToAllocateStockMove = convertUnitWithProduct(stockLocationLineUnit, stockMoveLine.getUnit(), leftQtyToAllocate, product);
BigDecimal neededQtyToAllocate = stockMoveLine.getRequestedReservedQty().subtract(stockMoveLine.getReservedQty());
BigDecimal allocatedStockMoveQty = leftQtyToAllocateStockMove.min(neededQtyToAllocate);
BigDecimal allocatedQty = convertUnitWithProduct(stockMoveLine.getUnit(), stockLocationLineUnit, allocatedStockMoveQty, product);
// update reserved qty in stock move line and sale order line
updateReservedQuantityFromStockMoveLine(stockMoveLine, product, allocatedStockMoveQty);
// update left qty to allocate
leftQtyToAllocate = leftQtyToAllocate.subtract(allocatedQty);
}
return qtyToAllocate.subtract(leftQtyToAllocate);
}
Aggregations