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);
}
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.
}
}
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);
}
}
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);
}
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();
}
Aggregations