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

How to get JSON data from controller and use it to create a Chart using RPC query in JavaScript

Subscriure's

Get notified when there's activity on this post

This question has been flagged
javascriptsnippetsodoo16features
1 Respondre
6039 Vistes
Avatar
Jay

Hello, I am trying to create a chart snippet using data from the controller and using that data to create a Chart snippet.
Here is what I have managed to do and I am getting this error from the console.


Failed to load resource: the server responded with a status of 500 (INTERNAL SERVER ERROR)

Controller:

@http.route ( '/btc/usd' , auth = "public" , type = "json" , methods =[ 'POST' , 'GET' ] , csrf = False ) 
def all_bitcoin_usd ( self , **kwargs ):
print ( 'Calling this method >>>' )
# fetch_usd = http.request.env['usd.btc.exchange'].search_read([], ['name', 'date', 'amount_paid'])

fetch_usd = http.request.env[ 'usd.btc.exchange' ].search([])
for i infetch_usd:
print ( 'fetch usd' , i)
param = {}
data = dict ()
data[ 'name' ] = i.name
data[ 'date' ] = i.date
data[ 'amount_paid' ] = i.amount_paid
param[ 'param' ] = data
n = json.dumps(param)
print ( 'nnn' , n)
return Response(json.dumps(param , default =date_utils.default) , content_type = 'application/json;charset=utf -8' ,status = 200 )

js file

odoo.define( 'dynamic_jobs_snippets.s_bitcoin_chart_temp2' , function (require) { 
var PublicWidget = require( 'web.public.widget' );
var rpc = require( 'web.rpc' );
var Dynamic = PublicWidget.Widget.extend( {
selector: '.usd_bitcoin_chart_can2' ,
start: function () {
var self = this ;
rpc.query({
route: '/btc/usd' ,
params: {},
}).then((result) => {
console .log(result);
const myChart = new Chart({
type: 'line' ,
data: {
labels: result.param[ 'name' ],
datasets: [{
label: 'My First Dataset' ,
data: result.param[ 'amount_paid' ],
fill: true ,
backgroundColor: 'rgba(255, 99, 132, 0.2)' ,
borderColor: 'rgb(255, 99, 132)' ,
pointBackgroundColor: 'rgb(255, 99, 132)' ,
pointBorderColor: '#fff' ,
pointHoverBorderColor: 'rgb(255, 99, 132)'
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
}
}
});

});
},
});
PublicWidget.registry.usd_bitcoin_chart_can2 = Dynamic;
return Dynamic;
});


Canvas UI

id="usd_bitcoin_chart " height="400px" width="400px"/>




0
Avatar
Descartar
Avatar
Mehjabin Farsana
Best Answer

Hi,

In your controller, it seems like there is a variable mismatch. You are assigning the result of search_read() to the values ​​variable, but you are returning fetch_usd instead. You should change return fetch_usd to return values ​​to return the data fetched from the server.

@http.route('/btc', auth='public', type='json', methods=['POST', 'GET'], csrf=False) def all_bitcoin_usd(self, **kwargs):
print
( 'Calling this method >>>')
values ​​= http.request.env['usd.btc'].search_read([], ['name', 'date', 'amount'])
print('fetch usd ', values)
return values


In addition to the variable mismatch, you may also want to make sure that the data you are returning from your controller is in the expected format in your JavaScript code. Currently, you are accessing fetch_usd['date'] and fetch_usd['amount'] , but your server-side code is returning a list of dictionaries with keys 'name' , 'date' , and 'amount' .


Hope this will help you

Thanks

1
Avatar
Descartar
Jay
Autor

Hi Mehjabin Farsana,
I have updated my code kindly check, and I am getting this error "Object of type date is not JSON serializable", dispite including default =date_utils.default.
I am also not loading the data from the Javascript end coz I am getting this error from the console:
pattern_waves_3.svg: Failed to load resource: the server responded with a status of 500 (INTERNAL SERVER ERROR).

I am also getting these errors from the console:
bitcoin.s_bitcoin_chart already defined
at odoo.define (web.assets_frontend_minimal.min.js:22:29)
at web.assets_frontend_lazy.min.js:10325:131
at web.assets_frontend_minimal.min.js:9:63
at new Promise (<anonymous>)
at processJob (web.assets_frontend_minimal.min.js:9:9)
at Object.processJobs (web.assets_frontend_minimal.min.js:17:1)
at odoo.define (web.assets_frontend_minimal.min.js:23:293)
at web.assets_frontend_lazy.min.js:10325:131
at web.assets_frontend_minimal.min.js:9:63
at new Promise (<anonymous>)

What could be the issue?

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
Can't log the console inside the include javascript Odoo v16 Solved
javascript odoo16features
Avatar
Avatar
1
d’abr. 24
3180
Odoo 16.0 CE - Missing widget: radio_reduce_selection for field of type selection
javascript odoo16features
Avatar
0
de gen. 24
2691
What is the Best Practice for Integrating JavaScript in Odoo 16?
javascript odoo16features
Avatar
Avatar
1
de set. 23
4319
Odoo 16 JavaScript: TypeError: utils.getComponent(...).IsCustomButton is not a function
javascript odoo16features
Avatar
Avatar
2
d’abr. 23
6530
How to call javascript on button click Solved
javascript odoo16features
Avatar
Avatar
2
de gen. 23
9004
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