1

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.

1
  • Thing is, if you store it in an integer field, you will only have 1 count per invoice. It wont help you, what you have to do is to make a function for the report. Anyway, you dont need the second iteration, with the first one you are already in the line. What you have to do is to save the product in, for example, a dictionary, and if the key already exists add the amount to that dictionary. Still you cant save it as a field. Commented Apr 6, 2016 at 15:07

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.