Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

not able to return value after jsonrpc ajax call getting empty array

Subscriure's

Get notified when there's activity on this post

This question has been flagged
Odoo13.0
1 Respondre
3133 Vistes
Avatar
paidy kumar

i am trying to show records count in menus for that i am trying below codes.

please help me guys need to return value instead empty array

my xml code 

using below xml code i am calling javascript function for getting count by passing action id






  • my js code:
    getRecordsCount: function (action_id) {
    var rec_count = [];
    console.log("getRecordsCount is ");
    console.log(action_id);
    ajax.jsonRpc("/get_records_count", 'call', {'action_id': action_id},
    {'async': false}).then(function (data) {
    rec_count.push(data);
    console.log(data['count'])
    });
    console.log(rec_count)
    return rec_count


    },
    my controller file .py file
    @http.route('/get_records_count', type='json', auth='public')
    def get_records_count(self,**kw):
    count = 0
    vals = {
    "count": count
    }
    action_id = kw.get('action_id')
    data = {'status': 200, 'response': vals, 'message': 'records count Returned'}
    action_obj = request.env['ir.actions.act_window'].search([('id', '=', action_id)])
    logging.info("action_obj.xml_id %s" % action_obj.xml_id)
    if action_obj:
    # and (action_obj.xml_id == 'web_advanced_search_sale_unit.menu_sale_all_unit' or action_obj.xml_id == 'web_advanced_search_sale_unit.menu_sale_my_units'):
    domain = action_obj.domain if action_obj.domain else []
    result = isinstance(domain, list)

    if result:
    domain = []
    logging.info("domain %s" % domain)
    count = request.env[action_obj.res_model].search_count(domain)
    logging.info("count %s" % count)
    else:
    if len(domain) > 0:
    logging.info("domain in ast %s" % domain)
    try:
    domain = ast.literal_eval(domain)
    count = request.env[action_obj.res_model].search_count(domain)
    except Exception as e:
    domain = []
    count = request.env[action_obj.res_model].search_count(domain)

    else:
    domain = []
    count = request.env[action_obj.res_model].search_count(domain)

    logging.info("count %s" % count)
    vals = {
    "count": count
    }
    data = {'status': 200, 'response': vals, 'message': 'records count Returned'}
    return vals


    0
    Avatar
    Descartar
    Avatar
    Jainesh Shah(Aktiv Software)
    Best Answer

    Hello paidy kumar,

     
    Please use the JS global variable like these,
    window.rec_count = []
    getRecordsCount: function (action_id) {
    console.log ("getRecordsCount is");
    console.log (action_id);
    ajax.jsonRpc ("/ get_records_count", 'call', {'action_id': action_id},
    {'async': false}). then (function (data) {
    window.rec_count.push (data);
    console.log (data ['count'])
    });
    console.log (window.rec_count)
    return window.rec_count
    },


    Thanks & Regards,
    Email: odoo@aktivsoftware.com
    Skype: kalpeshmaheshwari

    1
    Avatar
    Descartar
    paidy kumar
    Autor

    still empty array coming in logs first it is printing "getRecordsCount is" 2nd "action_id" and third it is printing before return statement log statement and finally inside ajax call log statement "data ['count']"

    paidy kumar
    Autor

    i tried below code getRecordsCount: function (action_id) {
    var i = 0
    if(i>0){
    window.rec_count.pop();
    }
    console.log("getRecordsCount is ");
    console.log(action_id);
    console.log("2window.rec count");
    console.log(window.rec_count);
    return ajax.jsonRpc("/get_records_count", 'call', {'action_id': action_id},{'async': true})
    },

    it is returning promise object how can i get actual object please help

    paidy kumar
    Autor

    here i am getting promise object

    Enjoying the discussion? Don't just read, join in!

    Create an account today to enjoy exclusive features and engage with our awesome community!

    Registrar-se
    Related Posts Respostes Vistes Activitat
    Odoo 13. Don't close a wizard when Click a button Solved
    Odoo13.0
    Avatar
    Avatar
    Avatar
    Avatar
    4
    de maig 24
    14222
    Permission error while user printing excel sheet report in odoo 13 Solved
    Odoo13.0
    Avatar
    Avatar
    1
    d’abr. 24
    4397
    One2many field edited from Transient Model cannot be made empty.
    Odoo13.0
    Avatar
    0
    de nov. 23
    3083
    Blank White Page After log in to Odoo13 Solved
    Odoo13.0
    Avatar
    1
    de set. 23
    3228
    How can I translate Options in Selection.field? Solved
    Odoo13.0
    Avatar
    Avatar
    2
    d’ag. 23
    6033
    Community
    • Tutorials
    • Documentació
    • Fòrum
    Codi obert
    • Descarregar
    • GitHub
    • Runbot
    • Traduccions
    Serveis
    • Allotjament a Odoo.sh
    • Suport
    • Actualització
    • Desenvolupaments personalitzats
    • Educació
    • Troba un comptable
    • Troba un partner
    • Converteix-te en partner
    Sobre nosaltres
    • La nostra empresa
    • Actius de marca
    • Contacta amb nosaltres
    • Llocs de treball
    • Esdeveniments
    • Pòdcast
    • Blog
    • Clients
    • Informació legal • Privacitat
    • Seguretat
    الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

    Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

    La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

    Website made with

    Odoo Experience on YouTube

    1. Use the live chat to ask your questions.
    2. The operator answers within a few minutes.

    Live support on Youtube
    Watch now