Reputation: 1468
I'm browsing for records, then I would like to perform specific code if browsing return results.
Here is my code :
sub = self.pool.get('subscription.subscription').search(cr,uid,[('partner_id','=',partner.id),('active','=',True)])
if sub:
mtp.send_mail(cr, uid, level.email_template_id.id, partner.id, context=ctx)
But it does not work, when evaluating the if
condition, an exception is raised :
NotImplementedError: Iteration is not allowed on browse_record(res.partner, 15918)
I don't understand, because i'm not iterating over the result by checking if a result exist, neither calling the __iter__
method.
Thank you for your help
Cheers
Upvotes: 0
Views: 807
Reputation: 11143
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.
Add this after method definition.
if not isinstance(ids, list):
ids = [ids]
Upvotes: 0
Reputation: 916
In general cases the problem is that you are invoking browse method with only one ID, not a list of IDs, so the return value is only one record, not a list of records, so is not iterable.
Upvotes: 1