Skip to Content
Menu
This question has been flagged
1 Reply
1955 Views

#####

My objective is to get a predefined remark base on the inputted Result value after checking Expected Result value.

For instance: 

if Expected Result is 20-30 and if any value between 20 to 30 is inputted as result value then remark will be Normal,

else if result value <= expected result then remark will be Low, and if result value >= expected result then remark will be High.

Second Condition :

If Expected Result is Yellow and Inputted Result Value is Yellow then remark will be Good else Poor if any other color

Third Condition:

If Expected Result is >50 and Inputted Result Value is 51 and above the remark will be Okay else Not Okay


class ResultGrade(models.Model):
_name = 'result.grade'
_description = 'Result grading'

name = fields.Char(string='Title', size=128, required=True)
result = fields.Text(string='Result')
expected_result = fields.Text(string='Expected Result')
sequence = fields.Integer(string='Sequence')
remark = fields.Char(string='Remark')

_order="sequence"

@api.onchange('expected_result', 'result')
def onchange_result(self):
if self.expected_result:
col1,col2 = self.expected_result.split('-')
if self.result:
if self.result >= col1 and self.result <= col2:
self.remark = 'Normal'
elif self.result <= col1:
self.remark = 'Low'
elif self.result >= col2:
self.remark = 'High'
elif self.result == col1:
self.remark = 'Good'
elif self.result != col1:
self.remark = 'Poor'
elif self.result == col1:
self.remark = 'Good'
elif self.result != col2:
self.remark = 'Poor'

My challenge is to get remark for Second and Third condition. How can i make it work please.


Avatar
Discard
Best Answer

Hello, still learning to post appropriately in forums...but here goes...

replace the below line:

result = fields.Text(string='Result')

with:

result = fields.Integer(string='Result')

Also type cast col1 and col2 to integer ( by adding the below lines ) just below --> col1,col2 = self.expected_result.split('-')

col1=int(col1)

col2=int(col2)

you can of course use float or integer type fields for type casting and for creating the result field above

Please refer the below link to know what went wrong in comparing string instead of integers and why the result came out differently

\https://www.journaldev.com/23511/python-string-comparison



Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
18017
1
Sep 23
1200
3
May 23
4088
7
Apr 23
47087
1
Dec 22
6432