Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
2690 Visualizzazioni

Hello forks,

Could someone help me correct this onchange code. I have a predefined values with different datatype. My code works fine if result value and predefined value are float datatype. But when inputted value is outside float i get an error.

Expected result values are float, integer, char, text.

How can i make it to work? Below is my onchange code

@api.onchange('normal_range', 'result')
def onchange_result(self):
    if self.normal_range:
        no1,no2 = self.normal_range.split('-')
        if self.result:
            if float(self.result) >= float(no1) and float(self.result) <= float(no2):
                self.remark = 'Normal'
            elif float(self.result) <= float(no1):
                self.remark = 'Below'
            elif float(self.result) >= float(no2):
                self.remark = 'Above'


Avatar
Abbandona

please share the error here and try doing debuging and urself u can find the answer,

and if your inputs are in digits python have no trouble making it to float

Risposta migliore

Try to use is instance function of python. which help you to check data type.

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
2
ott 23
6446
2
nov 22
6837
0
set 21
2935
4
ago 20
7752
2
mar 20
11633