コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
2687 ビュー

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'


アバター
破棄

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

最善の回答

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

アバター
破棄
関連投稿 返信 ビュー 活動
2
10月 23
6442
2
11月 22
6832
0
9月 21
2933
4
8月 20
7752
2
3月 20
11624