Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

Calling create method gives NameError (Odoo 12)

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
javascriptpythoncreateNameErrorodoo12
2 Răspunsuri
4809 Vizualizări
Imagine profil
Steven Deweirt

Hi

I'm having trouble calling the Create method in Python and it's throwing a NameError. The method that calls the Create method is called from JS.

Here is the JS (this works so maybe less important):

this._rpc({
model:'tcx.call.log',
method:'maakTest',
args:[
pId,
pName,
pNumber,
cDuration,
datum,
],
});

This is the Python code:

@api.one
def maakTest(partner_id, other_party_name, other_party_number, duration, call_date_time):
import pdb; pdb.set_trace()
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}
self.create(vals)

Here is the error:


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 749, in call_kw
    return _call_kw_multi(method, model, args, kwargs)
  File "/opt/odoo/odoo/odoo/api.py", line 736, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "</usr/local/lib/python3.6/dist-packages/decorator.py:decorator-gen-132>", line 2, in maakTest
  File "/opt/odoo/odoo/odoo/api.py", line 372, in loop
    result = [method(rec, *args, **kwargs) for rec in self]
  File "/opt/odoo/odoo/odoo/api.py", line 372, in <listcomp>
    result = [method(rec, *args, **kwargs) for rec in self]
  File "/opt/odoo/odoo/custom_addons/threecx/models/call_log.py", line 27, in maakTest
    self.create(vals)
NameError: name 'self' is not defined

Now, I do know that I haven't defined 'self' in ths case, but I'm wondering on how to do it. Adding it to the parameter list in the method header and then adding null in JavaScript isn't working and I don't see any other way of calling the create method.

Any help is greatly appreciated!

0
Imagine profil
Abandonează
Imagine profil
Sudhir Arya (ERP Harbor Consulting Services)
Cel mai bun răspuns

You forgot to pass self in your method definition and also use "@api.model" instead of "@api.one"..

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


4
Imagine profil
Abandonează
Steven Deweirt
Autor

When I add self to the method definition I get another error saying I'm missing 1 required positional argument (call_date_time). How should I pass self as an argument in my JS?

Sudhir Arya (ERP Harbor Consulting Services)

Remove @api.one and use @api.model

Imagine profil
Jos De Graeve - Accomodata
Cel mai bun răspuns

Hi,

The signature of your method misses the "self" argument.  Also use @api.model

Writing it like this should fix your problem:


    @api.model
def maakTest(self, partner_id, other_party_name, other_party_number, duration, call_date_time):
import pdb; pdb.set_trace()
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}
self.create(vals)


2
Imagine profil
Abandonează
Steven Deweirt
Autor

When I add self to the method definition I get another error saying I'm missing 1 required positional argument (call_date_time). How should I pass self as an argument in my JS?

Jos De Graeve - Accomodata

use @api.model - i edited my answer.

Enjoying the discussion? Don't just read, join in!

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

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
RPC calling python function does not return data from view
javascript python rpcjson odoo12
Imagine profil
Imagine profil
Imagine profil
Imagine profil
4
iul. 20
9105
Trying to call a Python method from JS Error (Odoo 12) Rezolvat
javascript python rpc odoo odoo12
Imagine profil
Imagine profil
Imagine profil
2
iun. 19
7991
Call python function from Javascript in Odoo12 Rezolvat
javascript python model fucntion odoo12
Imagine profil
Imagine profil
1
dec. 18
13525
No handler found error on email validation?
javascript python
Imagine profil
Imagine profil
1
iun. 25
4956
Create Journal Entries whit code Rezolvat
python odoo12
Imagine profil
Imagine profil
Imagine profil
2
aug. 25
7334
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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