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

one2many incoming shipments

By
Drew
on 10/28/13, 2:25 PM 1,091 views

I'm new to OpenERP, I have following:

shipment_obj = self.pool.get('stock.picking.in').browse(cr, uid, context.get('active_id'))

this returns incoming shipment_obj, I can access fields/properties, but when I try to access one2many field "move_lines", and iterate over it, it returns None type object.

  for product in shipment_obj.move_lines:
     etc...

Here is original fields from OpenERP stock.py:

'move_lines': fields.one2many('stock.move', 'picking_id', 'Internal Moves', states={'done': [('readonly', True)], 'cancel': [('readonly', True)]}),
'product_id': fields.related('move_lines', 'product_id', type='many2one', relation='product.product', string='Product'),

I want to be able to get the products for this incoming shipment.

What is correct syntax to use for iterating over?

Thanks for feedback!

0
Abhishek H Menon
On 10/30/13, 1:53 AM

instead of using

for product in shipment_obj.move_lines:
     etc...

use,

  for product in shipment_obj[0].move_lines:
         etc...

thanks for the response but none of the answers here work and to be honest they don't make any sense because browse returns one object if a single ID is passed as opposed to a list of IDs. ie: idea = self.browse(cr, uid, 42) would return the idea object, idea = self.browse(cr, uid, [42, 43, 44]) would return list of objects. browse Returns: object or list of objects requested. I figured out the problem but the answer is absolutely crazy to me at this point in time, what I posted works but requires one conditional element which as someone who is not new to programming escapes me.

Drew
on 10/30/13, 10:32 PM
0
Ashif Abdulrahman
On 10/29/13, 10:08 AM

you better use following,because in shipment_obj you will get a list

for product.move_lines in shipment_obj: etc..

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

0 follower(s)

Stats

Asked: 10/28/13, 2:25 PM
Seen: 1091 times
Last updated: 3/16/15, 8:10 AM