Search in sources :

Example 31 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class StockMoveLineServiceImpl method checkExpirationDates.

@Override
public void checkExpirationDates(StockMove stockMove) throws AxelorException {
    List<String> errorList = new ArrayList<>();
    for (StockMoveLine stockMoveLine : stockMove.getStockMoveLineList()) {
        TrackingNumber trackingNumber = stockMoveLine.getTrackingNumber();
        if (trackingNumber == null) {
            continue;
        }
        Product product = trackingNumber.getProduct();
        if (product == null || !product.getCheckExpirationDateAtStockMoveRealization()) {
            continue;
        }
        if (product.getHasWarranty() && trackingNumber.getWarrantyExpirationDate().isBefore(appBaseService.getTodayDate(stockMove.getCompany())) || product.getIsPerishable() && trackingNumber.getPerishableExpirationDate().isBefore(appBaseService.getTodayDate(stockMove.getCompany()))) {
            errorList.add(product.getName());
        }
    }
    if (!errorList.isEmpty()) {
        String errorStr = errorList.stream().collect(Collectors.joining(", "));
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.STOCK_MOVE_LINE_EXPIRED_PRODUCTS), errorStr);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) ArrayList(java.util.ArrayList) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) Product(com.axelor.apps.base.db.Product)

Example 32 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class InventoryService method generateStockMoveLines.

/**
 * Generate lines for the given stock move. Depending if we are creating an incoming or outgoing
 * stock move, we only create stock move line with positive quantity.
 *
 * @param inventoryLine an inventory line
 * @param stockMove a stock move being created
 * @param isEnteringStock whether we are creating an incoming or outgoing stock move.
 * @throws AxelorException
 */
protected void generateStockMoveLines(InventoryLine inventoryLine, StockMove stockMove, boolean isEnteringStock) throws AxelorException {
    Product product = inventoryLine.getProduct();
    TrackingNumber trackingNumber = inventoryLine.getTrackingNumber();
    BigDecimal diff = inventoryLine.getRealQty().subtract(inventoryLine.getCurrentQty());
    if (!isEnteringStock) {
        diff = diff.negate();
    }
    if (diff.signum() > 0) {
        BigDecimal avgPrice;
        StockLocationLine stockLocationLine = stockLocationLineService.getStockLocationLine(stockMove.getToStockLocation(), product);
        if (stockLocationLine != null) {
            avgPrice = stockLocationLine.getAvgPrice();
        } else {
            avgPrice = BigDecimal.ZERO;
        }
        StockMoveLine stockMoveLine = stockMoveLineService.createStockMoveLine(product, product.getName(), product.getDescription(), diff, avgPrice, avgPrice, product.getUnit(), stockMove, StockMoveLineService.TYPE_NULL, false, BigDecimal.ZERO);
        if (stockMoveLine == null) {
            throw new AxelorException(inventoryLine.getInventory(), TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVENTORY_7) + " " + inventoryLine.getInventory().getInventorySeq());
        }
        if (trackingNumber != null && stockMoveLine.getTrackingNumber() == null) {
            stockMoveLine.setTrackingNumber(trackingNumber);
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) TrackingNumber(com.axelor.apps.stock.db.TrackingNumber) Product(com.axelor.apps.base.db.Product) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) BigDecimal(java.math.BigDecimal)

Example 33 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class StockLocationLineServiceImpl method computeFutureQty.

@Override
public BigDecimal computeFutureQty(StockLocationLine stockLocationLine) throws AxelorException {
    // future quantity is current quantity minus planned outgoing stock move lines plus planned
    // incoming stock move lines.
    Product product = stockLocationLine.getProduct();
    BigDecimal futureQty = stockLocationLine.getCurrentQty();
    List<StockMoveLine> incomingStockMoveLineList = findIncomingPlannedStockMoveLines(stockLocationLine);
    List<StockMoveLine> outgoingStockMoveLineList = findOutgoingPlannedStockMoveLines(stockLocationLine);
    if (stockLocationLine.getUnit() == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LOCATION_LINE_MISSING_UNIT), stockLocationLine.getStockLocation().getName(), product.getFullName());
    }
    for (StockMoveLine incomingStockMoveLine : incomingStockMoveLineList) {
        BigDecimal qtyToAdd = unitConversionService.convert(incomingStockMoveLine.getUnit(), stockLocationLine.getUnit(), incomingStockMoveLine.getRealQty(), incomingStockMoveLine.getRealQty().scale(), product);
        futureQty = futureQty.add(qtyToAdd);
    }
    for (StockMoveLine outgoingStockMoveLine : outgoingStockMoveLineList) {
        BigDecimal qtyToSubtract = unitConversionService.convert(outgoingStockMoveLine.getUnit(), stockLocationLine.getUnit(), outgoingStockMoveLine.getRealQty(), outgoingStockMoveLine.getRealQty().scale(), product);
        futureQty = futureQty.subtract(qtyToSubtract);
    }
    return futureQty;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Product(com.axelor.apps.base.db.Product) StockMoveLine(com.axelor.apps.stock.db.StockMoveLine) BigDecimal(java.math.BigDecimal)

Example 34 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class StockLocationLineServiceImpl method updateLocation.

@Override
@Transactional(rollbackOn = { Exception.class })
public void updateLocation(StockLocation stockLocation, Product product, Unit stockMoveLineUnit, BigDecimal qty, boolean current, boolean future, boolean isIncrement, LocalDate lastFutureStockMoveDate) throws AxelorException {
    StockLocationLine stockLocationLine = this.getOrCreateStockLocationLine(stockLocation, product);
    if (stockLocationLine == null) {
        return;
    }
    Unit stockLocationLineUnit = stockLocationLine.getUnit();
    if (stockLocationLineUnit == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LOCATION_LINE_MISSING_UNIT), stockLocation.getName(), product.getFullName());
    }
    if (!stockLocationLineUnit.equals(stockMoveLineUnit)) {
        qty = unitConversionService.convert(stockMoveLineUnit, stockLocationLineUnit, qty, qty.scale(), product);
    }
    LOG.debug("Mise à jour du stock : Entrepot? {}, Produit? {}, Quantité? {}, Actuel? {}, Futur? {}, Incrément? {}, Date? {} ", stockLocation.getName(), product.getCode(), qty, current, future, isIncrement, lastFutureStockMoveDate);
    if (!isIncrement) {
        minStockRules(product, qty, stockLocationLine, current, future);
    } else {
        maxStockRules(product, qty, stockLocationLine, current, future);
    }
    stockLocationLine = this.updateLocation(stockLocationLine, stockMoveLineUnit, product, qty, current, future, isIncrement, lastFutureStockMoveDate);
    this.checkStockMin(stockLocationLine, false);
    stockLocationLineRepo.save(stockLocationLine);
}
Also used : AxelorException(com.axelor.exception.AxelorException) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Unit(com.axelor.apps.base.db.Unit) Transactional(com.google.inject.persist.Transactional)

Example 35 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class StockLocationLineServiceImpl method updateDetailLocation.

@Override
@Transactional(rollbackOn = { Exception.class })
public void updateDetailLocation(StockLocation stockLocation, Product product, Unit stockMoveLineUnit, BigDecimal qty, boolean current, boolean future, boolean isIncrement, LocalDate lastFutureStockMoveDate, TrackingNumber trackingNumber) throws AxelorException {
    StockLocationLine detailLocationLine = this.getOrCreateDetailLocationLine(stockLocation, product, trackingNumber);
    if (detailLocationLine == null) {
        return;
    }
    Unit stockLocationLineUnit = detailLocationLine.getUnit();
    if (stockLocationLineUnit == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.DETAIL_LOCATION_LINE_MISSING_UNIT), trackingNumber.getTrackingNumberSeq(), stockLocation.getName(), product.getFullName());
    }
    if (!stockLocationLineUnit.equals(stockMoveLineUnit)) {
        qty = unitConversionService.convert(stockMoveLineUnit, stockLocationLineUnit, qty, qty.scale(), product);
    }
    LOG.debug("Mise à jour du detail du stock : Entrepot? {}, Produit? {}, Quantité? {}, Actuel? {}, Futur? {}, Incrément? {}, Date? {}, Num de suivi? {} ", stockLocation.getName(), product.getCode(), qty, current, future, isIncrement, lastFutureStockMoveDate, trackingNumber);
    detailLocationLine = this.updateLocation(detailLocationLine, stockMoveLineUnit, product, qty, current, future, isIncrement, lastFutureStockMoveDate);
    this.checkStockMin(detailLocationLine, true);
    stockLocationLineRepo.save(detailLocationLine);
}
Also used : AxelorException(com.axelor.exception.AxelorException) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Unit(com.axelor.apps.base.db.Unit) Transactional(com.google.inject.persist.Transactional)

Aggregations

AxelorException (com.axelor.exception.AxelorException)546 Transactional (com.google.inject.persist.Transactional)126 BigDecimal (java.math.BigDecimal)118 ArrayList (java.util.ArrayList)84 IOException (java.io.IOException)73 Product (com.axelor.apps.base.db.Product)64 Company (com.axelor.apps.base.db.Company)63 LocalDate (java.time.LocalDate)58 Partner (com.axelor.apps.base.db.Partner)48 List (java.util.List)45 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)40 HashMap (java.util.HashMap)38 Invoice (com.axelor.apps.account.db.Invoice)33 StockMove (com.axelor.apps.stock.db.StockMove)32 Map (java.util.Map)31 Beans (com.axelor.inject.Beans)30 I18n (com.axelor.i18n.I18n)28 Inject (com.google.inject.Inject)28 MoveLine (com.axelor.apps.account.db.MoveLine)27 Context (com.axelor.rpc.Context)27