gpt4 book ai didi

python - 我正在处理休假条件,我想在 odoo 中根据性别显示休假类型

转载 作者:太空宇宙 更新时间:2023-11-03 10:53:55 26 4
gpt4 key购买 nike

条件是如果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")

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

谢谢...

最佳答案

我得到的答案只是一个缩进错误

        res['domain']={'holiday_status_id':return_domain_list}
return res

代替

res['domain']={'holiday_status_id':return_domain_list}
return res

关于python - 我正在处理休假条件,我想在 odoo 中根据性别显示休假类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45073682/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com