跳至内容
菜单
此问题已终结
4 回复
36113 查看

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

形象
丢弃

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

最佳答案

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
形象
丢弃
最佳答案

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

形象
丢弃
最佳答案

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


形象
丢弃
相关帖文 回复 查看 活动
1
10月 21
2210
0
9月 21
2894
0
12月 21
1866
1
12月 21
5884
0
7月 25
2