Jaymezon
Jaymezon

Reputation: 39

python TypeError: 'crm.lead.product' object cannot be interpreted as an integer, Odoo 14

'lead_product_ids' consist of a list of products and I am trying to multiply qty*price unit of each product to get the total and then add all totals.

error: TypeError: 'crm.lead.product' object cannot be interpreted as an integer

Code

 @api.depends('lead_product_ids.qty', 'lead_product_ids.price_unit', 'lead_product_ids')
    def _compute_total_price(self):
        for rec in self:
            for i in rec.lead_product_ids:
                for all in range(i):
                    total = (all.qty * all.price_unit)
                    rec.total_qty_price_unit = sum(total) or 0

Upvotes: 1

Views: 85

Answers (1)

holydragon
holydragon

Reputation: 6728

It looks like

for i in rec.lead_product_ids:

is assigning i as a product for each of the products in lead_product_ids.

So, when you do

for all in range(i):

It will try to do range() of i but range() expects an integer input -- not a product object, hence the error

TypeError: 'crm.lead.product' object cannot be interpreted as an integer

To solve this, you should use i instead.

@api.depends('lead_product_ids.qty', 'lead_product_ids.price_unit', 'lead_product_ids')
def _compute_total_price(self):
    for rec in self:
        for i in rec.lead_product_ids:
            total = (i.qty * i.price_unit)
            rec.total_qty_price_unit += total

Upvotes: 1

Related Questions