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.

3

How do I browse all the elements in a list?

By
Adunato
on 5/26/13, 9:53 AM 5,051 views

Currently I use this syntax:

purchase_line_obj = self.pool.get('purchase.order.line')
purchase_line_ids = purchase_line_obj.search(cr, uid, [('id','>',0)])
for purchase_line in purchase_line_obj.browse(cr, uid,  purchase_line_ids,context=context):

I have tried to pass None or 0 to the ids in the 'browse' call to no avail. Is there any way to obtain all the records from 'browse' without having to pass the list of all id's?

8

Sandeep

--Sandeep--
6083
| 6 5 8
Delhi, India
--Sandeep--
Python OpenERP Developer http://in.linkedin.com/pub/sandeep-rana/3b/a16/786/
Sandeep
On 5/26/13, 1:44 PM

Hi This is not a good idea to place id > 0 , actually there will be no 0 for IDs in database, database provide only numeric value for record ids

just do this way:

  purchase_line_obj = self.pool.get('purchase.order.line')
  purchase_line_ids = purchase_line_obj.search(cr, uid, [])   
      for purchase_line_id in purchase_line_ids :
          line=purchase_line_obj.browse(cr, uid,purchase_line_id ,context=context)
          print line.name

Thanks
Sandeep

Thanks, I was hoping that there would be a way to skip the 'search' step and get all the records from the 'browse'method, but this way is at least cleaner

Adunato
on 5/27/13, 6:06 AM
1
Ubaid
On 12/14/15, 11:45 PM

Hi

New API example is:

                order_object = self.env['sales.order']

                order_object_ids = order_object.search(['condition'])

                if order_object_ids:

                     for obj in order_object_ids:

                          order_line = order_object.browse(obj.id)

Thank you, that helped me with new API.

TK Fontaine
on 12/15/15, 6:42 AM
1

Omal Bastin

--Omal Bastin--
1146
| 6 6 8
Kochi, Kerala, India
--Omal Bastin--

Swiming deep into openERP/ODOO

Omal Bastin
On 5/27/13, 5:45 AM

Hi, If you want to get all the purchase order lines related to a purchase order and you have the purchase order id then

po_pool = self.pool.get('purchcase.order')
for po_obj in po_pool.browse(cr, uid, ids,context):
    print 'purchase order>>>>',po_obj.name
    for po_line in po_obj.order_line:#order_line is the field name of purchase order line model in purchase order model
        print 'purchase order line :::',po_line.name
0

Borni DHIFI

--Borni DHIFI--
5102
| 6 8 9
Tunis, Tunisia
--Borni DHIFI--

Techno Functional Consultant Odoo(OpenERP) 

http://www.linkedin.com/in/borni

Skype : dhifi.borni

Borni DHIFI
On 5/26/13, 11:33 AM

Hi,

For example display name for all lines :

purchase_line_obj = self.pool.get('purchase.order.line')
purchase_line_ids = purchase_line_obj.search(cr, uid, [('id','>',0)])
for purchase_line in purchase_line_ids :
    line=purchase_line_obj.browse(cr, uid,  purchase_line,context=context)
    print line.name

Thanks.

Thanks, but that's how I currently do it. The question was if there's a way to get all the records from an object without calling passing their ids's and therefore avoid a call to the search method

Adunato
on 5/26/13, 1:39 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

2 follower(s)

Stats

Asked: 5/26/13, 9:53 AM
Seen: 5051 times
Last updated: 10/7/16, 4:01 AM