Search in sources :

Example 16 with MrpLine

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

the class MrpLineController method toggleOne.

@Transactional(rollbackOn = { Exception.class })
public void toggleOne(ActionRequest request, ActionResponse response) {
    try {
        MrpLine mrpLine = request.getContext().asType(MrpLine.class);
        mrpLine = Beans.get(MrpLineRepository.class).find(mrpLine.getId());
        Beans.get(MrpLineService.class).updateProposalToProcess(mrpLine, !mrpLine.getProposalToProcess());
        response.setAttr("mrpLinePanel", "refresh", true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : MrpLineService(com.axelor.apps.supplychain.service.MrpLineService) MrpLine(com.axelor.apps.supplychain.db.MrpLine) AxelorException(com.axelor.exception.AxelorException) Transactional(com.google.inject.persist.Transactional)

Example 17 with MrpLine

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

the class ProjectedStockController method showChartProjectedStock.

public void showChartProjectedStock(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    List<Map<String, Object>> dataList = new ArrayList<>();
    @SuppressWarnings("unchecked") Collection<Map<String, Object>> contextMrpLineList = (Collection<Map<String, Object>>) context.get("_mrpLineListToProject");
    List<MrpLine> mrpLineList = contextMrpLineList.stream().map(map -> Mapper.toBean(MrpLine.class, map)).collect(Collectors.toList());
    if (!mrpLineList.isEmpty()) {
        List<MrpLine> mrpLineLastList = new ArrayList<>();
        MrpLine lastMrpLine = mrpLineList.get(0);
        for (int i = 1; i < mrpLineList.size(); ++i) {
            MrpLine mrpLine = mrpLineList.get(i);
            if (mrpLine.getMaturityDate().isAfter(lastMrpLine.getMaturityDate())) {
                mrpLineLastList.add(lastMrpLine);
            }
            lastMrpLine = mrpLine;
        }
        mrpLineLastList.add(lastMrpLine);
        lastMrpLine = mrpLineList.get(0);
        LocalDate mrpDate = lastMrpLine.getMaturityDate();
        for (MrpLine mrpLine : mrpLineLastList) {
            mrpDate = addInterElementForProjectedStockChart(dataList, lastMrpLine, mrpDate, mrpLine);
            Map<String, Object> dataMap = new HashMap<>();
            dataMap.put("name", mrpLine.getMaturityDate());
            dataMap.put("cumulativeQty", mrpLine.getCumulativeQty());
            dataList.add(dataMap);
            lastMrpLine = mrpLine;
        }
    }
    response.setData(dataList);
}
Also used : Context(com.axelor.rpc.Context) PurchaseOrderLine(com.axelor.apps.purchase.db.PurchaseOrderLine) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) ActionView(com.axelor.meta.schema.actions.ActionView) HashMap(java.util.HashMap) Mapper(com.axelor.db.mapper.Mapper) PurchaseOrderStockService(com.axelor.apps.supplychain.service.PurchaseOrderStockService) ArrayList(java.util.ArrayList) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) I18n(com.axelor.i18n.I18n) ActionRequest(com.axelor.rpc.ActionRequest) StockLocationLineService(com.axelor.apps.stock.service.StockLocationLineService) ProjectedStockService(com.axelor.apps.supplychain.service.ProjectedStockService) SaleOrderLineServiceSupplyChain(com.axelor.apps.supplychain.service.SaleOrderLineServiceSupplyChain) MrpLine(com.axelor.apps.supplychain.db.MrpLine) Collection(java.util.Collection) TraceBackService(com.axelor.exception.service.TraceBackService) Collectors(java.util.stream.Collectors) List(java.util.List) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) StockLocationLine(com.axelor.apps.stock.db.StockLocationLine) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) LocalDate(java.time.LocalDate) Context(com.axelor.rpc.Context) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MrpLine(com.axelor.apps.supplychain.db.MrpLine) LocalDate(java.time.LocalDate) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with MrpLine

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

the class MrpServiceProductionImpl method createManufOrderMrpLines.

@Transactional(rollbackOn = { Exception.class })
protected void createManufOrderMrpLines(Mrp mrp, ManufOrder manufOrder, MrpLineType manufOrderMrpLineType, MrpLineType manufOrderNeedMrpLineType) throws AxelorException {
    StockLocation stockLocation = manufOrder.getProdProcess().getStockLocation();
    LocalDate maturityDate = null;
    if (manufOrder.getPlannedEndDateT() != null) {
        maturityDate = manufOrder.getPlannedEndDateT().toLocalDate();
    } else {
        maturityDate = manufOrder.getPlannedStartDateT().toLocalDate();
    }
    maturityDate = this.computeMaturityDate(maturityDate, manufOrderMrpLineType);
    for (ProdProduct prodProduct : manufOrder.getToProduceProdProductList()) {
        Product product = prodProduct.getProduct();
        if ((this.isBeforeEndDate(maturityDate) || manufOrderMrpLineType.getIgnoreEndDate()) && this.isMrpProduct(product)) {
            MrpLine mrpLine = this.createMrpLine(mrp, product, manufOrderMrpLineType, prodProduct.getQty(), maturityDate, BigDecimal.ZERO, stockLocation, manufOrder);
            if (mrpLine != null) {
                mrpLineRepository.save(mrpLine);
            }
        }
    }
    if (manufOrderNeedMrpLineType == null) {
        return;
    }
    if (manufOrder.getIsConsProOnOperation()) {
        for (OperationOrder operationOrder : manufOrder.getOperationOrderList()) {
            for (ProdProduct prodProduct : operationOrder.getToConsumeProdProductList()) {
                Product product = prodProduct.getProduct();
                if (this.isMrpProduct(product)) {
                    maturityDate = null;
                    if (operationOrder.getPlannedEndDateT() != null) {
                        maturityDate = operationOrder.getPlannedEndDateT().toLocalDate();
                    } else {
                        maturityDate = operationOrder.getPlannedStartDateT().toLocalDate();
                    }
                    maturityDate = this.computeMaturityDate(maturityDate, manufOrderNeedMrpLineType);
                    MrpLine mrpLine = this.createMrpLine(mrp, prodProduct.getProduct(), manufOrderNeedMrpLineType, computeQtyLeftToConsume(operationOrder, prodProduct), maturityDate, BigDecimal.ZERO, stockLocation, operationOrder);
                    if (mrpLine != null) {
                        mrpLineRepository.save(mrpLine);
                    }
                }
            }
        }
    } else {
        for (ProdProduct prodProduct : manufOrder.getToConsumeProdProductList()) {
            Product product = prodProduct.getProduct();
            if (this.isMrpProduct(product)) {
                // add it with the level of manuf order product + 1.
                if (!this.productMap.containsKey(product.getId())) {
                    this.assignProductAndLevel(product, manufOrder.getProduct());
                    this.createAvailableStockMrpLine(product, manufOrder.getProdProcess().getStockLocation());
                }
                MrpLine mrpLine = this.createMrpLine(mrp, product, manufOrderNeedMrpLineType, computeQtyLeftToConsume(manufOrder, prodProduct), maturityDate, BigDecimal.ZERO, stockLocation, manufOrder);
                if (mrpLine != null) {
                    mrpLineRepository.save(mrpLine);
                }
            }
        }
    }
}
Also used : StockLocation(com.axelor.apps.stock.db.StockLocation) Product(com.axelor.apps.base.db.Product) ProdProduct(com.axelor.apps.production.db.ProdProduct) MrpLine(com.axelor.apps.supplychain.db.MrpLine) ProdProduct(com.axelor.apps.production.db.ProdProduct) LocalDate(java.time.LocalDate) OperationOrder(com.axelor.apps.production.db.OperationOrder) Transactional(com.google.inject.persist.Transactional)

Example 19 with MrpLine

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

Aggregations

MrpLine (com.axelor.apps.supplychain.db.MrpLine)19 Transactional (com.google.inject.persist.Transactional)10 LocalDate (java.time.LocalDate)6 BigDecimal (java.math.BigDecimal)4 Product (com.axelor.apps.base.db.Product)3 Unit (com.axelor.apps.base.db.Unit)3 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)3 ArrayList (java.util.ArrayList)3 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)2 StockLocation (com.axelor.apps.stock.db.StockLocation)2 MrpLineType (com.axelor.apps.supplychain.db.MrpLineType)2 MrpLineService (com.axelor.apps.supplychain.service.MrpLineService)2 ProjectedStockService (com.axelor.apps.supplychain.service.ProjectedStockService)2 AxelorException (com.axelor.exception.AxelorException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Company (com.axelor.apps.base.db.Company)1 Partner (com.axelor.apps.base.db.Partner)1 CompanyRepository (com.axelor.apps.base.db.repo.CompanyRepository)1 OperationOrder (com.axelor.apps.production.db.OperationOrder)1