Search in sources :

Example 1 with ActionRequest

use of com.axelor.rpc.ActionRequest in project axelor-open-suite by axelor.

the class PartnerSaleController method displayValues.

public void displayValues(ActionRequest request, ActionResponse response) {
    Partner customer = request.getContext().asType(Partner.class);
    try {
        customer = Beans.get(PartnerRepository.class).find(customer.getId());
        SortedSet<Map<String, Object>> saleDetailsByProduct = new TreeSet<Map<String, Object>>(Comparator.comparing(m -> (String) m.get("name")));
        PartnerSaleService partnerSaleService = Beans.get(PartnerSaleService.class);
        List<Product> productList = partnerSaleService.getProductBoughtByCustomer(customer);
        if (productList.isEmpty()) {
            response.setAttr("$saleDetailsByProduct", "hidden", true);
            return;
        }
        response.setAttr("$saleDetailsByProduct", "hidden", false);
        HashMap<String, BigDecimal> qtyAndPrice;
        for (Product product : productList) {
            qtyAndPrice = partnerSaleService.getTotalSaleQuantityAndPrice(customer, product);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("name", product.getName());
            map.put("$quantitySold", qtyAndPrice.get("qty"));
            map.put("$totalPrice", qtyAndPrice.get("price"));
            map.put("$averagePrice", qtyAndPrice.get("price").divide(qtyAndPrice.get("qty"), AppBaseService.DEFAULT_NB_DECIMAL_DIGITS, RoundingMode.HALF_EVEN));
            saleDetailsByProduct.add(map);
        }
        response.setValue("$saleDetailsByProduct", saleDetailsByProduct);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : SortedSet(java.util.SortedSet) TraceBackService(com.axelor.exception.service.TraceBackService) PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) HashMap(java.util.HashMap) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) TreeSet(java.util.TreeSet) PartnerSaleService(com.axelor.apps.sale.service.PartnerSaleService) BigDecimal(java.math.BigDecimal) List(java.util.List) Beans(com.axelor.inject.Beans) Product(com.axelor.apps.base.db.Product) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) ActionRequest(com.axelor.rpc.ActionRequest) Comparator(java.util.Comparator) Partner(com.axelor.apps.base.db.Partner) Context(com.axelor.rpc.Context) Singleton(com.google.inject.Singleton) RoundingMode(java.math.RoundingMode) HashMap(java.util.HashMap) Product(com.axelor.apps.base.db.Product) BigDecimal(java.math.BigDecimal) TreeSet(java.util.TreeSet) PartnerSaleService(com.axelor.apps.sale.service.PartnerSaleService) Partner(com.axelor.apps.base.db.Partner) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ActionRequest

use of com.axelor.rpc.ActionRequest in project axelor-open-suite by axelor.

the class ManufOrderController method generateMultiLevelManufOrder.

/**
 * Called from multi-level-planing-wizard-form, on clicking "Generate MO" button.
 *
 * @param request
 * @param response
 */
@SuppressWarnings("unchecked")
public void generateMultiLevelManufOrder(ActionRequest request, ActionResponse response) {
    try {
        Long moId = Long.valueOf(request.getContext().get("id").toString());
        ManufOrder mo = Beans.get(ManufOrderRepository.class).find(moId);
        ProdProductRepository prodProductRepository = Beans.get(ProdProductRepository.class);
        List<ProdProduct> prodProductList = ((List<LinkedHashMap<String, Object>>) request.getContext().get("components")).stream().filter(map -> (boolean) map.get("selected")).map(map -> prodProductRepository.find(Long.valueOf(map.get("id").toString()))).collect(Collectors.toList());
        if (prodProductList.isEmpty()) {
            throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.NO_PRODUCT_SELECTED));
        }
        List<Product> selectedProductList = new ArrayList<>();
        for (ProdProduct prod : prodProductList) {
            if (selectedProductList.contains(prod.getProduct())) {
                throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.DUPLICATE_PRODUCT_SELECTED));
            }
            selectedProductList.add(prod.getProduct());
        }
        List<ManufOrder> moList = Beans.get(ManufOrderService.class).generateAllSubManufOrder(selectedProductList, mo);
        response.setCanClose(true);
        response.setView(ActionView.define(I18n.get("Manufacturing orders")).model(ManufOrder.class.getName()).add("grid", "generated-manuf-order-grid").add("form", "manuf-order-form").param("popup", "true").param("popup-save", "false").param("show-toolbar", "false").param("show-confirm", "false").domain("self.id in (" + StringTool.getIdListString(moList) + ")").map());
    } 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) ManufOrderService(com.axelor.apps.production.service.manuforder.ManufOrderService) AxelorException(com.axelor.exception.AxelorException) ArrayList(java.util.ArrayList) ProdProduct(com.axelor.apps.production.db.ProdProduct) Product(com.axelor.apps.base.db.Product) ProdProduct(com.axelor.apps.production.db.ProdProduct) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) ManufOrderRepository(com.axelor.apps.production.db.repo.ManufOrderRepository) ProdProductRepository(com.axelor.apps.production.db.repo.ProdProductRepository) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 3 with ActionRequest

use of com.axelor.rpc.ActionRequest in project axelor-open-suite by axelor.

the class ManufOrderController method partialFinish.

public void partialFinish(ActionRequest request, ActionResponse response) {
    try {
        ManufOrder manufOrder = request.getContext().asType(ManufOrder.class);
        manufOrder = Beans.get(ManufOrderRepository.class).find(manufOrder.getId());
        // 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).partialFinish(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) BirtException(org.eclipse.birt.core.exception.BirtException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) ManufOrder(com.axelor.apps.production.db.ManufOrder)

Example 4 with ActionRequest

use of com.axelor.rpc.ActionRequest in project axelor-open-suite by axelor.

the class InvoiceController method massPaymentOnSupplierInvoices.

public void massPaymentOnSupplierInvoices(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        if (!ObjectUtils.isEmpty(context.get("_ids"))) {
            List<Long> invoiceIdList = (List) (((List) context.get("_ids")).stream().filter(ObjectUtils::notEmpty).map(input -> Long.parseLong(input.toString())).collect(Collectors.toList()));
            List<Long> invoiceToPay = Beans.get(InvoicePaymentCreateService.class).getInvoiceIdsToPay(invoiceIdList);
            if (invoiceToPay.isEmpty()) {
                response.setError(I18n.get(IExceptionMessage.INVOICE_NO_INVOICE_TO_PAY));
            }
            response.setView(ActionView.define(I18n.get("Register a mass payment")).model(InvoicePayment.class.getName()).add("form", "invoice-payment-mass-form").param("popup", "reload").param("show-toolbar", "false").param("show-confirm", "false").param("popup-save", "false").param("forceEdit", "true").context("_invoices", invoiceToPay).map());
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e, ResponseMessageType.ERROR);
    }
}
Also used : Context(com.axelor.rpc.Context) AppAccountService(com.axelor.apps.account.service.app.AppAccountService) PartnerService(com.axelor.apps.base.service.PartnerService) LoggerFactory(org.slf4j.LoggerFactory) PaymentCondition(com.axelor.apps.account.db.PaymentCondition) BankDetailsService(com.axelor.apps.base.service.BankDetailsService) Pair(org.apache.commons.lang3.tuple.Pair) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) InvoicePaymentCreateService(com.axelor.apps.account.service.payment.invoice.payment.InvoicePaymentCreateService) Function(com.google.common.base.Function) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) Set(java.util.Set) InvoiceService(com.axelor.apps.account.service.invoice.InvoiceService) Collectors(java.util.stream.Collectors) Currency(com.axelor.apps.base.db.Currency) InvoiceToolService(com.axelor.apps.account.service.invoice.InvoiceToolService) List(java.util.List) ObjectUtils(com.axelor.common.ObjectUtils) PriceList(com.axelor.apps.base.db.PriceList) AccountingSituationService(com.axelor.apps.account.service.AccountingSituationService) 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) InvoicePrintService(com.axelor.apps.account.service.invoice.print.InvoicePrintService) LanguageRepository(com.axelor.apps.base.db.repo.LanguageRepository) ActionView(com.axelor.meta.schema.actions.ActionView) AddressService(com.axelor.apps.base.service.AddressService) PrintingSettings(com.axelor.apps.base.db.PrintingSettings) ArrayList(java.util.ArrayList) IExceptionMessage(com.axelor.apps.account.exception.IExceptionMessage) InvoicePayment(com.axelor.apps.account.db.InvoicePayment) AccountingSituation(com.axelor.apps.account.db.AccountingSituation) AxelorException(com.axelor.exception.AxelorException) IrrecoverableService(com.axelor.apps.account.service.IrrecoverableService) I18n(com.axelor.i18n.I18n) Wizard(com.axelor.apps.base.db.Wizard) ActionRequest(com.axelor.rpc.ActionRequest) ResponseMessageType(com.axelor.exception.ResponseMessageType) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) StringTool(com.axelor.apps.tool.StringTool) JPA(com.axelor.db.JPA) Logger(org.slf4j.Logger) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) PartnerPriceListService(com.axelor.apps.base.service.PartnerPriceListService) TraceBackService(com.axelor.exception.service.TraceBackService) PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) Invoice(com.axelor.apps.account.db.Invoice) TradingNameService(com.axelor.apps.base.service.TradingNameService) InvoiceRepository(com.axelor.apps.account.db.repo.InvoiceRepository) Beans(com.axelor.inject.Beans) PaymentMode(com.axelor.apps.account.db.PaymentMode) BankDetails(com.axelor.apps.base.db.BankDetails) Context(com.axelor.rpc.Context) List(java.util.List) PriceList(com.axelor.apps.base.db.PriceList) ArrayList(java.util.ArrayList) ObjectUtils(com.axelor.common.ObjectUtils) InvoicePaymentCreateService(com.axelor.apps.account.service.payment.invoice.payment.InvoicePaymentCreateService) AxelorException(com.axelor.exception.AxelorException)

Example 5 with ActionRequest

use of com.axelor.rpc.ActionRequest in project axelor-open-suite by axelor.

the class AdvancedExportController method createCriteria.

@SuppressWarnings("unchecked")
private List<Long> createCriteria(ActionRequest request, AdvancedExport advancedExport) {
    if (request.getContext().get("_criteria") != null) {
        if (request.getContext().get("_criteria").toString().startsWith("[")) {
            String ids = request.getContext().get("_criteria").toString();
            return Splitter.on(", ").splitToList(ids.substring(1, ids.length() - 1)).stream().map(id -> Long.valueOf(id.toString())).collect(Collectors.toList());
        } else {
            ObjectMapper mapper = new ObjectMapper();
            ActionRequest parentRequest = mapper.convertValue(request.getContext().get("_criteria"), ActionRequest.class);
            Class<? extends Model> klass = (Class<? extends Model>) parentRequest.getBeanClass();
            Filter filter = Beans.get(AdvancedExportService.class).getJpaSecurityFilter(advancedExport.getMetaModel());
            Stream<? extends Model> listObj = parentRequest.getCriteria().createQuery(klass, filter).fetchSteam(advancedExport.getMaxExportLimit());
            return listObj.map(it -> it.getId()).collect(Collectors.toList());
        }
    }
    return null;
}
Also used : MetaModelRepository(com.axelor.meta.db.repo.MetaModelRepository) Filter(com.axelor.rpc.filter.Filter) ActionView(com.axelor.meta.schema.actions.ActionView) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Mapper(com.axelor.db.mapper.Mapper) AdvancedExportLine(com.axelor.apps.base.db.AdvancedExportLine) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) AdvancedExport(com.axelor.apps.base.db.AdvancedExport) AxelorException(com.axelor.exception.AxelorException) ActionResponse(com.axelor.rpc.ActionResponse) Map(java.util.Map) I18n(com.axelor.i18n.I18n) Inflector(com.axelor.common.Inflector) AdvancedExportRepository(com.axelor.apps.base.db.repo.AdvancedExportRepository) ActionRequest(com.axelor.rpc.ActionRequest) Splitter(com.google.common.base.Splitter) MetaFiles(com.axelor.meta.MetaFiles) Logger(org.slf4j.Logger) Model(com.axelor.db.Model) MetaField(com.axelor.meta.db.MetaField) MethodHandles(java.lang.invoke.MethodHandles) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TraceBackService(com.axelor.exception.service.TraceBackService) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Collectors(java.util.stream.Collectors) File(java.io.File) AdvancedExportService(com.axelor.apps.base.service.advancedExport.AdvancedExportService) MetaFile(com.axelor.meta.db.MetaFile) MetaModel(com.axelor.meta.db.MetaModel) List(java.util.List) Stream(java.util.stream.Stream) Beans(com.axelor.inject.Beans) MetaFieldRepository(com.axelor.meta.db.repo.MetaFieldRepository) IExceptionMessage(com.axelor.apps.base.exceptions.IExceptionMessage) Context(com.axelor.rpc.Context) Joiner(com.google.common.base.Joiner) Singleton(com.google.inject.Singleton) ActionRequest(com.axelor.rpc.ActionRequest) Filter(com.axelor.rpc.filter.Filter) Model(com.axelor.db.Model) MetaModel(com.axelor.meta.db.MetaModel) AdvancedExportService(com.axelor.apps.base.service.advancedExport.AdvancedExportService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

ActionRequest (com.axelor.rpc.ActionRequest)18 Beans (com.axelor.inject.Beans)17 ActionResponse (com.axelor.rpc.ActionResponse)17 Context (com.axelor.rpc.Context)17 List (java.util.List)17 TraceBackService (com.axelor.exception.service.TraceBackService)16 Singleton (com.google.inject.Singleton)16 I18n (com.axelor.i18n.I18n)15 ArrayList (java.util.ArrayList)15 AxelorException (com.axelor.exception.AxelorException)14 ActionView (com.axelor.meta.schema.actions.ActionView)14 BigDecimal (java.math.BigDecimal)13 Map (java.util.Map)13 Collectors (java.util.stream.Collectors)13 Product (com.axelor.apps.base.db.Product)12 TraceBackRepository (com.axelor.exception.db.repo.TraceBackRepository)11 MethodHandles (java.lang.invoke.MethodHandles)11 Logger (org.slf4j.Logger)11 LoggerFactory (org.slf4j.LoggerFactory)11 StringTool (com.axelor.apps.tool.StringTool)10