Skip to Content
Menu
This question has been flagged

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.


Avatar
Discard

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

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.

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.

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):

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.

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)
Avatar
Discard

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

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.

Related Posts Replies Views Activity
1
Nov 17
3535
1
Mar 23
1251
3
Aug 19
11085
7
Jul 19
3597
0
Jun 19
2246