Search in sources :

Example 6 with StockRules

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

the class MrpServiceImpl method checkInsufficientCumulativeQty.

@Transactional(rollbackOn = { Exception.class })
protected boolean checkInsufficientCumulativeQty(MrpLine mrpLine, Product product, boolean firstPass) throws AxelorException {
    BigDecimal cumulativeQty = mrpLine.getCumulativeQty();
    MrpLineType mrpLineType = mrpLine.getMrpLineType();
    boolean isProposalElement = this.isProposalElement(mrpLineType);
    BigDecimal minQty = mrpLine.getMinQty();
    if ((((mrpLine.getMrpLineType().getElementSelect() != MrpLineTypeRepository.ELEMENT_AVAILABLE_STOCK) && (!isProposalElement || mrpLineType.getTypeSelect() == MrpLineTypeRepository.TYPE_OUT)) || (mrpLine.getMrpLineType().getElementSelect() == MrpLineTypeRepository.ELEMENT_AVAILABLE_STOCK && firstPass)) && cumulativeQty.compareTo(mrpLine.getMinQty()) < 0) {
        Company company = null;
        StockLocation stockLocation = mrpLine.getStockLocation();
        log.debug("Cumulative qty ({} < {}) is insufficient for product ({}) at the maturity date ({})", cumulativeQty, minQty, product.getFullName(), mrpLine.getMaturityDate());
        BigDecimal reorderQty = minQty.subtract(cumulativeQty);
        StockRules stockRules = stockRulesService.getStockRules(product, stockLocation, StockRulesRepository.TYPE_FUTURE, StockRulesRepository.USE_CASE_USED_FOR_MRP);
        if (stockRules != null) {
            reorderQty = reorderQty.max(stockRules.getReOrderQty());
        }
        if (stockLocation.getCompany() != null) {
            company = stockLocation.getCompany();
        }
        MrpLineType mrpLineTypeProposal = this.getMrpLineTypeForProposal(stockRules, product, company);
        if (mrpLineTypeProposal == null) {
            return false;
        }
        long duplicateCount = mrpLineRepository.all().filter("self.mrp.id = ?1  AND self.isEditedByUser = ?2 AND self.product = ?3 AND self.relatedToSelectName = ?4", mrp.getId(), true, product, mrpLine.getRelatedToSelectName()).count();
        if (duplicateCount != 0) {
            return false;
        }
        this.createProposalMrpLine(mrpLine.getMrp(), product, mrpLineTypeProposal, reorderQty, stockLocation, mrpLine.getMaturityDate(), mrpLine.getMrpLineOriginList(), mrpLine.getRelatedToSelectName());
        return true;
    }
    return false;
}
Also used : Company(com.axelor.apps.base.db.Company) StockLocation(com.axelor.apps.stock.db.StockLocation) MrpLineType(com.axelor.apps.supplychain.db.MrpLineType) BigDecimal(java.math.BigDecimal) StockRules(com.axelor.apps.stock.db.StockRules) Transactional(com.google.inject.persist.Transactional)

Example 7 with StockRules

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

the class StockRulesServiceProductionImpl method generateOrder.

public void generateOrder(Product product, BigDecimal qty, StockLocationLine stockLocationLine, int type) throws AxelorException {
    StockLocation stockLocation = stockLocationLine.getStockLocation();
    if (stockLocation == null) {
        return;
    }
    StockRules stockRules = this.getStockRules(product, stockLocation, type, StockRulesRepository.USE_CASE_STOCK_CONTROL);
    if (stockRules == null) {
        return;
    }
    if (stockRules.getOrderAlertSelect().equals(StockRulesRepository.ORDER_ALERT_PRODUCTION_ORDER)) {
        this.generateProductionOrder(product, qty, stockLocationLine, type, stockRules);
    } else {
        this.generatePurchaseOrder(product, qty, stockLocationLine, type);
    }
}
Also used : StockLocation(com.axelor.apps.stock.db.StockLocation) StockRules(com.axelor.apps.stock.db.StockRules)

Aggregations

StockRules (com.axelor.apps.stock.db.StockRules)7 StockLocation (com.axelor.apps.stock.db.StockLocation)5 Transactional (com.google.inject.persist.Transactional)3 Company (com.axelor.apps.base.db.Company)2 BigDecimal (java.math.BigDecimal)2 Partner (com.axelor.apps.base.db.Partner)1 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)1 StockLocationLine (com.axelor.apps.stock.db.StockLocationLine)1 StockLocationLineRepository (com.axelor.apps.stock.db.repo.StockLocationLineRepository)1 StockRulesRepository (com.axelor.apps.stock.db.repo.StockRulesRepository)1 MrpLineType (com.axelor.apps.supplychain.db.MrpLineType)1 AxelorException (com.axelor.exception.AxelorException)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1