Skip to Content
Odoo Menu
  • Log ind
  • Prøv gratis
  • Apps
    Økonomi
    • Bogføring
    • Fakturering
    • Udgifter
    • Regneark (BI)
    • Dokumenter
    • e-Signatur
    Salg
    • CRM
    • Salg
    • POS Butik
    • POS Restaurant
    • Abonnementer
    • Udlejning
    Hjemmeside
    • Hjemmesidebygger
    • e-Handel
    • Blog
    • Forum
    • LiveChat
    • e-Læring
    Forsyningskæde
    • Lagerbeholdning
    • Produktion
    • PLM
    • Indkøb
    • Vedligeholdelse
    • Kvalitet
    HR
    • Medarbejdere
    • Rekruttering
    • Fravær
    • Medarbejdersamtaler
    • Anbefalinger
    • Flåde
    Marketing
    • Markedsføring på sociale medier
    • E-mailmarketing
    • SMS-marketing
    • Arrangementer
    • Automatiseret marketing
    • Spørgeundersøgelser
    Tjenester
    • Projekt
    • Timesedler
    • Udkørende Service
    • Kundeservice
    • Planlægning
    • Aftaler
    Produktivitet
    • Dialog
    • Godkendelser
    • IoT
    • VoIP
    • Vidensdeling
    • WhatsApp
    Tredjepartsapps Odoo Studio Odoo Cloud-platform
  • Brancher
    Detailhandel
    • Boghandel
    • Tøjforretning
    • Møbelforretning
    • Dagligvarebutik
    • Byggemarked
    • Legetøjsforretning
    Mad og værtsskab
    • Bar og pub
    • Restaurant
    • Fastfood
    • Gæstehus
    • Drikkevareforhandler
    • Hotel
    Ejendom
    • Ejendomsmægler
    • Arkitektfirma
    • Byggeri
    • Ejendomsadministration
    • Havearbejde
    • Boligejerforening
    Rådgivning
    • Regnskabsfirma
    • Odoo-partner
    • Marketingbureau
    • Advokatfirma
    • Rekruttering
    • Audit & certificering
    Produktion
    • Tekstil
    • Metal
    • Møbler
    • Fødevareproduktion
    • Bryggeri
    • Firmagave
    Heldbred & Fitness
    • Sportsklub
    • Optiker
    • Fitnesscenter
    • Kosmetolog
    • Apotek
    • Frisør
    Håndværk
    • Handyman
    • IT-hardware og support
    • Solenergisystemer
    • Skomager
    • Rengøringsservicer
    • VVS- og ventilationsservice
    Andet
    • Nonprofitorganisation
    • Miljøagentur
    • Udlejning af billboards
    • Fotografi
    • Cykeludlejning
    • Softwareforhandler
    Gennemse alle brancher
  • Community
    Få mere at vide
    • Tutorials
    • Dokumentation
    • Certificeringer
    • Oplæring
    • Blog
    • Podcast
    Bliv klogere
    • Udannelselsesprogram
    • Scale Up!-virksomhedsspillet
    • Besøg Odoo
    Få softwaren
    • Download
    • Sammenlign versioner
    • Udgaver
    Samarbejde
    • Github
    • Forum
    • Arrangementer
    • Oversættelser
    • Bliv partner
    • Tjenester til partnere
    • Registrér dit regnskabsfirma
    Modtag tjenester
    • Find en partner
    • Find en bogholder
    • Kontakt en rådgiver
    • Implementeringstjenester
    • Kundereferencer
    • Support
    • Opgraderinger
    Github Youtube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Få en demo
  • Prissætning
  • Hjælp

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

  • CRM
  • e-Commerce
  • Bogføring
  • Lager
  • PoS
  • Projekt
  • MRP
All apps
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Du skal være registreret for at interagere med fællesskabet.
All Posts People Emblemer
Tags (View all)
odoo accounting v14 pos v15
Om dette forum
Hjælp

Trying to call a Python method from JS Error (Odoo 12)

Tilmeld

Få besked, når der er aktivitet på dette indlæg

Dette spørgsmål er blevet anmeldt
javascriptpythonrpcodooodoo12
2 Besvarelser
7989 Visninger
Avatar
Steven Deweirt

Hi

So I'm trying to call a Python method from JavaScript and it's producing a certain error. I tried following guidelines on how to call methods but I think there's something wrong with the arguments.

Here is the Python method:

 @api.model
def maakTest(partner_id, other_party_name, other_party_number, duration, call_date_time):
#def maakTest(partner_id, other_party_name, other_party_number, duration, call_date_time):
self.partner_id = partner_id
self.other_party_name = other_party_name
self.other_party_number = other_party_number
self.note = duration
self.call_date_time = call_date_time
vals = {'partner_id':self.partner_id,'other_party_name':self.other_party_name,'other_party_number':self.other_party_number,'duration':self.duration,'call_date_time':self.call_date_time}
self.create(vals)

Here is the JS method (specifically in bold):

handleEnded: function (cmd) {
var self = this;
self.$(".phonering-alo-ph-img-circle").css("visibility","hidden");
if (cmd.CallID == self.callId) {
if (self.callState == "Ringing") {
// Show missed call screen
}

else if (self.callState == "Connected") {
self.stopTimer();
self.$(".tcx_button_end_call").css("display", "none");
self.$(".dial_pad").css("display", "none");
//self.$(".tcx_now_number").css("display","none");
//self.$(".tcx_backspace").css("display","none");
this.hideDialPad();
}

self.$(".tcx_mute_hold").css("display", "none");
this.callState = "Ended";

var today = new Date();
var y = today.getFullYear().toString();
var m = (today.getMonth() + 1).toString();
var d = today.getDate().toString();
(d.length == 1) && (d = '0' + d);
(m.length == 1) && (m = '0' + m);
var datum = y + '-' + m + '-' + d;

console.log(this.partnerId);
console.log(this.partnerName);
console.log(this.partnerNumber);
console.log(this.callDuration);
console.log(datum);

var pId = this.partnerId;
var pName = this.partnerName;
var pNumber = this.partnerNumber;
var cDuration = this.callDuration;
this._rpc({
model:'tcx.call.log',
method:'maakTest',

args:[{
'other_party_number': pNumber,
'duration': cDuration,
'call_date_time': datum,
'partner_id': pId,
'other_party_name': pName,
}],

});
}
}


Here is the error I'm getting in Odoo:


Traceback (most recent call last):
  File "/opt/odoo/odoo/odoo/http.py", line 654, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/odoo/odoo/http.py", line 312, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "/opt/odoo/odoo/odoo/tools/pycompat.py", line 87, in reraise
    raise value
  File "/opt/odoo/odoo/odoo/http.py", line 696, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/odoo/odoo/http.py", line 344, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/odoo/odoo/service/model.py", line 97, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/odoo/odoo/http.py", line 337, in checked_call
    result = self.endpoint(*a, **kw)
  File "/opt/odoo/odoo/odoo/http.py", line 939, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/odoo/odoo/http.py", line 517, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/odoo/addons/web/controllers/main.py", line 962, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/opt/odoo/odoo/addons/web/controllers/main.py", line 954, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/opt/odoo/odoo/odoo/api.py", line 745, in call_kw
    return _call_kw_model(method, model, args, kwargs)
  File "/opt/odoo/odoo/odoo/api.py", line 718, in _call_kw_model
    result = method(recs, *args, **kwargs)
TypeError: maakTest() missing 3 required positional arguments: 'other_party_number', 'duration', and 'call_date_time'

I'm also getting a JS error but it seems to be the same one:

web.assets_common.js:3555
 Server application error {"code":200,"message":"Odoo Server 
Error","data":{"name":"builtins.TypeError","debug":"Traceback (most 
recent call last):\n  File \"/opt/odoo/odoo/odoo/http.py\", line 654, in
 _handle_exception\n    return
 super(JsonRequest, self)._handle_exception(exception)\n  File 
\"/opt/odoo/odoo/odoo/http.py\", line 312, in _handle_exception\n    
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])\n 
 File \"/opt/odoo/odoo/odoo/tools/pycompat.py\", line
 87, in reraise\n    raise value\n  File 
\"/opt/odoo/odoo/odoo/http.py\", line 696, in dispatch\n    result = 
self._call_function(**self.params)\n  File 
\"/opt/odoo/odoo/odoo/http.py\", line 344, in _call_function\n    return
 checked_call(self.db, *args, **kwargs)\n 
 File \"/opt/odoo/odoo/odoo/service/model.py\", line 97, in wrapper\n   
 return f(dbname, *args, **kwargs)\n  File 
\"/opt/odoo/odoo/odoo/http.py\", line 337, in checked_call\n    result =
 self.endpoint(*a, **kw)\n  File \"/opt/odoo/odoo/odoo/http.py\", line
 939, in __call__\n    return self.method(*args, **kw)\n  File 
\"/opt/odoo/odoo/odoo/http.py\", line 517, in response_wrap\n    
response = f(*args, **kw)\n  File 
\"/opt/odoo/odoo/addons/web/controllers/main.py\", line 962, in 
call_kw\n    return self._call_kw(model,
 method, args, kwargs)\n  File 
\"/opt/odoo/odoo/addons/web/controllers/main.py\", line 954, in 
_call_kw\n    return call_kw(request.env[model], method, args, 
kwargs)\n  File \"/opt/odoo/odoo/odoo/api.py\", line 745, in call_kw\n   
 return _call_kw_model(method,
 model, args, kwargs)\n  File \"/opt/odoo/odoo/odoo/api.py\", line 718, 
in _call_kw_model\n    result = method(recs, *args, 
**kwargs)\nTypeError: maakTest() missing 3 required positional 
arguments: 'other_party_number', 'duration', and 
'call_date_time'\n","message":"maakTest()
 missing 3 required positional arguments: 'other_party_number', 
'duration', and 'call_date_time'","arguments":["maakTest() missing 3 
required positional arguments: 'other_party_number', 'duration', and 
'call_date_time'"],"exception_type":"internal_error"}}
(anonymous) @ web.assets_common.js:3555
         

Any help would be greatly appreciated.



0
Avatar
Kassér
Avatar
Raciel Perdomo Gómez
Bedste svar

You are passing a single parameter to the function, which is a dictionary.

Instead of passing a dictionary, pass all variables like:


this._rpc({
model:'tcx.call.log',
method:'maakTest',

args:[pNumber,
cDuration,
datum,
pId,
pName,
],

});
}
0
Avatar
Kassér
Avatar
Jos De Graeve - Accomodata
Bedste svar

Hi,

Your python method misses the "self" parameter:

Try this:


    @api.model
def maakTest(self, partner_id, other_party_name, other_party_number, duration, call_date_time):

vals = {'partner_id': partner_id,'other_party_name': other_party_name,'other_party_number': other_party_number,'duration':duration,'call_date_time': call_date_time}
return self.create(vals)

Basically:

* @api.model is ok for a create() function that does not operate on a recordset

* make sure self is the first parameter!

* just put the right parameters i a dictionairy, assigning them first with self.val = val is useless and might cause errors/unintended side effects.

* make sure to return the newly created record


1
Avatar
Kassér
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Tilmeld dig
Related Posts Besvarelser Visninger Aktivitet
rpc.query doesn't work
javascript rpc odoo
Avatar
Avatar
1
aug. 23
411
Call wizard view in js function
javascript python odoo
Avatar
Avatar
1
dec. 22
4382
TypeError: Cannot read property 'taxes_by_id' of undefined at DiscountButton.apply_discount
javascript python odoo
Avatar
0
dec. 20
50
How to call JavaScript from python function?
javascript python odoo
Avatar
0
dec. 15
14339
Display header only on the first page and footer on the last page Qweb Odoo 14
javascript python xml odoo
Avatar
Avatar
Avatar
2
aug. 24
7745
Community
  • Tutorials
  • Dokumentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Oversættelser
Tjenester
  • Odoo.sh-hosting
  • Support
  • Opgradere
  • Individuelt tilpasset udvikling
  • Uddannelse
  • Find en bogholder
  • Find en partner
  • Bliv partner
Om os
  • Vores virksomhed
  • Brandaktiver
  • Kontakt os
  • Stillinger
  • Arrangementer
  • Podcast
  • Blog
  • Kunder
  • Juridiske dokumenter • Privatlivspolitik
  • Sikkerhedspolitik
الْعَرَبيّة 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 er en samling open source-forretningsapps, der dækker alle dine virksomhedsbehov – lige fra CRM, e-handel og bogføring til lagerstyring, POS, projektledelse og meget mere.

Det unikke ved Odoo er, at systemet både er brugervenligt og fuldt integreret.

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