Search in sources :

Example 6 with MrpLine

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

the class MrpLineController method generateProposal.

public void generateProposal(ActionRequest request, ActionResponse response) throws AxelorException {
    MrpLine mrpLine = request.getContext().asType(MrpLine.class);
    Beans.get(MrpLineService.class).generateProposal(Beans.get(MrpLineRepository.class).find(mrpLine.getId()));
    response.setFlash(I18n.get("The proposal has been successfully generated."));
    response.setReload(true);
}
Also used : MrpLineService(com.axelor.apps.supplychain.service.MrpLineService) MrpLine(com.axelor.apps.supplychain.db.MrpLine)

Example 7 with MrpLine

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

the class MrpLineServiceImpl method updateProposalToProcess.

@Override
public void updateProposalToProcess(List<Integer> mrpLineIds, boolean proposalToProcess) {
    MrpLine mrpLine;
    for (Integer mrpId : mrpLineIds) {
        mrpLine = mrpLineRepo.find(Long.valueOf(mrpId));
        updateProposalToProcess(mrpLine, proposalToProcess);
    }
}
Also used : MrpLine(com.axelor.apps.supplychain.db.MrpLine)

Example 8 with MrpLine

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

the class MrpServiceImpl method createSaleForecastMrpLines.

@Transactional(rollbackOn = { Exception.class })
protected void createSaleForecastMrpLines(Mrp mrp, MrpForecast mrpForecast, MrpLineType saleForecastMrpLineType) throws AxelorException {
    LocalDate maturityDate = mrpForecast.getForecastDate();
    if (maturityDate != null && !maturityDate.isBefore(today) && this.isBeforeEndDate(maturityDate)) {
        Unit unit = mrpForecast.getProduct().getUnit();
        BigDecimal qty = mrpForecast.getQty();
        if (!unit.equals(mrpForecast.getUnit())) {
            qty = Beans.get(UnitConversionService.class).convert(mrpForecast.getUnit(), unit, qty, qty.scale(), mrpForecast.getProduct());
        }
        MrpLine mrpLine = this.createMrpLine(mrp, mrpForecast.getProduct(), saleForecastMrpLineType, qty, maturityDate, BigDecimal.ZERO, mrpForecast.getStockLocation(), mrpForecast);
        if (mrpLine != null) {
            mrpLineRepository.save(mrpLine);
        }
    }
}
Also used : MrpLine(com.axelor.apps.supplychain.db.MrpLine) Unit(com.axelor.apps.base.db.Unit) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 9 with MrpLine

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

the class MrpServiceImpl method generateProposals.

@Override
@Transactional(rollbackOn = { Exception.class })
public void generateProposals(Mrp mrp, boolean isProposalPerSupplier) throws AxelorException {
    Map<Pair<Partner, LocalDate>, PurchaseOrder> purchaseOrders = new HashMap<>();
    Map<Partner, PurchaseOrder> purchaseOrdersPerSupplier = new HashMap<>();
    List<MrpLine> mrpLineList = mrpLineRepository.all().filter("self.mrp.id = ?1 AND self.proposalToProcess = true", mrp.getId()).order("maturityDate").fetch();
    for (MrpLine mrpLine : mrpLineList) {
        if (!mrpLine.getProposalGenerated()) {
            mrpLineService.generateProposal(mrpLine, purchaseOrders, purchaseOrdersPerSupplier, isProposalPerSupplier);
            mrpLine.setProposalToProcess(false);
            mrpLineRepository.save(mrpLine);
        }
    }
}
Also used : HashMap(java.util.HashMap) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) MrpLine(com.axelor.apps.supplychain.db.MrpLine) Partner(com.axelor.apps.base.db.Partner) Pair(org.apache.commons.lang3.tuple.Pair) Transactional(com.google.inject.persist.Transactional)

Example 10 with MrpLine

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

the class MrpServiceImpl method massUpdateProposalToProcess.

@Override
@Transactional(rollbackOn = { Exception.class })
public void massUpdateProposalToProcess(Mrp mrp, boolean proposalToProcess) {
    Query<MrpLine> mrpLineQuery = mrpLineRepository.all().filter("self.mrp.id = :mrpId AND self.mrpLineType.elementSelect in (:purchaseProposal, :manufProposal)").bind("mrpId", mrp.getId()).bind("purchaseProposal", MrpLineTypeRepository.ELEMENT_PURCHASE_PROPOSAL).bind("manufProposal", MrpLineTypeRepository.ELEMENT_MANUFACTURING_PROPOSAL).order("id");
    int offset = 0;
    List<MrpLine> mrpLineList;
    while (!(mrpLineList = mrpLineQuery.fetch(AbstractBatch.FETCH_LIMIT, offset)).isEmpty()) {
        for (MrpLine mrpLine : mrpLineList) {
            offset++;
            mrpLineService.updateProposalToProcess(mrpLine, true);
        }
        JPA.clear();
    }
}
Also used : MrpLine(com.axelor.apps.supplychain.db.MrpLine) Transactional(com.google.inject.persist.Transactional)

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