Search in sources :

Example 76 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class StockMoveLineController method deallocateAll.

/**
 * Called from stock move form view, on clicking allocateAll button on one stock move line. Call
 * {@link ReservedQtyService#updateReservedQty(stockMoveLine, BigDecimal.ZERO)}.
 *
 * @param request
 * @param response
 */
public void deallocateAll(ActionRequest request, ActionResponse response) {
    try {
        StockMoveLine stockMoveLine = request.getContext().asType(StockMoveLine.class);
        stockMoveLine = Beans.get(StockMoveLineRepository.class).find(stockMoveLine.getId());
        Beans.get(ReservedQtyService.class).updateReservedQty(stockMoveLine, BigDecimal.ZERO);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : ReservedQtyService(com.axelor.apps.supplychain.service.ReservedQtyService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) AxelorException(com.axelor.exception.AxelorException)

Example 77 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class StockMoveLineController method cancelReservation.

/**
 * Called from stock move line form view, on request qty click. Call {@link
 * ReservedQtyService#cancelReservation(StockMoveLine)}.
 *
 * @param request
 * @param response
 */
public void cancelReservation(ActionRequest request, ActionResponse response) {
    try {
        StockMoveLine stockMoveLine = request.getContext().asType(StockMoveLine.class);
        stockMoveLine = Beans.get(StockMoveLineRepository.class).find(stockMoveLine.getId());
        Product product = stockMoveLine.getProduct();
        if (product == null || !product.getStockManaged()) {
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_PRODUCT_NOT_STOCK_MANAGED));
        }
        Beans.get(ReservedQtyService.class).cancelReservation(stockMoveLine);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ReservedQtyService(com.axelor.apps.supplychain.service.ReservedQtyService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product) AxelorException(com.axelor.exception.AxelorException)

Example 78 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class StockMoveLineController method requestQty.

/**
 * Called from stock move line form view, on request qty click. Call {@link
 * ReservedQtyService#requestQty(StockMoveLine)}.
 *
 * @param request
 * @param response
 */
public void requestQty(ActionRequest request, ActionResponse response) {
    try {
        StockMoveLine stockMoveLine = request.getContext().asType(StockMoveLine.class);
        stockMoveLine = Beans.get(StockMoveLineRepository.class).find(stockMoveLine.getId());
        Product product = stockMoveLine.getProduct();
        if (product == null || !product.getStockManaged()) {
            throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.SALE_ORDER_LINE_PRODUCT_NOT_STOCK_MANAGED));
        }
        Beans.get(ReservedQtyService.class).requestQty(stockMoveLine);
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ReservedQtyService(com.axelor.apps.supplychain.service.ReservedQtyService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product) AxelorException(com.axelor.exception.AxelorException)

Example 79 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine 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)

Example 80 with StockMoveLine

use of com.axelor.apps.stock.db.StockMoveLine in project axelor-open-suite by axelor.

the class SaleOrderStockServiceImpl method setReservationDateTime.

/**
 * Fill reservation date time in stock move lines with sale order following supplychain
 * configuration.
 *
 * @param stockMove
 * @param saleOrder
 */
protected void setReservationDateTime(StockMove stockMove, SaleOrder saleOrder) throws AxelorException {
    SupplyChainConfig supplyChainConfig = supplyChainConfigService.getSupplyChainConfig(saleOrder.getCompany());
    List<StockMoveLine> stockMoveLineList = stockMove.getStockMoveLineList();
    if (stockMoveLineList == null) {
        stockMoveLineList = new ArrayList<>();
    }
    for (StockMoveLine stockMoveLine : stockMoveLineList) {
        LocalDateTime reservationDateTime;
        switch(supplyChainConfig.getSaleOrderReservationDateSelect()) {
            case SupplyChainConfigRepository.SALE_ORDER_CONFIRMATION_DATE:
                reservationDateTime = saleOrder.getConfirmationDateTime();
                break;
            case SupplyChainConfigRepository.SALE_ORDER_SHIPPING_DATE:
                SaleOrderLine saleOrderLine = stockMoveLine.getSaleOrderLine();
                if (saleOrderLine == null || saleOrderLine.getEstimatedDelivDate() == null) {
                    reservationDateTime = null;
                } else {
                    reservationDateTime = saleOrderLine.getEstimatedDelivDate().atStartOfDay();
                }
                break;
            default:
                throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.RESERVATION_SALE_ORDER_DATE_CONFIG_INCORRECT_VALUE));
        }
        if (reservationDateTime == null) {
            reservationDateTime = Beans.get(AppBaseService.class).getTodayDateTime().toLocalDateTime();
        }
        stockMoveLine.setReservationDateTime(reservationDateTime);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) AxelorException(com.axelor.exception.AxelorException) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) SupplyChainConfig(com.axelor.apps.supplychain.db.SupplyChainConfig) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Aggregations

StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)121 BigDecimal (java.math.BigDecimal)59 StockMove (com.axelor.apps.stock.db.StockMove)44 AxelorException (com.axelor.exception.AxelorException)41 Product (com.axelor.apps.base.db.Product)33 Transactional (com.google.inject.persist.Transactional)31 ArrayList (java.util.ArrayList)28 List (java.util.List)18 Company (com.axelor.apps.base.db.Company)16 StockMoveRepository (com.axelor.apps.stock.db.repo.StockMoveRepository)16 StockLocation (com.axelor.apps.stock.db.StockLocation)14 StockMoveLineService (com.axelor.apps.stock.service.StockMoveLineService)14 Unit (com.axelor.apps.base.db.Unit)13 Beans (com.axelor.inject.Beans)13 ProdProduct (com.axelor.apps.production.db.ProdProduct)12 StockMoveService (com.axelor.apps.stock.service.StockMoveService)12 I18n (com.axelor.i18n.I18n)12 Inject (com.google.inject.Inject)12 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)10 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)10