use of com.axelor.apps.base.db.CancelReason in project axelor-open-suite by axelor.
the class SaleOrderServiceSupplychainImpl method enableEditOrder.
@Override
@Transactional(rollbackOn = { Exception.class })
public boolean enableEditOrder(SaleOrder saleOrder) throws AxelorException {
boolean checkAvailabiltyRequest = super.enableEditOrder(saleOrder);
if (!Beans.get(AppSupplychainService.class).isApp("supplychain")) {
return checkAvailabiltyRequest;
}
List<StockMove> allStockMoves = Beans.get(StockMoveRepository.class).findAllBySaleOrderAndStatus(StockMoveRepository.ORIGIN_SALE_ORDER, saleOrder.getId(), StockMoveRepository.STATUS_PLANNED).fetch();
List<StockMove> stockMoves = !allStockMoves.isEmpty() ? allStockMoves.stream().filter(stockMove -> !stockMove.getAvailabilityRequest()).collect(Collectors.toList()) : allStockMoves;
checkAvailabiltyRequest = stockMoves.size() != allStockMoves.size() ? true : checkAvailabiltyRequest;
if (!stockMoves.isEmpty()) {
StockMoveService stockMoveService = Beans.get(StockMoveService.class);
CancelReason cancelReason = appSupplychain.getCancelReasonOnChangingSaleOrder();
if (cancelReason == null) {
throw new AxelorException(appSupplychain, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, IExceptionMessage.SUPPLYCHAIN_MISSING_CANCEL_REASON_ON_CHANGING_SALE_ORDER);
}
for (StockMove stockMove : stockMoves) {
stockMoveService.cancel(stockMove, cancelReason);
stockMove.setArchived(true);
for (StockMoveLine stockMoveline : stockMove.getStockMoveLineList()) {
stockMoveline.setSaleOrderLine(null);
stockMoveline.setArchived(true);
}
}
}
return checkAvailabiltyRequest;
}
Aggregations