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.
I dont know which method is, but you should try api.multi, if that doesnt work it should be api.model
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):
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.