Hey everyone,
I’m trying to set the field purchase_order_line when spliting a StockMove in two part.
For that, I’m editing the splitInto2 function of com.axelor.apps.stock.service.StockMoveServiceImpl
Here is my code :
public StockMove splitInto2(
StockMove originalStockMove, List<StockMoveLine> modifiedStockMoveLines)
throws AxelorException {
// Copy this stock move
StockMove newStockMove = stockMoveRepo.copy(originalStockMove, false);
newStockMove.setStockMoveLineList(new ArrayList<>());
// Clement - 20/11/20 - In copy OriginTypeSelect set null
newStockMove.setOriginTypeSelect(originalStockMove.getOriginTypeSelect());
modifiedStockMoveLines =
modifiedStockMoveLines
.stream()
.filter(stockMoveLine -> stockMoveLine.getQty().compareTo(BigDecimal.ZERO) != 0)
.collect(Collectors.toList());
for (StockMoveLine moveLine : modifiedStockMoveLines) {
StockMoveLine newStockMoveLine;
// Set quantity in new stock move line
newStockMoveLine = stockMoveLineRepo.copy(moveLine, false);
newStockMoveLine.setQty(moveLine.getQty());
newStockMoveLine.setRealQty(moveLine.getQty());
//Clement - 08/04/21
newStockMoveLine.setPurchaseOrderLine(moveLine.getPurchaseOrderLine());
newStockMoveLine.setSaleOrderLine(moveLine.getSaleOrderLine());
//Fin Clement
// add stock move line
newStockMove.addStockMoveLineListItem(newStockMoveLine);
// find the original move line to update it
Optional<StockMoveLine> correspondingMoveLine =
originalStockMove
.getStockMoveLineList()
.stream()
.filter(stockMoveLine -> stockMoveLine.getId().equals(moveLine.getId()))
.findFirst();
if (BigDecimal.ZERO.compareTo(moveLine.getQty()) > 0
|| (correspondingMoveLine.isPresent()
&& moveLine.getQty().compareTo(correspondingMoveLine.get().getRealQty()) > 0)) {
throw new AxelorException(
TraceBackRepository.CATEGORY_INCONSISTENCY,
I18n.get(IExceptionMessage.STOCK_MOVE_16),
originalStockMove);
}
if (correspondingMoveLine.isPresent()) {
// Update quantity in original stock move.
// If the remaining quantity is 0, remove the stock move line
BigDecimal remainingQty = correspondingMoveLine.get().getQty().subtract(moveLine.getQty());
if (BigDecimal.ZERO.compareTo(remainingQty) == 0) {
// Remove the stock move line
originalStockMove.removeStockMoveLineListItem(correspondingMoveLine.get());
} else {
correspondingMoveLine.get().setQty(remainingQty);
correspondingMoveLine.get().setRealQty(remainingQty);
}
}
}
if (!newStockMove.getStockMoveLineList().isEmpty()) {
newStockMove.setExTaxTotal(stockMoveToolService.compute(newStockMove));
originalStockMove.setExTaxTotal(stockMoveToolService.compute(originalStockMove));
return stockMoveRepo.save(newStockMove);
} else {
return null;
}
}
During Compilation, I got the following error on the line I added : cannot find symbol. symbol: method getPurchaseOrderLine()
location: variable moveLine of type StockMoveLine
My code is surrounded by « //Clement - 08/04/21 » and « //Fin Clement »
I can’t understand why because I saw this method is used in others classes.
Does somebody know why ?
I’m working on axelor 5.2