Reputation: 340
I'm trying to retrieve the current ID from a postgresql database using openERP. This is my function (inside a class):
def get_id(self, cr):
cr.execute("SELECT id FROM table ORDER BY id DESC LIMIT 1")
id = cr.fetchone()[0]
return id
Then, I am calling the function this way:
'last_id':fields.function(get_id, method = True, string = 'ID Number', type = 'integer')
But I'm getting following error:
TypeError: get_id() takes exactly 2 arguments (7 given)
what am I doing wrong?
Upvotes: 0
Views: 138
Reputation: 980
You can do it like this.
def get_id(self, cr, uid, ids, fields, arg, context=None):
res = {}
for field in fields:
cr.execute("SELECT id FROM table ORDER BY id DESC LIMIT 1")
id = cr.fetchone()[0]
res[ids[0]][field] = id
return res
Upvotes: 1
Reputation: 3207
You have not defined function syntax correctly.
def get_id (self, cr, uid, ids, fields, arg, context=None):
res = {}
cr.execute("SELECT id FROM table ORDER BY id DESC LIMIT 1")
id = cr.fetchone()[0]
res[ids[0]] = id
return res
Do some thing like this
please read this doc. https://doc.openerp.com/v6.0/developer/2_5_Objects_Fields_Methods/field_type.html
Hope this will be helpful.
Upvotes: 1