Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Approvazioni
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto

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

  • CRM
  • e-Commerce
  • Contabilità
  • Magazzino
  • PoS
  • Progetti
  • MRP
All apps
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

Calling create method gives NameError (Odoo 12)

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
javascriptpythoncreateNameErrorodoo12
2 Risposte
4799 Visualizzazioni
Avatar
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
Avatar
Abbandona
Avatar
Sudhir Arya (ERP Harbor Consulting Services)
Risposta migliore

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
Avatar
Abbandona
Steven Deweirt
Autore

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

Avatar
Jos De Graeve - Accomodata
Risposta migliore

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
Avatar
Abbandona
Steven Deweirt
Autore

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.

Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
RPC calling python function does not return data from view
javascript python rpcjson odoo12
Avatar
Avatar
Avatar
Avatar
4
lug 20
9100
Trying to call a Python method from JS Error (Odoo 12) Risolto
javascript python rpc odoo odoo12
Avatar
Avatar
Avatar
2
giu 19
7991
Call python function from Javascript in Odoo12 Risolto
javascript python model fucntion odoo12
Avatar
Avatar
1
dic 18
13517
No handler found error on email validation?
javascript python
Avatar
Avatar
1
giu 25
4952
Create Journal Entries whit code Risolto
python odoo12
Avatar
Avatar
Avatar
2
ago 25
7324
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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