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

Making use of Old API style method in Odoo 10.0

Iscriviti

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

La domanda è stata contrassegnata
Odoo10.0BridgingOldAPINewAPIFunctionCall
3 Risposte
7402 Visualizzazioni
Avatar
Komala Kiran Kumar. Parepalli

Hi Guys,

As per the Odoo documentation given at https://www.odoo.com/documentation/10.0/reference/orm.html#compatibility-between-new-api-and-old-api, it specifies I can make use of the old style method in Odoo 10.0 and the Odoo itself will decorate it appropriately (Automatic Bridging).

But I couldn't quite get it right. I have written a sample class with 2 methods one with Old API style and the Other with new API style, but I was unable to make a call to the old method successfully.


Here is the sample code I was using:

from odoo import models, fields, api

class SampleModule(models.Model):
_name = 'sample.module'

column_one = fields.Char("Column One")
column_two = fields.Char("Column Two")
column_three = fields.Char("Column Three")

def old_method(self, cr, uid, ids):
print self, cr, uid, ids
return True

def new_method(self):
return self.old_method()

Note: I even tried decorating the Old method with @api.cr_uid_ids

When I make a call to the new_method() from a button it is always returning with an error saying old_method requires 4 arguments but only 2 given.

File "/var/www/electrickiwi-nest/www/odoo/addons/web/controllers/main.py", line 889, in call_button
    action = self._call_kw(model, method, args, {})
  File "/var/www/electrickiwi-nest/www/odoo/addons/web/controllers/main.py", line 877, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/var/www/electrickiwi-nest/www/odoo/api.py", line 682, in call_kw
    return call_kw_multi(method, model, args, kwargs)
  File "/var/www/electrickiwi-nest/www/odoo/api.py", line 673, in call_kw_multi
    result = method(recs, *args, **kwargs)
TypeError: old_method() takes exactly 4 arguments (2 given)


Can someone please help me with this. Not sure if I am missing anything here.

Thanks in advance.


0
Avatar
Abbandona
Esther Martín

I dont know which method is, but you should try api.multi, if that doesnt work it should be api.model

Komala Kiran Kumar. Parepalli
Autore

Hi Esther, Thanks for the suggestion.

As per my understanding on the Odoo documentation api.Model & api.Multi are to decorate on the new_method to make it callable from Old_method. (Call New API method from an Old API method). Not sure if I am missing anything but certainly I can try.

Thank you once again.

Raaj Mishra

Hi Kiran, if you find any solution for this pls update, as I also need the implement somthing like that, I am also trying the same from myside.

Raaj Mishra

I reviewed the doc and saw somthing like which we can try:

odoo.api.v8(method_v8)

Decorate a method that supports the new-style api only. An old-style api may be provided by redefining a method with the same name and decorated with v7():

@api.v8

def foo(self):

...

@api.v7

def foo(self, cr, uid, ids, context=None):

Komala Kiran Kumar. Parepalli
Autore

Hi Raaj, I actually tried this but didn't find it useful. As far as I understand it will be useful to have the same function with 2 different styles (Old & New API). But this is not useful if you want to have a function just in Old API style of coding.

Cheers.

Avatar
Denis Baranov
Risposta migliore

Hey,

If you don't use any decorator for your old method to pass the values (in case you utilize an already existing method), try to pass the required parameteres directly through the environment (env):

self.old_method(cr=self.env.cr, uid=self.env.user.id, ids=seld.ids)
1
Avatar
Abbandona
Raaj Mishra

Yes it working thanks..just one spell mistake...ids=seld.ids it should be self.ids

Komala Kiran Kumar. Parepalli
Autore

Hey, thanks for the suggestion. But the question here is its not given in the documentation like that and the whole intention is to call an Old API style method using a button from the form.

If I want to use as you said then I need to write a wrapper method in New API style to call the old method for each method I want to make use of.

In the way, you suggested you are making them be treated as the explicit arguments/user defined arguments but not framework default arguments.

Anyways thanks for the suggestion.

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à
Is there any dictionary/material to convert Old API to New API?
odoo7 odoo11 OldAPI NewAPI
Avatar
Avatar
1
nov 17
5070
Readonly field disappears when saved in odoo 10.
Odoo10.0
Avatar
Avatar
1
mar 23
3269
How to pass a value from sale.order to stock.picking? Risolto
Odoo10.0
Avatar
Avatar
Avatar
Avatar
3
ago 19
14172
READONLY PRICE UNIT Risolto
Odoo10.0
Avatar
Avatar
7
lug 19
5462
how to change font size entire odoo frontend without website depedancey module
Odoo10.0
Avatar
0
giu 19
3987
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