添加功能

This commit is contained in:
李鹏宇
2026-07-16 10:44:45 +08:00
parent 45df21922a
commit 6685056cee
5 changed files with 91 additions and 24 deletions
@@ -18,6 +18,28 @@ class YuthonEmergencyContactLine(models.Model):
home_address = fields.Char(string="家庭住址")
documents_ids = fields.Many2many('ir.attachment', string="附件")
@api.model
def create(self, vals):
record = super().create(vals)
if record.employee_id:
record.employee_id.update_parental_leave()
return record
def write(self, vals):
res = super().write(vals)
for record in self:
if record.employee_id:
record.employee_id.update_parental_leave()
return res
def unlink(self):
employees = self.mapped('employee_id')
res = super().unlink()
for employee in employees:
if employee:
employee.update_parental_leave()
return res
class YuthonWorkExperienceLine(models.Model):
_name = 'yuthon.work.experience.line'
+26 -21
View File
@@ -1156,11 +1156,19 @@ class YuthonHrEmployee(models.Model):
def update_parental_leave(self):
today = datetime.now().date()
active_contracts = self.env['hr.contract'].search([
('state', '=', 'open'),
('contract_type_id.name', 'ilike', '正式合同'),
('employee_id', '!=', False)
])
# 如果 self 有具体员工(个人调用),只查该员工的合同;否则(定时任务)查全部
if self:
active_contracts = self.env['hr.contract'].search([
('state', '=', 'open'),
('contract_type_id.name', 'ilike', '正式合同'),
('employee_id', 'in', self.ids)
])
else:
active_contracts = self.env['hr.contract'].search([
('state', '=', 'open'),
('contract_type_id.name', 'ilike', '正式合同'),
('employee_id', '!=', False)
])
allocate_config = self.env['yuthon.parenting.allocate'].search([], limit=1)
valid_limit = allocate_config.valid_limit # 截至年龄(如3)
cycle_years = allocate_config.cycle_years # 周期年数(如1)
@@ -1219,10 +1227,8 @@ class YuthonHrEmployee(models.Model):
continue
holiday_status_id = self.env['hr.leave.type'].search([('name', '=', '育儿假')], limit=1)
# 更新报表
parenting_line_ids = []
# 6. 检查是否已存在相同分配记录,避免重复
# 检查是否已存在相同分配记录,避免重复
existing_allocation = self.env['hr.leave.allocation'].search([
('employee_id', '=', employee.id),
('name', '=', '育儿假分配'),
@@ -1230,22 +1236,30 @@ class YuthonHrEmployee(models.Model):
('date_from', '=', date_from),
('date_to', '=', date_to),
], limit=1)
if existing_allocation:
continue
if not existing_allocation:
self.env['hr.leave.allocation'].create({
'name': '育儿假分配',
'allocation_type': 'regular',
'employee_id': employee.id,
'date_from': date_from,
'date_to': date_to,
'holiday_status_id': holiday_status_id.id,
'number_of_days': total_days,
})
reports_id = self.env['yuthon.vacation.reports'].search([
('employee_id', '=', employee.id),
('vacation_date', '=', fields.Date.today().replace(day=1))
], limit=1) #
if reports_id:
reports_id.parenting_line_ids.search([
existing_report_line = reports_id.parenting_line_ids.search([
('vacation_id', '=', reports_id.id),
('employee_id', '=', employee.id),
('update_date', '=', date_from),
('end_date', '=', date_to),
('text','=', '育儿假分配')
], limit=1)
if not parenting_line_ids:
if not existing_report_line:
reports_id.parenting_line_ids.sudo().create({
'vacation_id': reports_id.id,
'employee_id': employee.id,
@@ -1255,15 +1269,6 @@ class YuthonHrEmployee(models.Model):
'text': '育儿假分配'
})
self.env['hr.leave.allocation'].create({
'name': '育儿假分配',
'allocation_type': 'regular',
'employee_id': employee.id,
'date_from': date_from,
'date_to': date_to,
'holiday_status_id':holiday_status_id.id,
'number_of_days': total_days,
})
def regularization_task(self):
today = fields.Date.today()