Search in sources :

Example 1 with Mrp

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

the class MrpController method runCalculation.

public void runCalculation(ActionRequest request, ActionResponse response) {
    Mrp mrp = request.getContext().asType(Mrp.class);
    MrpService mrpService = Beans.get(MrpService.class);
    MrpRepository mrpRepository = Beans.get(MrpRepository.class);
    try {
        mrpService.runCalculation(mrpRepository.find(mrp.getId()));
    } catch (Exception e) {
        TraceBackService.trace(response, e);
        mrpService.onError(mrpRepository.find(mrp.getId()), e);
    } finally {
        response.setReload(true);
    }
}
Also used : Mrp(com.axelor.apps.supplychain.db.Mrp) MrpService(com.axelor.apps.supplychain.service.MrpService) MrpRepository(com.axelor.apps.supplychain.db.repo.MrpRepository) AxelorException(com.axelor.exception.AxelorException)

Example 2 with Mrp

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

the class MrpController method printWeeks.

/**
 * Prints the weekly breakdown MRP birt report and shows it to the user.
 *
 * @param request
 * @param response
 */
public void printWeeks(ActionRequest request, ActionResponse response) {
    Mrp mrp = request.getContext().asType(Mrp.class);
    mrp = Beans.get(MrpRepository.class).find(mrp.getId());
    String name = I18n.get("MRP") + "-" + mrp.getId();
    try {
        String fileLink = ReportFactory.createReport(IReport.MRP_WEEKS, name).addParam("mrpId", mrp.getId()).addParam("Timezone", getTimezone(mrp)).addParam("Locale", ReportSettings.getPrintingLocale(null)).addParam("endDate", Beans.get(MrpService.class).findMrpEndDate(mrp).atStartOfDay().toString()).addFormat(ReportSettings.FORMAT_PDF).generate().getFileLink();
        response.setView(ActionView.define(name).add("html", fileLink).map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Mrp(com.axelor.apps.supplychain.db.Mrp) MrpService(com.axelor.apps.supplychain.service.MrpService) AxelorException(com.axelor.exception.AxelorException)

Example 3 with Mrp

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

the class MrpController method printList.

/**
 * Prints the list MRP birt report and shows it to the user.
 *
 * @param request
 * @param response
 */
public void printList(ActionRequest request, ActionResponse response) {
    Mrp mrp = request.getContext().asType(Mrp.class);
    String name = I18n.get("MRP") + "-" + mrp.getId();
    try {
        String fileLink = ReportFactory.createReport(IReport.MRP_LIST, name).addParam("mrpId", mrp.getId()).addParam("Timezone", getTimezone(mrp)).addParam("Locale", ReportSettings.getPrintingLocale(null)).addFormat(ReportSettings.FORMAT_PDF).generate().getFileLink();
        response.setView(ActionView.define(name).add("html", fileLink).map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Mrp(com.axelor.apps.supplychain.db.Mrp) AxelorException(com.axelor.exception.AxelorException)

Example 4 with Mrp

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

the class ProjectedStockServiceImpl method createProjectedStock.

@Transactional(rollbackOn = { Exception.class })
@Override
public List<MrpLine> createProjectedStock(Long productId, Long companyId, Long stockLocationId) throws AxelorException {
    Product product = Beans.get(ProductRepository.class).find(productId);
    Company company = Beans.get(CompanyRepository.class).find(companyId);
    StockLocation stockLocation = stockLocationRepository.find(stockLocationId);
    Mrp mrp = new Mrp();
    mrp.setStockLocation(findStockLocation(company, stockLocation));
    // If a company has no stockLocation
    if (mrp.getStockLocation() == null) {
        return Collections.emptyList();
    }
    mrp.addProductSetItem(product);
    mrp.setMrpTypeSelect(MrpRepository.MRP_TYPE_MRP);
    mrp = Beans.get(MrpRepository.class).save(mrp);
    mrp = Beans.get(MrpService.class).createProjectedStock(mrp, product, company, stockLocation);
    List<MrpLine> mrpLineList = Beans.get(MrpLineRepository.class).all().filter("self.mrp = ?1 AND self.product = ?2 AND self.qty != 0", mrp, product).order("maturityDate").order("mrpLineType.typeSelect").order("mrpLineType.sequence").order("id").fetch();
    if (mrpLineList.isEmpty()) {
        List<MrpLine> mrpLineListToDelete = Beans.get(MrpLineRepository.class).all().filter("self.mrp = ?1", mrp).fetch();
        removeMrpAndMrpLine(mrpLineListToDelete);
        return Collections.emptyList();
    }
    for (MrpLine mrpLine : mrpLineList) {
        mrpLine.setCompany(mrpLine.getStockLocation().getCompany());
        mrpLine.setUnit(mrpLine.getProduct().getUnit());
    }
    return mrpLineList;
}
Also used : MrpLineRepository(com.axelor.apps.supplychain.db.repo.MrpLineRepository) Company(com.axelor.apps.base.db.Company) CompanyRepository(com.axelor.apps.base.db.repo.CompanyRepository) StockLocation(com.axelor.apps.stock.db.StockLocation) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Product(com.axelor.apps.base.db.Product) MrpLine(com.axelor.apps.supplychain.db.MrpLine) Mrp(com.axelor.apps.supplychain.db.Mrp) Transactional(com.google.inject.persist.Transactional)

Example 5 with Mrp

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

the class MrpController method generateAllProposals.

public void generateAllProposals(ActionRequest request, ActionResponse response) {
    try {
        Mrp mrp = request.getContext().asType(Mrp.class);
        Boolean isProposalsPerSupplier = (Boolean) request.getContext().get("consolidateProposalsPerSupplier");
        Beans.get(MrpService.class).generateProposals(Beans.get(MrpRepository.class).find(mrp.getId()), isProposalsPerSupplier != null && isProposalsPerSupplier);
        response.setFlash(I18n.get("Proposals have been generated successfully."));
    } catch (AxelorException e) {
        TraceBackService.trace(response, e);
    } finally {
        response.setReload(true);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Mrp(com.axelor.apps.supplychain.db.Mrp) MrpService(com.axelor.apps.supplychain.service.MrpService)

Aggregations

Mrp (com.axelor.apps.supplychain.db.Mrp)8 AxelorException (com.axelor.exception.AxelorException)6 MrpService (com.axelor.apps.supplychain.service.MrpService)5 MrpRepository (com.axelor.apps.supplychain.db.repo.MrpRepository)2 Transactional (com.google.inject.persist.Transactional)2 Company (com.axelor.apps.base.db.Company)1 Product (com.axelor.apps.base.db.Product)1 CompanyRepository (com.axelor.apps.base.db.repo.CompanyRepository)1 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)1 StockLocation (com.axelor.apps.stock.db.StockLocation)1 MrpLine (com.axelor.apps.supplychain.db.MrpLine)1 MrpLineRepository (com.axelor.apps.supplychain.db.repo.MrpLineRepository)1