Search in sources :

Example 76 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class StockMovePrintServiceImpl method prepareReportSettings.

@Override
public ReportSettings prepareReportSettings(StockMove stockMove, String format) throws AxelorException {
    if (stockMove.getPrintingSettings() == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, String.format(I18n.get(IExceptionMessage.STOCK_MOVES_MISSING_PRINTING_SETTINGS), stockMove.getStockMoveSeq()), stockMove);
    }
    String locale = ReportSettings.getPrintingLocale(stockMove.getPartner());
    String title = getFileName(stockMove);
    AppBase appBase = appBaseService.getAppBase();
    ReportSettings reportSetting = ReportFactory.createReport(IReport.STOCK_MOVE, title + " - ${date}");
    return reportSetting.addParam("StockMoveId", stockMove.getId()).addParam("Timezone", stockMove.getCompany() != null ? stockMove.getCompany().getTimezone() : null).addParam("Locale", locale).addParam("GroupProducts", appBase.getIsRegroupProductsOnPrintings() && stockMove.getGroupProductsOnPrintings()).addParam("GroupProductTypes", appBase.getRegroupProductsTypeSelect()).addParam("GroupProductLevel", appBase.getRegroupProductsLevelSelect()).addParam("GroupProductProductTitle", appBase.getRegroupProductsLabelProducts()).addParam("GroupProductServiceTitle", appBase.getRegroupProductsLabelServices()).addParam("HeaderHeight", stockMove.getPrintingSettings().getPdfHeaderHeight()).addParam("FooterHeight", stockMove.getPrintingSettings().getPdfFooterHeight()).addFormat(format);
}
Also used : AxelorException(com.axelor.exception.AxelorException) ReportSettings(com.axelor.apps.report.engine.ReportSettings) AppBase(com.axelor.apps.base.db.AppBase)

Example 77 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class InventoryController method checkDuplicateProduct.

public void checkDuplicateProduct(ActionRequest request, ActionResponse response) throws AxelorException {
    Inventory inventory = request.getContext().asType(Inventory.class);
    Query query = JPA.em().createQuery("select COUNT(*) FROM InventoryLine self WHERE self.inventory.id = :invent GROUP BY self.product, self.trackingNumber HAVING COUNT(self) > 1");
    try {
        query.setParameter("invent", inventory.getId()).getSingleResult();
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.INVENTORY_PRODUCT_TRACKING_NUMBER_ERROR));
    } catch (NoResultException e) {
    // if control came here means no duplicate product.
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Query(javax.persistence.Query) NoResultException(javax.persistence.NoResultException) Inventory(com.axelor.apps.stock.db.Inventory)

Example 78 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class ChartBuilderService method build.

/**
 * Root Method to access the service it generate AbstractView from ViewBuilder.
 *
 * @param viewBuilder ViewBuilder object of type chart.
 * @return AbstractView from meta schema.
 * @throws JAXBException
 * @throws AxelorException
 */
public void build(ChartBuilder chartBuilder) throws JAXBException, AxelorException {
    if (chartBuilder.getName().contains(" ")) {
        throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.CHART_BUILDER_1));
    }
    searchFields = new ArrayList<String>();
    // onNewFields = new ArrayList<RecordField>();
    joins = new ArrayList<String>();
    categType = "text";
    String[] queryString = prepareQuery(chartBuilder);
    // setOnNewAction(chartBuilder);
    String xml = createXml(chartBuilder, queryString);
    log.debug("Chart xml: {}", xml);
    ObjectViews chartView = XMLViews.fromXML(xml);
    MetaView metaView = metaService.generateMetaView(chartView.getViews().get(0));
    if (metaView != null) {
        chartBuilder.setMetaViewGenerated(metaView);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) ObjectViews(com.axelor.meta.schema.ObjectViews) MetaView(com.axelor.meta.db.MetaView)

Example 79 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class ConformityCertificatePrintServiceImpl method prepareReportSettings.

@Override
public ReportSettings prepareReportSettings(StockMove stockMove, String format) throws AxelorException {
    if (stockMove.getPrintingSettings() == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, String.format(I18n.get(IExceptionMessage.STOCK_MOVES_MISSING_PRINTING_SETTINGS), stockMove.getStockMoveSeq()), stockMove);
    }
    String locale = ReportSettings.getPrintingLocale(stockMove.getPartner());
    String title = getFileName(stockMove);
    ReportSettings reportSetting = ReportFactory.createReport(IReport.CONFORMITY_CERTIFICATE, title + " - ${date}");
    return reportSetting.addParam("StockMoveId", stockMove.getId()).addParam("Timezone", stockMove.getCompany() != null ? stockMove.getCompany().getTimezone() : null).addParam("Locale", locale).addParam("HeaderHeight", stockMove.getPrintingSettings().getPdfHeaderHeight()).addParam("FooterHeight", stockMove.getPrintingSettings().getPdfFooterHeight()).addFormat(format);
}
Also used : AxelorException(com.axelor.exception.AxelorException) ReportSettings(com.axelor.apps.report.engine.ReportSettings)

Example 80 with AxelorException

use of com.axelor.exception.AxelorException in project axelor-open-suite by axelor.

the class StockMoveServiceImpl method printStockMove.

@Override
public String printStockMove(StockMove stockMove, List<Integer> lstSelectedMove, String reportType) throws AxelorException {
    List<Long> selectedStockMoveListId;
    if (lstSelectedMove != null && !lstSelectedMove.isEmpty()) {
        selectedStockMoveListId = lstSelectedMove.stream().map(integer -> Long.parseLong(integer.toString())).collect(Collectors.toList());
        stockMove = stockMoveRepo.find(selectedStockMoveListId.get(0));
    } else if (stockMove != null && stockMove.getId() != null) {
        selectedStockMoveListId = new ArrayList<>();
        selectedStockMoveListId.add(stockMove.getId());
    } else {
        throw new AxelorException(StockMove.class, TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.STOCK_MOVE_10));
    }
    List<StockMove> stockMoveList = stockMoveRepo.all().filter("self.id IN (" + selectedStockMoveListId.stream().map(Object::toString).collect(Collectors.joining(",")) + ") AND self.printingSettings IS NULL").fetch();
    if (!stockMoveList.isEmpty()) {
        String exceptionMessage = String.format(I18n.get(IExceptionMessage.STOCK_MOVES_MISSING_PRINTING_SETTINGS), "<ul>" + stockMoveList.stream().map(StockMove::getStockMoveSeq).collect(Collectors.joining("</li><li>", "<li>", "</li>")) + "<ul>");
        throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, exceptionMessage);
    }
    String stockMoveIds = selectedStockMoveListId.stream().map(Object::toString).collect(Collectors.joining(","));
    String title = I18n.get("Stock move");
    if (stockMove.getStockMoveSeq() != null) {
        title = selectedStockMoveListId.size() == 1 ? I18n.get("StockMove") + " " + stockMove.getStockMoveSeq() : I18n.get("StockMove(s)");
    }
    String locale = reportType.equals(IReport.PICKING_STOCK_MOVE) ? Beans.get(UserService.class).getLanguage() : ReportSettings.getPrintingLocale(stockMove.getPartner());
    ReportSettings reportSettings = ReportFactory.createReport(reportType, title + "-${date}").addParam("StockMoveId", stockMoveIds).addParam("Timezone", null).addParam("Locale", locale);
    if (reportType.equals(IReport.CONFORMITY_CERTIFICATE)) {
        reportSettings.toAttach(stockMove);
    }
    return reportSettings.generate().getFileLink();
}
Also used : AxelorException(com.axelor.exception.AxelorException) StockMove(com.axelor.apps.stock.db.StockMove) ReportSettings(com.axelor.apps.report.engine.ReportSettings) ArrayList(java.util.ArrayList)

Aggregations

AxelorException (com.axelor.exception.AxelorException)546 Transactional (com.google.inject.persist.Transactional)126 BigDecimal (java.math.BigDecimal)118 ArrayList (java.util.ArrayList)84 IOException (java.io.IOException)73 Product (com.axelor.apps.base.db.Product)64 Company (com.axelor.apps.base.db.Company)63 LocalDate (java.time.LocalDate)58 Partner (com.axelor.apps.base.db.Partner)48 List (java.util.List)45 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)40 HashMap (java.util.HashMap)38 Invoice (com.axelor.apps.account.db.Invoice)33 StockMove (com.axelor.apps.stock.db.StockMove)32 Map (java.util.Map)31 Beans (com.axelor.inject.Beans)30 I18n (com.axelor.i18n.I18n)28 Inject (com.google.inject.Inject)28 MoveLine (com.axelor.apps.account.db.MoveLine)27 Context (com.axelor.rpc.Context)27