Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Making use of Old API style method in Odoo 10.0

Subscribe

Get notified when there's activity on this post

This question has been flagged
Odoo10.0BridgingOldAPINewAPIFunctionCall
3 Replies
7397 Views
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
Discard
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
Author

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
Author

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
Best Answer

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
Discard
Raaj Mishra

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

Komala Kiran Kumar. Parepalli
Author

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.

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

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

Sign up
Related Posts Replies Views Activity
Is there any dictionary/material to convert Old API to New API?
odoo7 odoo11 OldAPI NewAPI
Avatar
Avatar
1
Nov 17
5065
Readonly field disappears when saved in odoo 10.
Odoo10.0
Avatar
Avatar
1
Mar 23
3266
How to pass a value from sale.order to stock.picking? Solved
Odoo10.0
Avatar
Avatar
Avatar
Avatar
3
Aug 19
14160
READONLY PRICE UNIT Solved
Odoo10.0
Avatar
Avatar
7
Jul 19
5458
how to change font size entire odoo frontend without website depedancey module
Odoo10.0
Avatar
0
Jun 19
3970
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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