Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

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

Odoberať

Get notified when there's activity on this post

This question has been flagged
javascriptpythonrpcodooodoo12
2 Replies
7997 Zobrazenia
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
Zrušiť
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
Zrušiť
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
Zrušiť
Enjoying the discussion? Don't just read, join in!

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

Registrácia
Related Posts Replies Zobrazenia Aktivita
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
4388
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
14359
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
7769
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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