Skip to Content
Menu
This question has been flagged
2 Replies
2339 Views

Hello, 

Someone can explain me what exactly do this code?

What means the "and True or False" at the end?

    def _compute_is_employee(self):       
 for rec in self:           
 rec.is_employee = rec.employee_id and True or False
Avatar
Discard
Best Answer

Three cases. this expression returns True if employee_id has integer greater than 0 else False 

employee_id = 105
is_employee = employee_id and True or False
print(is_employee) -> True
employee_id = 0
is_employee = employee_id and True or False
print(is_employee) -> False
employee_id = ''
is_employee = employee_id and True or False
print(is_employee) -> False
Avatar
Discard
Best Answer

Hello Michele, 

rec.is_employee = rec.employee_id and True or False

This python code will work like bellow

If rec has employee_id means is_employee boolean field will get checked(True) otherwise unchecked(False).

Avatar
Discard
Related Posts Replies Views Activity
2
Apr 24
463
1
Jan 22
2186
2
Aug 19
10005
0
Apr 19
1777
2
Feb 19
2321