Erlan Efarda
Erlan Efarda

Reputation: 11

Openerp NotImplementedError: Iteration is not allowed on browse_record(stock.move, 159275)

I'm browsing for records, then I would like to perform specific code if browsing return results.

Here is my code :

 def create_update_date(self, cr, uid, ids, context=None):
        _log.info ('this is method to create a MO')
        _log.info (context)
        picking_obj = self.pool.get('stock.picking')
        move_obj = self.pool.get('stock.move')
        for stock in self.browse(cr, uid, ids, context=None):
            for  wiz in picking_obj.browse(cr, uid, stock.stock_id.id, context=None):
                date_pick = stock.date
                for wizs in wiz.move_lines:
                    move_obj.write(cr,uid,wizs,{'date_expected':date_pick})

But it does not work, when evaluating the if condition, an exception is raised :

NotImplementedError: Iteration is not allowed on browse_record(stock.move, 159275)

Upvotes: 1

Views: 1400

Answers (1)

Daniel Reis
Daniel Reis

Reputation: 13352

To solve, add this before your for loop:

if not isinstance(ids, list):
    ids = [ids]

The catch is that ids can be wither a list of ids or a numeric id.

In the latter case, browse returns a single record, non iterable, instead of an iterable collection of records. The solution is to make sure ids is a list.

Another possible cause for the problem is the last write() command: it the wizs is a Record, and the write operation expects an ID. You may try replacing it with:

move_obj.write(cr, uid, wizs.id, {'date_expected':date_pick})

Upvotes: 2

Related Questions