Weird behavior using pow() on a float function field

Hi everyone,
I am having a weird behavior on a float function field.

I define the following fields

weight = fields.Float('Weight', digits=(3,2),help='Weight in kilos')    
height = fields.Float('Height', digits=(3,1), help='Height in centimeters')    
bmi = fields.Function(
    fields.Float('BMI', digits=(2,2),help='Body mass index'), 'get_bmi')

def get_bmi(self, name):
    bmi = 0
    if self.height:
        bmi =(self.weight / pow((self.height/100),2))
    return bmi

Each time I want to change the view or close the tab tryton ask me to save the record even if it is already saved.

When I took off the pow function, for example, making bmi = self.weight/self.height, the problem is gone.

I am using tryton 5.0.

I don’t know if it is a bug or maybe I corrupted somthing on the db
Regards.
Francisco

Hi Francisco,

I think that the problem is that in some case you have to be returning a number that have more digits that the ones you defined for the field (2,2).

Thank you very much OscarQ. Your answer helps me to solve this problem

On the getter, it has to return a rounded floating number using the round function

def get_bmi(self, name):
    bmi = 0
    if self.height:
        bmi =(self.weight / pow((self.height/100),2))
        bmi = round(bmi,3)
    return bmi

This is the solution

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.