Skip to Content
Menu
This question has been flagged
1 Reply
2242 Views
How can i display wrong input message to users if wrong value is entered in a field?

My code below
@api.onchange('normal_range', 'result', 'check_value')
    def onchange_result(self):
        if self.check_value == '<' and self.normal_range:
            no1,no2 = self.normal_range.split('<')
            if self.result:
                if int(self.result) >= int(no1) and int(self.result) <= int(no2):
                    self.remark = 'Average'
                elif int(self.result) <= int(no1):
                    self.remark = 'Below Average'
                elif int(self.result) >= int(no2):
                    self.remark = 'Above Average'
Error shown below:
File "/home/dev/Desktop/odoo-10.0/customs_mark/mark_result.py", line 418, in onchange_result if float(self.result) >= float(no1) and float(self.result) <= float(no2):
ValueError: could not convert string to float: AB
Avatar
Discard
Best Answer

Hello there, 

You are getting this issue is because some time result or no1, no2 may contains the string value. 

Kindly update below mentioned code

@api.onchange('normal_range', 'result', 'check_value')

    def onchange_result(self):

        if self.check_value == '<' and self.normal_range:

            no1,no2 = self.normal_range.split('<')

            result = self.result

            if result and result.isdigit() and no1.isdigit() and no2.isdigit():

                if int(self.result) >= int(no1) and int(self.result) <= int(no2):

                    self.remark = 'Average'

                elif int(self.result) <= int(no1):

                    self.remark = 'Below Average'

                elif int(self.result) >= int(no2):

                    self.remark = 'Above Average'

Thanks

Anisha Bahukhandi

Technical Content Writer

Avatar
Discard