Skip to Content
Menú
This question has been flagged

Hello!, i want edit the ControlPanel for insert some data, wich update when you change of model, for this i add a file "/mymodule/static/src/xml/templates.xml" and declare it in __manyfest__.py


.xml:

?xml version="1.0" encoding="UTF-8"?>
templates>
t t-extend="ControlPanel">
t t-jquery="div.o_cp_mid" t-operation="append">
script type="text/javascript" src="/mymodule/static/src/js/indicadores2.js">/script>

/t>
/t>
/templates>

This call to the "/mymodule/static/src/js/indicadores2.js" script

.js:


odoo.define('mymodule.indicadores2', function (require) {
'use strict';

require('web.dom_ready');
var ajax = require('web.ajax');
var urlc="";
var model="";
if (window.location.href.indexOf('model=')>-1){
​urlc=window.location.href.slice(window.location.href.indexOf('model=')+'model='.length);
model=urlc.slice(0,urlc.indexOf('&'));
};
out=axaj.jsonRpc('/get2_indicadores?model='+model,'call',{}).then(function(data){return data}); This line Crash, trying to call the function"get2_indicadores" on main_controller.py
console.log('res:'+out);
return out
});

 

on Main_controller.py

from odoo import http
from odoo.http import request
class MymoduleControllers(http.Controller):

@http.route('/get2_indicadores', auth="public")
def get2_indicadores(self,**kw):

res = False
out=""
name_model = kw.get('model')
indicadores = request.env['mymodule.indicadores'].sudo().search([('modelo', '=', name_model)])
if indicadores:

out+="h2>Indicadores/h2>br/>"
res={}
for indi in indicadores:
if indi.name0 not in res:
res[indi.name0]=[0.,0.,0.]
if indi.name=='ACTUAL':
res[indi.name0][0]=indi.value_f
elif indi.name=='ESPERADO':
res[indi.name0][1]=indi.value_f
if indi.name=='PROM':
res[indi.name0][2]=indi.value_f
for ky in res.keys():
out+='li>'+ky+':'+str(res[ky][0])+'/'+str(res[ky][1])+'('+str(res[ky][2])+')'+'/li>br/>'

return out


This last function works fine, if i call "localhost:8069/get2_indicadores?model=model_name" manually, but i cannot make to be called him by the .js...


im making overextend steps? or are something wrong? im in odoo12

Thanks!

Avatar
Descartar
Related Posts Respostes Vistes Activitat
2
de des. 24
1284
2
de des. 23
1756
0
de maig 23
3409
1
d’ag. 20
8929
0
de juny 20
2613