Ir al contenido
Menú
Se marcó esta pregunta
4 Respuestas
35565 Vistas

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
Descartar

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

Mejor respuesta

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
Descartar
Mejor respuesta

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
Descartar
Mejor respuesta

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


Avatar
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
1
oct 21
1837
0
sept 21
2523
0
dic 21
1489
1
dic 21
5155
2
mar 24
1332