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

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
アバター
破棄
最善の回答

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
アバター
破棄
最善の回答

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).

アバター
破棄
関連投稿 返信 ビュー 活動
2
4月 24
1651
1
1月 22
2999
2
8月 19
13370
0
4月 19
2452
2
2月 19
3201