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

weird issue accessing list of objects

By
Drew
on 11/3/13, 8:17 PM 600 views

If I do:

if shipment_obj.move_lines:
    for line in shipment_obj.move_lines: 
        #line.name, line.id etc..

this works no problem, but I shouldn't need the if statement.

If I just do:

    for line in shipment_obj.move_lines: 
       #line.name, line.id etc..

this throws: "TypeError: 'NoneType' object is not iterable"

Just want to know, why this could be?

here for reference:

shipment_obj = self.pool.get('stock.picking.in').browse(cr, uid, context.get('active_id')) #gives correct shipment obj

trying to access:

 'move_lines': fields.one2many('stock.move', 'picking_id', 'Internal Moves', states={'done': [('readonly', True)], 'cancel': [('readonly', True)]})

Does it really work when using "if", or does it just not throw errors?

Antanas
on 11/4/13, 10:25 AM

it just throws errors when I don't use the if, its absolutely crazy I know.

Drew
on 11/4/13, 10:33 AM

yes when I use the if it works fine

Drew
on 11/4/13, 10:34 AM

found the problem. sorry, it is the way I thought the method was called that didn't need to check context and active_id since there would always be a context and active_id, I was wrong.

Drew
on 11/4/13, 12:26 PM
1
Drew
On 11/4/13, 12:29 PM

found the problem, context needs to be checked as well as active_id:

 if context is not None and context.get('active_id'):

...it is the way I thought the method was called that didn't need to check context and active_id since there would always be a context and active_id, I was wrong.

The devil was in the details, as usual...

Antanas
on 11/4/13, 12:30 PM

thanks for your help.

Drew
on 11/4/13, 12:44 PM
0
Antanas
On 11/4/13, 2:36 AM

If there is no move_lines, it is False, not None.

Try instead:

if shipment_obj.move_lines:
    for line in shipment_obj.move_lines: 
        #line.name, line.id 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: 11/3/13, 8:17 PM
Seen: 600 times
Last updated: 3/16/15, 8:10 AM