Skip to Content
Menu
This question has been flagged
4 Replies
35333 Views

Guys what i did wrong... im getting message = "TypeError: 'int' object is not iterable"


age = fields.Integer(string="Age", required=False, default="1")

group = fields.Char(string="Group", compute="_compute_group", store=True)

total = fields.Char(string="Total" )

totalage = fields.Integer(string="Totalage", compute="_calculate_total_age", store=True)

@api.one

@api.depends('age')

def _calculate_total_age(self):

currentage = 0

for number in self.age:

currentage = currentage + number.age

self.totalage = currentage

Avatar
Discard

What do you want yo compute? No sense a loop with integer field.

Best Answer

Try this, change for loop like this, for number in self: 

or try the below one

age = fields.Integer(string="Age", required=False, default="1")
group = fields.Char(string="Group", compute="_compute_group", store=True)
total = fields.Char(string="Total" )
totalage = fields.Integer(string="Totalage", compute="_calculate_total_age", store=True)

@api.one
@api.depends('age')
def _calculate_total_age(self):
currentage = 0
  currentage = currentage + self.age
self.totalage = currentage
Avatar
Discard
Best Answer

you defined age as an integer.

i dont understand why you used for number in self.age:  

This format ( for i in variable ) is used if variable is an array or string
Try these instead :
for number in range(self.age):

     //number will have values from 0 - self.age

or 

if self.age :

     // if you want to check there is value in field age

Avatar
Discard
Best Answer

@api.depends('age')
def _calculate_total_age(self):
if self.age:
self.totalage=self.age


Avatar
Discard
Related Posts Replies Views Activity
1
Oct 21
1689
0
Sep 21
2390
0
Dec 21
1387
1
Dec 21
4951
2
Mar 24
1162