use of com.axelor.exception.service.TraceBackService in project axelor-open-suite by axelor.
the class SaleOrderController method createStockMove.
public void createStockMove(ActionRequest request, ActionResponse response) {
SaleOrder saleOrder = request.getContext().asType(SaleOrder.class);
try {
if (saleOrder.getId() != null) {
SaleOrderStockService saleOrderStockService = Beans.get(SaleOrderStockService.class);
List<Long> stockMoveList = saleOrderStockService.createStocksMovesFromSaleOrder(Beans.get(SaleOrderRepository.class).find(saleOrder.getId()));
if (stockMoveList != null && stockMoveList.size() == 1) {
response.setView(ActionView.define(I18n.get("Stock move")).model(StockMove.class.getName()).add("form", "stock-move-form").add("grid", "stock-move-grid").param("search-filters", "internal-stock-move-filters").param("forceEdit", "true").domain("self.id = " + stockMoveList.get(0)).context("_showRecord", String.valueOf(stockMoveList.get(0))).context("_userType", StockMoveRepository.USER_TYPE_SALESPERSON).map());
// we have to inject TraceBackService to use non static methods
Beans.get(TraceBackService.class).findLastMessageTraceBack(Beans.get(StockMoveRepository.class).find(stockMoveList.get(0))).ifPresent(traceback -> response.setNotify(String.format(I18n.get(com.axelor.apps.message.exception.IExceptionMessage.SEND_EMAIL_EXCEPTION), traceback.getMessage())));
} else if (stockMoveList != null && stockMoveList.size() > 1) {
response.setView(ActionView.define(I18n.get("Stock move")).model(StockMove.class.getName()).add("grid", "stock-move-grid").add("form", "stock-move-form").param("search-filters", "internal-stock-move-filters").domain("self.id in (" + Joiner.on(",").join(stockMoveList) + ")").context("_userType", StockMoveRepository.USER_TYPE_SALESPERSON).map());
// we have to inject TraceBackService to use non static methods
TraceBackService traceBackService = Beans.get(TraceBackService.class);
StockMoveRepository stockMoveRepository = Beans.get(StockMoveRepository.class);
stockMoveList.stream().map(stockMoveRepository::find).map(traceBackService::findLastMessageTraceBack).filter(Optional::isPresent).map(Optional::get).findAny().ifPresent(traceback -> response.setNotify(String.format(I18n.get(com.axelor.apps.message.exception.IExceptionMessage.SEND_EMAIL_EXCEPTION), traceback.getMessage())));
} else {
response.setFlash(I18n.get(IExceptionMessage.SO_NO_DELIVERY_STOCK_MOVE_TO_GENERATE));
}
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.exception.service.TraceBackService in project axelor-open-suite by axelor.
the class ManufOrderController method finish.
public void finish(ActionRequest request, ActionResponse response) {
try {
Long manufOrderId = (Long) request.getContext().get("id");
ManufOrder manufOrder = Beans.get(ManufOrderRepository.class).find(manufOrderId);
// we have to inject TraceBackService to use non static methods
TraceBackService traceBackService = Beans.get(TraceBackService.class);
long tracebackCount = traceBackService.countMessageTraceBack(manufOrder);
if (!Beans.get(ManufOrderWorkflowService.class).finish(manufOrder)) {
response.setNotify(I18n.get(IExceptionMessage.MANUF_ORDER_EMAIL_NOT_SENT));
} else if (traceBackService.countMessageTraceBack(manufOrder) > tracebackCount) {
traceBackService.findLastMessageTraceBack(manufOrder).ifPresent(traceback -> response.setNotify(String.format(I18n.get(com.axelor.apps.message.exception.IExceptionMessage.SEND_EMAIL_EXCEPTION), traceback.getMessage())));
}
response.setReload(true);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.exception.service.TraceBackService in project axelor-open-suite by axelor.
the class StockMoveController method realize.
public void realize(ActionRequest request, ActionResponse response) {
try {
StockMove stockMoveFromRequest = request.getContext().asType(StockMove.class);
StockMove stockMove = Beans.get(StockMoveRepository.class).find(stockMoveFromRequest.getId());
// we have to inject TraceBackService to use non static methods
TraceBackService traceBackService = Beans.get(TraceBackService.class);
long tracebackCount = traceBackService.countMessageTraceBack(stockMove);
if (stockMove.getStatusSelect() == null || stockMove.getStatusSelect() != StockMoveRepository.STATUS_PLANNED) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, I18n.get(IExceptionMessage.STOCK_MOVE_REALIZATION_WRONG_STATUS));
}
String newSeq = Beans.get(StockMoveService.class).realize(stockMove);
response.setReload(true);
if (newSeq != null) {
if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_INCOMING) {
response.setFlash(String.format(I18n.get(IExceptionMessage.STOCK_MOVE_INCOMING_PARTIAL_GENERATED), newSeq));
} else if (stockMove.getTypeSelect() == StockMoveRepository.TYPE_OUTGOING) {
response.setFlash(String.format(I18n.get(IExceptionMessage.STOCK_MOVE_OUTGOING_PARTIAL_GENERATED), newSeq));
} else {
response.setFlash(String.format(I18n.get(IExceptionMessage.STOCK_MOVE_9), newSeq));
}
}
if (traceBackService.countMessageTraceBack(stockMove) > tracebackCount) {
traceBackService.findLastMessageTraceBack(stockMove).ifPresent(traceback -> response.setNotify(String.format(I18n.get(com.axelor.apps.message.exception.IExceptionMessage.SEND_EMAIL_EXCEPTION), traceback.getMessage())));
}
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations