Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Get first record from another object?

By
Jo
on 1/10/15, 6:26 AM 1,275 views

hello all,

Here i want to know how to get the first record of a table.

here is my code, please correct it....

    user_ids = self.pool.get('test.project').browse(cr, uid, ids, context=context)

    user_ids[0]

Thanks in advance...

1

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 1/10/15, 9:30 AM

I suggest you use this, the safe construction:

test_obj = self.pool.get('test.project')
user_ids = test_obj.search(cr, uid, [('id','in',ids)], context=context)
if user_ids:
    first_record =  test_obj.browse(cr, uid, user_ids[0], context=context)
    first_ID =  user_ids[0]

UPDATE: Full user_ids list from test.project:

user_ids = test_obj.search(cr, uid, [], context=context)
 

Hi, This user_ids doesn't return any ids to browse records!!!

Jo
on 1/10/15, 11:43 AM

Hi, This user_ids doesn't return any ids to browse records!!!

Jo
on 1/10/15, 11:44 AM

user_ids empty if... all test.project empty or... if your source ids empty or.... source ids not from test.project. What are your ids?

zbik
on 1/10/15, 11:54 AM

hi, i i'm searching and browsing from another class function, so there is no source ids from test.project. what i do next? please

Jo
on 1/10/15, 11:59 AM

If you need a full and complete list of the user_ids from test.project, see UPDATE in my answer

zbik
on 1/10/15, 12:07 PM

Thanks

Jo
on 1/10/15, 12:25 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/10/15, 6:26 AM
Seen: 1275 times
Last updated: 3/16/15, 8:10 AM