Jay Venkat
Jay Venkat

Reputation: 397

Method read declaration in odoo 8

In openerp ,

 data = self.read(cr, uid, ids, [], context=context)[0]

What is the equivalent statement of above in odoo 8. I am getting wrong result when I used the below statement.

data = self.with_context(context).browse(self.ids)[0]

I am new to odoo 8, Please help me on this...

Upvotes: 0

Views: 2044

Answers (2)

littlegreen
littlegreen

Reputation: 7420

Quite often I am lazy and just use the V7 api. It still works fine.

@api.v8
def function_i_want_to_edit_that_uses_v8_api(self):
    # omg where are my cr and uid objects
    # oh... i can just smuggle :-P
    data = self.browse(self._cr, self._uid, self._ids, context=self._context)

But this should also work:

@api.v8
def function_i_want_to_edit_that_uses_v8_api(self):
    data = self.browse(self._ids)

Maybe the only problem is the missing _? Also make sure that any functions in which you use this are v8-enabled, eg. decorated with @api.v8 or similar.

Upvotes: 2

Atul Arvind
Atul Arvind

Reputation: 16743

Here is example of browse and read method in odoo v7 which method called from button.

def call_button(self, cr, uid, ids, context=None):
    if not context: context = {}
    for rec in self.browse(cr, uid, ids, context=context):
        print rec.name
    '''or '''
    for rec in self.read(cr, uid, ids, context=context):
        print rec.get('name')

if you need to write the same method in odoo v8 you can write like,

@api.one
def call_button(self):
    print self # which will return you a record set using you can directly access fields and method of that model
    print self.read() # which will return you a list of dictionary

and if you want to pass context you can use with_context with your environment.

hope this helps.

Upvotes: 0

Related Questions