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

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
Abbandona
Risposta migliore

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
Abbandona
Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
2
apr 24
1636
1
gen 22
2972
2
ago 19
13343
0
apr 19
2436
2
feb 19
3184