Search in sources :

Example 6 with TraceBackService

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);
    }
}
Also used : IExceptionMessage(com.axelor.apps.supplychain.exception.IExceptionMessage) SaleOrderServiceSupplychainImpl(com.axelor.apps.supplychain.service.SaleOrderServiceSupplychainImpl) Mapper(com.axelor.db.mapper.Mapper) SaleOrderLineRepository(com.axelor.apps.sale.db.repo.SaleOrderLineRepository) BigDecimal(java.math.BigDecimal) SaleOrderRepository(com.axelor.apps.sale.db.repo.SaleOrderRepository) ActionResponse(com.axelor.rpc.ActionResponse) BlockingService(com.axelor.apps.base.service.BlockingService) Map(java.util.Map) SaleOrder(com.axelor.apps.sale.db.SaleOrder) StockLocationService(com.axelor.apps.stock.service.StockLocationService) PartnerSupplychainLinkTypeRepository(com.axelor.apps.supplychain.db.repo.PartnerSupplychainLinkTypeRepository) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) SaleOrderStockService(com.axelor.apps.supplychain.service.SaleOrderStockService) Currency(com.axelor.apps.base.db.Currency) BlockingRepository(com.axelor.apps.base.db.repo.BlockingRepository) List(java.util.List) SaleOrderLine(com.axelor.apps.sale.db.SaleOrderLine) PurchaseOrder(com.axelor.apps.purchase.db.PurchaseOrder) SaleOrderPurchaseService(com.axelor.apps.supplychain.service.SaleOrderPurchaseService) LocalDate(java.time.LocalDate) PriceList(com.axelor.apps.base.db.PriceList) Optional(java.util.Optional) SaleOrderInvoiceService(com.axelor.apps.supplychain.service.SaleOrderInvoiceService) Partner(com.axelor.apps.base.db.Partner) Joiner(com.google.common.base.Joiner) Singleton(com.google.inject.Singleton) Company(com.axelor.apps.base.db.Company) ActionView(com.axelor.meta.schema.actions.ActionView) TemporalUnit(java.time.temporal.TemporalUnit) HashMap(java.util.HashMap) SaleOrderCreateServiceSupplychainImpl(com.axelor.apps.supplychain.service.SaleOrderCreateServiceSupplychainImpl) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Strings(com.google.common.base.Strings) AxelorException(com.axelor.exception.AxelorException) StockLocation(com.axelor.apps.stock.db.StockLocation) SaleOrderReservedQtyService(com.axelor.apps.supplychain.service.SaleOrderReservedQtyService) I18n(com.axelor.i18n.I18n) Wizard(com.axelor.apps.base.db.Wizard) PartnerSupplychainLinkService(com.axelor.apps.supplychain.service.PartnerSupplychainLinkService) ActionRequest(com.axelor.rpc.ActionRequest) ResponseMessageType(com.axelor.exception.ResponseMessageType) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) SaleOrderLineServiceSupplyChain(com.axelor.apps.supplychain.service.SaleOrderLineServiceSupplyChain) JPA(com.axelor.db.JPA) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) TraceBackService(com.axelor.exception.service.TraceBackService) Invoice(com.axelor.apps.account.db.Invoice) Team(com.axelor.team.db.Team) ChronoUnit(java.time.temporal.ChronoUnit) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Beans(com.axelor.inject.Beans) SaleOrderSupplychainService(com.axelor.apps.supplychain.service.SaleOrderSupplychainService) AppSupplychainService(com.axelor.apps.supplychain.service.app.AppSupplychainService) Context(com.axelor.rpc.Context) TraceBackService(com.axelor.exception.service.TraceBackService) StockMove(com.axelor.apps.stock.db.StockMove) Optional(java.util.Optional) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) SaleOrder(com.axelor.apps.sale.db.SaleOrder) SaleOrderStockService(com.axelor.apps.supplychain.service.SaleOrderStockService) AxelorException(com.axelor.exception.AxelorException)

Example 7 with TraceBackService

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);
    }
}
Also used : IExceptionMessage(com.axelor.apps.production.exceptions.IExceptionMessage) AppProductionService(com.axelor.apps.production.service.app.AppProductionService) BirtException(org.eclipse.birt.core.exception.BirtException) CostSheetRepository(com.axelor.apps.production.db.repo.CostSheetRepository) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) ActionView(com.axelor.meta.schema.actions.ActionView) ProdProductRepository(com.axelor.apps.production.db.repo.ProdProductRepository) LoggerFactory(org.slf4j.LoggerFactory) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) ActionResponse(com.axelor.rpc.ActionResponse) I18n(com.axelor.i18n.I18n) ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) ActionRequest(com.axelor.rpc.ActionRequest) ProdProductProductionRepository(com.axelor.apps.production.service.ProdProductProductionRepository) ProdProduct(com.axelor.apps.production.db.ProdProduct) StringTool(com.axelor.apps.tool.StringTool) ManufOrderPrintService(com.axelor.apps.production.service.manuforder.ManufOrderPrintService) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) MethodHandles(java.lang.invoke.MethodHandles) CostSheet(com.axelor.apps.production.db.CostSheet) TraceBackService(com.axelor.exception.service.TraceBackService) IOException(java.io.IOException) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) Collectors(java.util.stream.Collectors) ManufOrderWorkflowService(com.axelor.apps.production.service.manuforder.ManufOrderWorkflowService) List(java.util.List) IReport(com.axelor.apps.production.report.IReport) CostSheetService(com.axelor.apps.production.service.costsheet.CostSheetService) ReportSettings(com.axelor.apps.report.engine.ReportSettings) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) ManufOrder(com.axelor.apps.production.db.ManufOrder) ReportFactory(com.axelor.apps.ReportFactory) LocalDate(java.time.LocalDate) ObjectUtils(com.axelor.common.ObjectUtils) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) Context(com.axelor.rpc.Context) ManufOrderStockMoveService(com.axelor.apps.production.service.manuforder.ManufOrderStockMoveService) Singleton(com.google.inject.Singleton) TraceBackService(com.axelor.exception.service.TraceBackService) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 8 with TraceBackService

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);
    }
}
Also used : TraceBackService(com.axelor.exception.service.TraceBackService) AxelorException(com.axelor.exception.AxelorException) StockMove(com.axelor.apps.stock.db.StockMove) StockMoveService(com.axelor.apps.stock.service.StockMoveService) StockMoveRepository(com.axelor.apps.stock.db.repo.StockMoveRepository) AxelorException(com.axelor.exception.AxelorException)

Aggregations

AxelorException (com.axelor.exception.AxelorException)8 TraceBackService (com.axelor.exception.service.TraceBackService)8 Invoice (com.axelor.apps.account.db.Invoice)4 InvoiceService (com.axelor.apps.account.service.invoice.InvoiceService)3 StockMove (com.axelor.apps.stock.db.StockMove)3 TraceBackRepository (com.axelor.exception.db.repo.TraceBackRepository)3 I18n (com.axelor.i18n.I18n)3 Beans (com.axelor.inject.Beans)3 ActionView (com.axelor.meta.schema.actions.ActionView)3 ActionRequest (com.axelor.rpc.ActionRequest)3 ActionResponse (com.axelor.rpc.ActionResponse)3 Context (com.axelor.rpc.Context)3 Singleton (com.google.inject.Singleton)3 BigDecimal (java.math.BigDecimal)3 LocalDate (java.time.LocalDate)3 ReportFactory (com.axelor.apps.ReportFactory)2 Product (com.axelor.apps.base.db.Product)2 ProductRepository (com.axelor.apps.base.db.repo.ProductRepository)2 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)2 CostSheet (com.axelor.apps.production.db.CostSheet)2