跳至內容
選單
此問題已被標幟
4 回覆
36136 瀏覽次數

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
2218
0
9月 21
2898
0
12月 21
1878
1
12月 21
5898
0
7月 25
2