条件是 hr.employee 中的员工是女性,然后显示只能分配给女性员工的休假类型,与男性员工相同
将保存性别特定的离开 的 hr_leave_rules.leave_rules 代码如下:
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")
我没有发现任何错误的代码是: -
@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
感谢...
答案 0 :(得分:3)
我的答案只有一个缩进错误
res['domain']={'holiday_status_id':return_domain_list}
return res
而不是
res['domain']={'holiday_status_id':return_domain_list}
return res