Reputation: 3907
I just want to know, how can some functions be translated into the new API, or if there is need to fully translate them, depending on what api call are we using.
For example,
@api.model
the method is exposed as not using ids, its recordset will generally be empty. Its "old API" signature is cr, uid, *arguments, context:
@api.model
def some_method(self, a_value):
pass
# can be called as
old_style_model.some_method(cr, uid, a_value, context=context)
On Odoo v8, suppose I have this kind of function:
def update_info(self, cr, uid, ids, context=None):
""" OpenERP osv memory wizard : update_info_partner
"""
context = context or {}
seniat_url_obj = self.env('seniat.url')
self.cr.execute('''SELECT id FROM res_partner WHERE vat ilike 'VE%';''')
record = self.cr.fetchall()
pids = [item[0] for item in record]
seniat_url_obj.connect_seniat(cr, uid, pids, context=context,
all_rif=True)
return{}
If I add @api.model
decorator to this function, I guess I also need to update the attributes of it, ie: self, cr, uid, ids, context=None
, right?
In this case, it is sufficient, to add @api.model
decorator and then change the function attributes to only self
?
I'm just trying to get how to work this out, from now on, since I'm mirgating some modules from v8 to v10.
Upvotes: 1
Views: 863
Reputation: 14801
As you've written by yourself
the method is exposed as not using ids, its recordset will generally be empty.
api.model
is more of a static method thing, in odoo ORM context. For python itself it's ofcourse not a static method. If you're working with records (database records as python objects) use api.multi
or api.one
. If you don't have records at all, for example the ORM create()
, use api.model
.
"Translating" old methods to the new API could be considered very easy, for this topic only. If you see ids
or id
or maybe <model>_id(s)
in the method parameters, it's probably api.multi
or api.one
. And if you don't have em: api.model
. Exceptions are compute, onchange and constraint methods.
Upvotes: 2