Search in sources :

Example 1 with MrpLineType

use of com.axelor.apps.supplychain.db.MrpLineType in project axelor-open-suite by axelor.

the class MrpServiceImpl method createSaleForecastMrpLines.

protected void createSaleForecastMrpLines() throws AxelorException {
    MrpLineType saleForecastMrpLineType = this.getMrpLineType(MrpLineTypeRepository.ELEMENT_SALE_FORECAST);
    if (saleForecastMrpLineType == null) {
        return;
    }
    List<MrpForecast> mrpForecastList = new ArrayList<>();
    mrp = mrpRepository.find(mrp.getId());
    if (mrp.getMrpForecastSet().isEmpty()) {
        mrpForecastList.addAll(mrpForecastRepository.all().filter("self.product.id in (?1) AND self.stockLocation in (?2) AND self.forecastDate >= ?3 AND self.statusSelect = ?4", this.productMap.keySet(), this.stockLocationList, today, MrpForecastRepository.STATUS_CONFIRMED).fetch());
    } else {
        mrpForecastList.addAll(mrp.getMrpForecastSet());
    }
    for (MrpForecast mrpForecast : mrpForecastList) {
        this.createSaleForecastMrpLines(mrpRepository.find(mrp.getId()), mrpForecastRepository.find(mrpForecast.getId()), mrpLineTypeRepository.find(saleForecastMrpLineType.getId()));
        JPA.clear();
    }
}
Also used : ArrayList(java.util.ArrayList) MrpLineType(com.axelor.apps.supplychain.db.MrpLineType) MrpForecast(com.axelor.apps.supplychain.db.MrpForecast)

Example 2 with MrpLineType

use of com.axelor.apps.supplychain.db.MrpLineType in project axelor-open-suite by axelor.

the class MrpServiceImpl method createSaleOrderMrpLines.

protected void createSaleOrderMrpLines() throws AxelorException {
    MrpLineType saleOrderMrpLineType = this.getMrpLineType(MrpLineTypeRepository.ELEMENT_SALE_ORDER);
    if (saleOrderMrpLineType == null) {
        return;
    }
    String statusSelect = saleOrderMrpLineType.getStatusSelect();
    List<Integer> statusList = StringTool.getIntegerList(statusSelect);
    List<SaleOrderLine> saleOrderLineList = new ArrayList<>();
    mrp = mrpRepository.find(mrp.getId());
    if (mrp.getSaleOrderLineSet().isEmpty()) {
        saleOrderLineList.addAll(saleOrderLineRepository.all().filter("self.product.id in (?1) AND self.saleOrder.stockLocation in (?2) AND self.deliveryState != ?3 " + "AND self.saleOrder.statusSelect IN (?4)", this.productMap.keySet(), this.stockLocationList, SaleOrderLineRepository.DELIVERY_STATE_DELIVERED, statusList).fetch());
    } else {
        saleOrderLineList.addAll(mrp.getSaleOrderLineSet());
    }
    for (SaleOrderLine saleOrderLine : saleOrderLineList) {
        this.createSaleOrderMrpLines(mrpRepository.find(mrp.getId()), saleOrderLineRepository.find(saleOrderLine.getId()), mrpLineTypeRepository.find(saleOrderMrpLineType.getId()), statusList);
        JPA.clear();
    }
}
Also used : ArrayList(java.util.ArrayList) MrpLineType(com.axelor.apps.supplychain.db.MrpLineType) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine)

Example 3 with MrpLineType

use of com.axelor.apps.supplychain.db.MrpLineType in project axelor-open-suite by axelor.

the class MrpServiceProductionImpl method createAvailableStockMrpLine.

protected void createAvailableStockMrpLine(Product product, StockLocation stockLocation) throws AxelorException {
    MrpLineType availableStockMrpLineType = this.getMrpLineType(MrpLineTypeRepository.ELEMENT_AVAILABLE_STOCK);
    if (availableStockMrpLineType == null) {
        return;
    }
    mrpLineRepository.save(this.createAvailableStockMrpLine(mrpRepository.find(mrp.getId()), productRepository.find(product.getId()), stockLocation, availableStockMrpLineType));
}
Also used : MrpLineType(com.axelor.apps.supplychain.db.MrpLineType)

Example 4 with MrpLineType

use of com.axelor.apps.supplychain.db.MrpLineType 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 5 with MrpLineType

use of com.axelor.apps.supplychain.db.MrpLineType in project axelor-open-suite by axelor.

the class MrpServiceImpl method createPurchaseMrpLines.

protected void createPurchaseMrpLines() throws AxelorException {
    MrpLineType purchaseOrderMrpLineType = this.getMrpLineType(MrpLineTypeRepository.ELEMENT_PURCHASE_ORDER);
    if (purchaseOrderMrpLineType == null) {
        return;
    }
    String statusSelect = purchaseOrderMrpLineType.getStatusSelect();
    List<Integer> statusList = StringTool.getIntegerList(statusSelect);
    if (statusList.isEmpty()) {
        statusList.add(PurchaseOrderRepository.STATUS_VALIDATED);
    }
    // TODO : Manage the case where order is partially delivered
    List<PurchaseOrderLine> purchaseOrderLineList = purchaseOrderLineRepository.all().filter("self.product.id in (?1) AND self.purchaseOrder.stockLocation in (?2) AND self.receiptState != ?3 " + "AND self.purchaseOrder.statusSelect IN (?4)", this.productMap.keySet(), this.stockLocationList, PurchaseOrderRepository.STATE_RECEIVED, statusList).fetch();
    for (PurchaseOrderLine purchaseOrderLine : purchaseOrderLineList) {
        this.createPurchaseMrpLines(mrpRepository.find(mrp.getId()), purchaseOrderLineRepository.find(purchaseOrderLine.getId()), mrpLineTypeRepository.find(purchaseOrderMrpLineType.getId()));
        JPA.clear();
    }
}
Also used : PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) MrpLineType(com.axelor.apps.supplychain.db.MrpLineType)

Aggregations

MrpLineType (com.axelor.apps.supplychain.db.MrpLineType)9 ArrayList (java.util.ArrayList)3 MrpLine (com.axelor.apps.supplychain.db.MrpLine)2 Transactional (com.google.inject.persist.Transactional)2 Company (com.axelor.apps.base.db.Company)1 Product (com.axelor.apps.base.db.Product)1 BillOfMaterial (com.axelor.apps.production.db.BillOfMaterial)1 ManufOrder (com.axelor.apps.production.db.ManufOrder)1 ProdProduct (com.axelor.apps.production.db.ProdProduct)1 PurchaseOrderLine (com.axelor.apps.purchase.db.PurchaseOrderLine)1 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)1 StockLocation (com.axelor.apps.stock.db.StockLocation)1 StockRules (com.axelor.apps.stock.db.StockRules)1 MrpForecast (com.axelor.apps.supplychain.db.MrpForecast)1 BigDecimal (java.math.BigDecimal)1 List (java.util.List)1