Search in sources :

Example 6 with MrpLineType

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

the class MrpServiceImpl method consolidateMrp.

protected void consolidateMrp() {
    List<MrpLine> mrpLineList = mrpLineRepository.all().filter("self.mrp.id = ?1", mrp.getId()).order("product.code").order("maturityDate").order("mrpLineType.typeSelect").order("mrpLineType.sequence").order("id").fetch();
    Map<List<Object>, MrpLine> map = Maps.newHashMap();
    MrpLine consolidateMrpLine = null;
    List<Object> keys = new ArrayList<>();
    for (MrpLine mrpLine : mrpLineList) {
        MrpLineType mrpLineType = mrpLine.getMrpLineType();
        keys.clear();
        keys.add(mrpLineType);
        keys.add(mrpLine.getProduct());
        keys.add(mrpLine.getMaturityDate());
        keys.add(mrpLine.getStockLocation());
        if (map.containsKey(keys)) {
            consolidateMrpLine = map.get(keys);
            consolidateMrpLine.setQty(consolidateMrpLine.getQty().add(mrpLine.getQty()));
            consolidateMrpLine.setCumulativeQty(consolidateMrpLine.getCumulativeQty().add(mrpLine.getCumulativeQty()));
            mrpLineRepository.remove(mrpLine);
        } else {
            map.put(keys, mrpLine);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) MrpLine(com.axelor.apps.supplychain.db.MrpLine) List(java.util.List) ArrayList(java.util.ArrayList) MrpLineType(com.axelor.apps.supplychain.db.MrpLineType)

Example 7 with MrpLineType

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

the class MrpServiceProductionImpl method createMPSLines.

protected void createMPSLines() throws AxelorException {
    MrpLineType mpsNeedMrpLineType = this.getMrpLineType(MrpLineTypeRepository.ELEMENT_MASTER_PRODUCTION_SCHEDULING);
    if (mpsNeedMrpLineType == null || mrp.getMrpTypeSelect() != MrpRepository.MRP_TYPE_MRP) {
        return;
    }
    List<MrpLine> mpsMrpLineList = mrpLineRepository.all().filter("self.product.id in (?1) AND self.stockLocation in (?2) AND self.mrp.mrpTypeSelect = ?3 " + "AND self.mrp.statusSelect = ?4 AND self.mrpLineType.elementSelect = ?5 AND self.maturityDate >= ?6 AND (?7 is true OR self.maturityDate <= ?8)", this.productMap.keySet(), this.stockLocationList, MrpRepository.MRP_TYPE_MPS, MrpRepository.STATUS_CALCULATION_ENDED, MrpLineTypeRepository.ELEMENT_MASTER_PRODUCTION_SCHEDULING, today.atStartOfDay(), mrp.getEndDate() == null, mrp.getEndDate()).fetch();
    for (MrpLine mpsMrpLine : mpsMrpLineList) {
        this.createMpsMrpLines(mrpRepository.find(mrp.getId()), mrpLineRepository.find(mpsMrpLine.getId()), mrpLineTypeRepository.find(mpsNeedMrpLineType.getId()));
        JPA.clear();
    }
}
Also used : MrpLine(com.axelor.apps.supplychain.db.MrpLine) MrpLineType(com.axelor.apps.supplychain.db.MrpLineType)

Example 8 with MrpLineType

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

the class MrpServiceProductionImpl method createManufOrderMrpLines.

// Manufacturing order AND manufacturing order need
protected void createManufOrderMrpLines() throws AxelorException {
    MrpLineType manufOrderMrpLineType = this.getMrpLineType(MrpLineTypeRepository.ELEMENT_MANUFACTURING_ORDER);
    if (manufOrderMrpLineType == null) {
        return;
    }
    MrpLineType manufOrderNeedMrpLineType = this.getMrpLineType(MrpLineTypeRepository.ELEMENT_MANUFACTURING_ORDER_NEED);
    String statusSelect = manufOrderMrpLineType.getStatusSelect();
    List<Integer> statusList = StringTool.getIntegerList(statusSelect);
    if (statusList.isEmpty()) {
        statusList.add(ManufOrderRepository.STATUS_FINISHED);
    }
    List<ManufOrder> manufOrderList = manufOrderRepository.all().filter("self.product.id in (?1) AND self.prodProcess.stockLocation in (?2) " + "AND self.statusSelect IN (?3)", this.productMap.keySet(), this.stockLocationList, statusList).fetch();
    for (ManufOrder manufOrder : manufOrderList) {
        this.createManufOrderMrpLines(mrpRepository.find(mrp.getId()), manufOrderRepository.find(manufOrder.getId()), mrpLineTypeRepository.find(manufOrderMrpLineType.getId()), mrpLineTypeRepository.find(manufOrderNeedMrpLineType.getId()));
        JPA.clear();
    }
}
Also used : MrpLineType(com.axelor.apps.supplychain.db.MrpLineType) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 9 with MrpLineType

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

the class MrpServiceProductionImpl method createProposalMrpLine.

@Override
@Transactional(rollbackOn = { Exception.class })
protected void createProposalMrpLine(Mrp mrp, Product product, MrpLineType mrpLineType, BigDecimal reorderQty, StockLocation stockLocation, LocalDate maturityDate, List<MrpLineOrigin> mrpLineOriginList, String relatedToSelectName) throws AxelorException {
    super.createProposalMrpLine(mrp, product, mrpLineType, reorderQty, stockLocation, maturityDate, mrpLineOriginList, relatedToSelectName);
    if (!Beans.get(AppProductionService.class).isApp("production")) {
        return;
    }
    BillOfMaterial defaultBillOfMaterial = product.getDefaultBillOfMaterial();
    if (mrpLineType.getElementSelect() == MrpLineTypeRepository.ELEMENT_MANUFACTURING_PROPOSAL && defaultBillOfMaterial != null) {
        MrpLineType manufProposalNeedMrpLineType = this.getMrpLineType(MrpLineTypeRepository.ELEMENT_MANUFACTURING_PROPOSAL_NEED);
        if (manufProposalNeedMrpLineType == null) {
            return;
        }
        for (BillOfMaterial billOfMaterial : defaultBillOfMaterial.getBillOfMaterialSet()) {
            Product subProduct = billOfMaterial.getProduct();
            if (this.isMrpProduct(subProduct)) {
                // TODO take the time to do the Manuf order (use machine planning)
                super.createProposalMrpLine(mrp, subProduct, manufProposalNeedMrpLineType, reorderQty.multiply(billOfMaterial.getQty()).setScale(appBaseService.getNbDecimalDigitForQty(), RoundingMode.HALF_UP), stockLocation, maturityDate, mrpLineOriginList, relatedToSelectName);
            }
        }
    }
}
Also used : BillOfMaterial(com.axelor.apps.production.db.BillOfMaterial) Product(com.axelor.apps.base.db.Product) ProdProduct(com.axelor.apps.production.db.ProdProduct) MrpLineType(com.axelor.apps.supplychain.db.MrpLineType) Transactional(com.google.inject.persist.Transactional)

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