The condition is if the employee in hr.employee is female then display the leave type which can be allocated only to female employee and same as for the male employee
Gender specific leave will be saved from hr_leave_rules.leave_rules code provided as follows:
class HRLeaveRules(models.Model):
_name = 'hr_leave_rules.leave_rules'
half_day_allowed = fields.Selection([
('yes',"Yes"),
('no',"No")],
string="Half Day Allowed", required=True)
gender_specific = fields.Selection([
('all' ,"All"),
('male',"Male"),
('female',"Female")],
string="Gender Specific", required=True)
leaves_allowed_on_prorata_basis = fields.Selection([
('yes',"Yes"),
('no',"No")],
string="Leaves allowed on pro rata basis", required=True)
leave_encashment = fields.Boolean(string="Leave Encashment",
required=True)
leave_encashment_for_maximum = fields.Integer(
string = "Leave Encashment for maximum", required=True)
can_emp_club_leave = fields.Selection([
('yes',"Yes"),
('no',"No")],
string="Can Employees Club this leave with any other leave",
required=True)
past_dated_leave_allowed = fields.Selection([
('yes',"Yes"),
('no',"No")],
string="Past dated leave application allowed", required=True)
override_paid_leave_to_unpaid = fields.Selection([
('yes',"Yes"),
('no',"No")],
string="Can managers override paid leaves to unpaid", required=True)
carry_frwrdng_leaves = fields.Boolean(string="Carry forwarding of leaves",
required=True)
maximum_accumulation_in_year = fields.Integer(string = "Maximum Accumulation in year",
required=True)
leave_encash_rest_leaves = fields.Selection([
('yes',"Yes"),
('no',"No")],
string="Leave Encashment for Rest Leaves", required=True)
employee_id = fields.Many2one('hr.employee', string="Employee")
holiday_status_id = fields.Many2one("hr.holidays.status",
string="Leave Type", required=True)
department_id = fields.Many2one('hr.department',
related='employee_id.department_id', string='Department')
count_intervening_leaves = fields.Boolean(
string="Count intervening holidays/weekly offs as leaves",
required=True)
count_intervening_leaves_back_date = fields.Boolean(
string="Count intervening holidays/weekly offs as leaves if applying for back date",
required=True)
leaves_probation_period = fields.Boolean(string="Leaves allowed in probation period",
required=True)
max_con_leaves_month = fields.Boolean(string="Maximum consecutive leaves per month",
required=True)
leave_encashment_cycle = fields.Selection([
('annually',"Annually"),
('super_annuation',"Super Annuation / Relieving")],
string="Leave Encashment Cycle", required=True)
description = fields.Text(string="Description")
The code in which i'm not finding any error is :-
@api.onchange('employee_id')
def _gender_specification_check(self):
listed = []
return_domain_list = []
res={}
if self.employee_id.gender == 'male' or self.employee_id.gender == 'female':
if self.employee_id.gender == 'male':
s='male'
else :
s='female'
current = self.env['hr_leave_rules.leave_rules'].search([('gender_specific','=',s)])
for item in current:
listed.append(item.holiday_status_id.id)
for item in range(len(listed)-1):
return_domain_list.append('&')
for item in listed:
return_domain_list.append(('id','!=',str(item)))
else:
current = self.env['hr_leave_rules.leave_rules'].search([('gender_specific','=',self.employee_id.gender)])
for item in current:
listed.append(item.holiday_status_id.id)
for item in range(len(listed)-1):
return_domain_list.append('|')
for item in listed:
return_domain_list.append(('id','=',str(item)))
res['domain']={'holiday_status_id':return_domain_list}
return res
Thanks...