Merge pull request !3896 from 李鹏宇/dev
This commit is contained in:
李鹏宇
2025-07-16 10:01:32 +00:00
committed by Gitee
3 changed files with 100 additions and 46 deletions
+68 -5
View File
@@ -151,16 +151,43 @@ class HrLeave(models.Model):
@api.model
def create(self, vals):
allocation = super(HrLeave, self).create(vals)
if allocation.holiday_status_id.name == '年假' and allocation.state == 'validate':
employee = allocation.employee_id
days = allocation.number_of_days * 8
if allocation.state != 'validate':
return allocation # 只处理已审批的休假
employees = self._get_employees_from_holiday_type1(allocation)
# 根据假期类型执行不同逻辑
if allocation.holiday_status_id.name == '年假':
self._process_annual_leave(allocation, employees)
elif allocation.holiday_status_id.name == '补休':
self._process_compensatory_leave(allocation, employees)
return allocation
def _get_employees_from_holiday_type1(self, allocation):
"""根据holiday_type获取员工列表"""
if allocation.holiday_type == 'employee':
return self.env['hr.employee'].browse(allocation.employee_id.id)
elif allocation.holiday_type == 'company':
return self.env['hr.employee'].search([('company_id', '=', allocation.company_id.id)])
return self.env['hr.employee'] # 空记录集
def _process_annual_leave(self, allocation, employees):
"""处理年假逻辑"""
days = allocation.number_of_days * 8
for employee in employees:
# 更新员工年假余额
employee.write({
'user_year': employee.user_year + days
})
reports_id = self.env['yuthon.vacation.reports'].search([
('employee_id', '=', employee.id)
], limit=1)
# 创建假期明细记录
if not reports_id:
reports_id = self.env['yuthon.vacation.reports'].create({
'employee_id': employee.id,
})
self.env['vacation.leave.line'].create({
'vacation_id': reports_id.id,
'update_type': 'reduce',
@@ -169,7 +196,29 @@ class HrLeave(models.Model):
'text': '休假',
'allocation_type': 'vacation',
})
return allocation
def _process_compensatory_leave(self, allocation, employees):
"""处理补休逻辑"""
for employee in employees:
reports_id = self.env['yuthon.vacation.reports'].search([
('employee_id', '=', employee.id)
], limit=1)
if not reports_id:
reports_id = self.env['yuthon.vacation.reports'].create({
'employee_id': employee.id,
})
self.env['vacation.over.line'].create({
'vacation_id': reports_id.id,
'employee_id': employee.id,
'update_type': 'add',
'workday': allocation.number_of_days * 8,
'legal_day': 0,
'public_holidays': 0,
'meal_number': 0,
'update_date': fields.Date.today(),
'is_void': False,
'text': f'补休',
})
def unlink(self):
for record in self:
@@ -187,6 +236,20 @@ class HrLeave(models.Model):
employee.write({
'user_year': employee.user_year - days
})
elif record.employee_id and record.holiday_status_id.name == '补休':
employee = record.employee_id
days = record.number_of_hours_display
over_lines_to_delete = self.env['vacation.over.line'].search([
('employee_id', '=', employee.id),
('workday', '=', days),
('update_type', '=', 'reduce'),
('text', 'ilike', f'%{record.name}%'), # 通过名称模糊匹配
])
if over_lines_to_delete:
over_lines_to_delete.write({'is_void': True})
return super(HrLeave, self).unlink()
@api.depends('request_hour_from')
@@ -216,37 +216,37 @@ class VacationOverline(models.Model):
is_void = fields.Boolean(string='是否作废')
text = fields.Text(string='备注')
def _sync_to_employee(self, reverse=False):
"""将数据同步到关联员工
:param reverse: 是否反向操作(用于删除场景)
"""
employee = self.vacation_id.employee_id
employee.meal_number -= self.meal_number
# 根据操作类型确定计算方式
sign = -1 if reverse else 1
if self.update_type == 'add':
employee.write({
'normal_overtime_hours': employee.normal_overtime_hours + (self.workday * sign),
'holiday_overtime_hours': employee.holiday_overtime_hours + (self.legal_day * sign),
'weekend_overtime_hours': employee.weekend_overtime_hours + (self.public_holidays * sign)
})
elif self.update_type == 'reduce':
employee.write({
'normal_overtime_hours': employee.normal_overtime_hours - (self.workday * sign),
'holiday_overtime_hours': employee.holiday_overtime_hours - (self.legal_day * sign),
'weekend_overtime_hours': employee.weekend_overtime_hours - (self.public_holidays * sign)
})
@api.model
def create(self, vals):
record = super(VacationOverline, self).create(vals)
record._sync_to_employee()
return record
def unlink(self):
"""删除记录时同步扣减员工加班时长"""
self._sync_to_employee(reverse=True)
return super(VacationOverline, self).unlink()
# def _sync_to_employee(self, reverse=False):
# """将数据同步到关联员工
# :param reverse: 是否反向操作(用于删除场景)
# """
# employee = self.vacation_id.employee_id
# employee.meal_number -= self.meal_number
# # 根据操作类型确定计算方式
# sign = -1 if reverse else 1
# if self.update_type == 'add':
# employee.write({
# 'normal_overtime_hours': employee.normal_overtime_hours + (self.workday * sign),
# 'holiday_overtime_hours': employee.holiday_overtime_hours + (self.legal_day * sign),
# 'weekend_overtime_hours': employee.weekend_overtime_hours + (self.public_holidays * sign)
# })
# elif self.update_type == 'reduce':
# employee.write({
# 'normal_overtime_hours': employee.normal_overtime_hours - (self.workday * sign),
# 'holiday_overtime_hours': employee.holiday_overtime_hours - (self.legal_day * sign),
# 'weekend_overtime_hours': employee.weekend_overtime_hours - (self.public_holidays * sign)
# })
#
# @api.model
# def create(self, vals):
# record = super(VacationOverline, self).create(vals)
# record._sync_to_employee()
# return record
#
# def unlink(self):
# """删除记录时同步扣减员工加班时长"""
# self._sync_to_employee(reverse=True)
# return super(VacationOverline, self).unlink()
class VacationMealLine(models.Model):
_name = 'vacation.meal.line'
@@ -12,8 +12,6 @@ class ChoosePropertyWizard(models.Model):
self.lease_contract_id.lease_ids.unlink()
lease_name = []
lease_ids_to_add = []
electricity_list = []
water_list = []
fee_list = []
for record in self.property_ids:
lease_name.append(record.name)
@@ -29,17 +27,10 @@ class ChoosePropertyWizard(models.Model):
'proportional': standard_id.amount}])
else:
rec.is_mange = False
rec.electricity_fee_ids = [(5, 0, 0)]
rec.mange_fee_ids = [(5, 0, 0)]
rec.water_fee_ids = [(5, 0, 0)]
manage_id = record.manage_information_ids[0] if record.manage_information_ids else False
rec.admin_id = manage_id.admin_id.id
rec.admin_id = manage_id.admin_line_id.id
rec.company_id = manage_id.company_id.id
rec.precinct_id = manage_id.precinct_id.id
rec.electricity_fee_ids = electricity_list
rec.water_fee_ids = water_list
rec.mange_fee_ids = fee_list
self.lease_contract_id.lease_ids = lease_ids_to_add
self.lease_contract_id.write({'name': ','.join(lease_name),
'use_address': ','.join(lease_name),