Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
2998 มุมมอง

i need to make leave type 'holiday_status_id' field change dynamically based on : logged in user, request type and state 
this function work only with create allocate but in case edit it doesn't work

# Enable Employee To Request Allocate For Compensation Only
# Enable Officer group To Request Allocate For Compensation and Paid Only
@api.onchange('employee_id', 'type', 'state')
def change_leave_type(self):
for holiday_type in self:
print(holiday_type.state)
if holiday_type.type == 'add' and holiday_type.state in ['draft','confirm'] and holiday_type.env.uid == holiday_type.user_id.id and not holiday_type.env.user.has_group('hr_holidays.group_hr_holidays_user'):
allocate_type = holiday_type.env['hr.holidays.status'].search([('name', '=', 'Compensatory Days')]).id
return {'domain': {'holiday_status_id':[('id', '=', allocate_type)]}}
elif holiday_type.type == 'add' and holiday_type.env.user.has_group('hr_holidays.group_hr_holidays_user') and not holiday_type.env.user.has_group('hr_holidays.group_hr_holidays_manager'):
ids = []
allocation_types = holiday_type.env['hr.holidays.status'].search([])
for allocate in allocation_types:
if allocate.name != 'Unpaid':
ids.append(allocate.id)
return {'domain': {'holiday_status_id':[('id', '=', ids)]}}

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

You can follow this: https://youtu.be/XGqXEL2qQmE 

Hope it helps, Thanks

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ม.ค. 20
2920
0
ม.ค. 20
3124
1
ธ.ค. 19
4146
Hide fields in Filters And Group By แก้ไขแล้ว
3
มิ.ย. 23
15887
1
มี.ค. 22
13321