Overslaan naar inhoud
Odoo Menu
  • Aanmelden
  • Probeer het gratis
  • Apps
    Financiën
    • Boekhouding
    • Facturatie
    • Onkosten
    • Spreadsheet (BI)
    • Documenten
    • Ondertekenen
    Verkoop
    • CRM
    • Verkoop
    • Kassasysteem winkel
    • Kassasysteem Restaurant
    • Abonnementen
    • Verhuur
    Websites
    • Websitebouwer
    • E-commerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Bevoorradingsketen
    • Voorraad
    • Productie
    • PLM
    • Inkoop
    • Onderhoud
    • Kwaliteit
    Personeelsbeheer
    • Werknemers
    • Werving & Selectie
    • Verlof
    • Evaluaties
    • Aanbevelingen
    • Wagenpark
    Marketing
    • Sociale media-marketing
    • E-mailmarketing
    • Sms-marketing
    • Evenementen
    • Marketingautomatisering
    • Enquêtes
    Diensten
    • Project
    • Urenstaten
    • Buitendienst
    • Helpdesk
    • Planning
    • Afspraken
    Productiviteit
    • Chat
    • Goedkeuringen
    • IoT
    • VoIP
    • Kennis
    • WhatsApp
    Apps van derden Odoo Studio Odoo Cloud Platform
  • Bedrijfstakken
    Detailhandel
    • Boekhandel
    • kledingwinkel
    • Meubelzaak
    • Supermarkt
    • Bouwmarkt
    • Speelgoedwinkel
    Food & Hospitality
    • Bar en Pub
    • Restaurant
    • Fastfood
    • Gastenverblijf
    • Drankenhandelaar
    • Hotel
    Vastgoed
    • Makelaarskantoor
    • Architectenbureau
    • Bouw
    • Vastgoedbeheer
    • Tuinieren
    • Vereniging van eigenaren
    Consulting
    • Accountantskantoor
    • Odoo Partner
    • Marketingbureau
    • Advocatenkantoor
    • Talentenwerving
    • Audit & Certificering
    Productie
    • Textiel
    • Metaal
    • Meubels
    • Eten
    • Brewery
    • Relatiegeschenken
    Gezondheid & Fitness
    • Sportclub
    • Opticien
    • Fitnesscentrum
    • Wellness-medewerkers
    • Apotheek
    • Kapper
    Trades
    • Klusjesman
    • IT-hardware & support
    • Zonne-energiesystemen
    • Schoenmaker
    • Schoonmaakdiensten
    • HVAC-diensten
    Andere
    • Non-profitorganisatie
    • Milieuagentschap
    • Verhuur van Billboards
    • Fotograaf
    • Fietsleasing
    • Softwareverkoper
    Browse all Industries
  • Community
    Leren
    • Tutorials
    • Documentatie
    • Certificeringen
    • Training
    • Blog
    • Podcast
    Versterk het onderwijs
    • Onderwijs- programma
    • Scale Up! Business Game
    • Bezoek Odoo
    Download de Software
    • Downloaden
    • Vergelijk edities
    • Releases
    Werk samen
    • Github
    • Forum
    • Evenementen
    • Vertalingen
    • Word een Partner
    • Services for Partners
    • Registreer je accountantskantoor
    Diensten
    • Vind een partner
    • Vind een boekhouder
    • Een adviseur ontmoeten
    • Implementatiediensten
    • Klantreferenties
    • Ondersteuning
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Vraag een demo aan
  • Prijzen
  • Help

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

  • CRM
  • e-Commerce
  • Boekhouding
  • Voorraad
  • PoS
  • Project
  • MRP
All apps
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Alle posts Personen Badges
Labels (Bekijk alle)
odoo accounting v14 pos v15
Over dit forum
Help

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

Inschrijven

Ontvang een bericht wanneer er activiteit is op deze post

Deze vraag is gerapporteerd
javascriptsnippetsodoo16features
1 Beantwoorden
6034 Weergaven
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
Annuleer
Avatar
Mehjabin Farsana
Beste antwoord

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
Annuleer
Jay
Auteur

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?

Geniet je van het gesprek? Blijf niet alleen lezen, doe ook mee!

Maak vandaag nog een account aan om te profiteren van exclusieve functies en deel uit te maken van onze geweldige community!

Aanmelden
Gerelateerde posts Antwoorden Weergaven Activiteit
Can't log the console inside the include javascript Odoo v16 Opgelost
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
jan. 24
2691
What is the Best Practice for Integrating JavaScript in Odoo 16?
javascript odoo16features
Avatar
Avatar
1
sep. 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 Opgelost
javascript odoo16features
Avatar
Avatar
2
jan. 23
9004
Community
  • Tutorials
  • Documentatie
  • Forum
Open Source
  • Downloaden
  • Github
  • Runbot
  • Vertalingen
Diensten
  • Odoo.sh Hosting
  • Ondersteuning
  • Upgrade
  • Gepersonaliseerde ontwikkelingen
  • Onderwijs
  • Vind een boekhouder
  • Vind een partner
  • Word een Partner
Over ons
  • Ons bedrijf
  • Merkelementen
  • Neem contact met ons op
  • Vacatures
  • Evenementen
  • Podcast
  • Blog
  • Klanten
  • Juridisch • Privacy
  • Beveiliging
الْعَرَبيّة 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 is een suite van open source zakelijke apps die aan al je bedrijfsbehoeften voldoet: CRM, E-commerce, boekhouding, inventaris, kassasysteem, projectbeheer, enz.

Odoo's unieke waardepropositie is om tegelijkertijd zeer gebruiksvriendelijk en volledig geïntegreerd te zijn.

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