Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

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

Naroči se

Get notified when there's activity on this post

This question has been flagged
javascriptpythonrpcodooodoo12
2 Odgovori
7976 Prikazi
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
Opusti
Avatar
Raciel Perdomo Gómez
Best Answer

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
Opusti
Avatar
Jos De Graeve - Accomodata
Best Answer

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
Opusti
Enjoying the discussion? Don't just read, join in!

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

Prijavi
Related Posts Odgovori Prikazi Aktivnost
rpc.query doesn't work
javascript rpc odoo
Avatar
Avatar
1
avg. 23
411
Call wizard view in js function
javascript python odoo
Avatar
Avatar
1
dec. 22
4370
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
14324
Display header only on the first page and footer on the last page Qweb Odoo 14
javascript python xml odoo
Avatar
Avatar
Avatar
2
avg. 24
7717
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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