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) {my controller file .py file
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
},@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