Search in sources :

Example 1 with CancelReason

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;
}
Also used : AxelorException(com.axelor.exception.AxelorException) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveService(com.axelor.apps.stock.service.StockMoveService) CancelReason(com.axelor.apps.base.db.CancelReason) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Transactional(com.google.inject.persist.Transactional)

Aggregations

CancelReason (com.axelor.apps.base.db.CancelReason)1 StockMove (com.axelor.apps.stock.db.StockMove)1 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)1 StockMoveService (com.axelor.apps.stock.service.StockMoveService)1 AxelorException (com.axelor.exception.AxelorException)1 Transactional (com.google.inject.persist.Transactional)1