Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

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

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
javascriptsnippetsodoo16features
1 Rispondi
6032 Visualizzazioni
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
Abbandona
Avatar
Mehjabin Farsana
Risposta migliore

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
Abbandona
Jay
Autore

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?

Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
Can't log the console inside the include javascript Odoo v16 Risolto
javascript odoo16features
Avatar
Avatar
1
apr 24
3180
Odoo 16.0 CE - Missing widget: radio_reduce_selection for field of type selection
javascript odoo16features
Avatar
0
gen 24
2691
What is the Best Practice for Integrating JavaScript in Odoo 16?
javascript odoo16features
Avatar
Avatar
1
set 23
4319
Odoo 16 JavaScript: TypeError: utils.getComponent(...).IsCustomButton is not a function
javascript odoo16features
Avatar
Avatar
2
apr 23
6527
How to call javascript on button click Risolto
javascript odoo16features
Avatar
Avatar
2
gen 23
9004
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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