Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
6 ตอบกลับ
42196 มุมมอง

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?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

คำตอบที่ดีที่สุด

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.

คำตอบที่ดีที่สุด

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
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

Related Posts ตอบกลับ มุมมอง กิจกรรม
Index output of browse method แก้ไขแล้ว
1
ส.ค. 22
2861
1
มี.ค. 15
4675
2
ส.ค. 23
2088
2
ธ.ค. 15
4690
2
ต.ค. 15
9076