beriliox
beriliox

Reputation: 267

Odoo Error: TypeError: 'int' object is not iterable

I'm creating a function in the invoice module. What you should do is to have this function products line are equal invoice and return the amount per product. This is better explained in the following image:

enter image description here

For example, the product "Aceite Hidraulico" appears 3 times on the invoice. Then the function should return a 3 for this product.

Well, this is the function I have in my account.invoice.py:

total_quantity = fields.Integer(compute='count_invoice_invoice', string = 'Cantidad Productos', readonly = True, store=True)

@api.one
@api.depends('invoice_line_ids.product_id')
def count_invoice_invoice(self):
    res = {}
    counter = 0
    for po in self.invoice_line_ids:
        for product in po.product_id.id:
            counter += 1
            res [self.total_quantity] = counter
    return res

For the function to differentiate between one product and another, I use the id field product.product model. But when I try to create the invoice, Odoo shows me a message int type fields can not be iterables. This is a problem because the id field to differentiate products is an integer.

What should I do?

This is the message showing Odoo:

for product in po.product_id.id:

TypeError: int object is not iterable

Thank you very much for your help and time spent. I appreciate any suggestions or advice to get what you want to do.

Upvotes: 1

Views: 3262

Answers (2)

Hari Prasad
Hari Prasad

Reputation: 50

Seems you are trying to loop on an integer. If you want to increment the counter try to loop it on the object. For Ex:

for po in self.invoice_line_ids:
    for product in po.product_id:
        counter += 1
        res [self.total_quantity] = counter
return res

By this way you can loop through the object and if you need to get each product id you can get it by product.id inside the loop.

Upvotes: 1

Mahendra Barad
Mahendra Barad

Reputation: 11

Actually you have Problem with for loop. you are trying loop on integer. po.product_id.id is integer so I think there is no need to use that for loop even thought if you want to use the for loop use like this: for product in [po.product_id.id]:

Thanks

Upvotes: 0

Related Questions