!2643 添加功能

Merge pull request !2643 from 李鹏宇/dev_zhou
This commit is contained in:
李鹏宇
2025-05-03 15:44:45 +00:00
committed by Gitee
2 changed files with 34 additions and 14 deletions
+33 -13
View File
@@ -167,25 +167,45 @@ class HrLeave(models.Model):
holiday.number_of_hours = hours
holiday.number_of_days = days
if holiday.holiday_status_id.type_of_work == "0":
calendar = self.env['resource.calendar'].sudo().search([("name", "=", "行政考勤工作日")], limit=1)
calendar_leaves = self.env['resource.calendar.leaves'].search([])
found = False
calendar_leaves = self.env['resource.calendar.leaves'].search([("calendar_id", "=", "行政考勤工作日")])
target_day = holiday.request_date_from
for leaves in calendar_leaves:
shift_days = leaves.shift_replacement_day.split(',') if leaves.shift_replacement_day else []
for day_str in shift_days:
day = datetime.strptime(day_str, '%m月%d日')
if day.month == target_day.month and day.day == target_day.day:
hours = float(holiday.request_hour_to) - float(holiday.request_hour_from) -2
holiday.number_of_hours = hours
found = True
break
if not found:
day, hours = holiday._get_duration(resource_calendar=calendar)
total_hours = (self.request_date_to - self.request_date_from).days
days = calendar.hours_per_day / 8 * total_hours + 1
holiday.number_of_hours = hours
holiday.number_of_days = days
hour = float(holiday.request_hour_to) - float(holiday.request_hour_from) -2
holiday.number_of_hours = hour
holidays_list = []
shift_days_list = []
for leaves in calendar_leaves:
if leaves.holidays:
holidays_list.extend(leaves.holidays.split(','))
if leaves.shift_replacement_day:
shift_days_list.extend(leaves.shift_replacement_day.split(','))
days = (self.request_date_to - self.request_date_from).days + 1
current_date = self.request_date_from
while current_date <= self.request_date_to:
current_date_str = current_date.strftime('%m月%d日')
current_date_str = self.remove_leading_zero(current_date_str)
is_weekend = current_date.weekday() in [5, 6]
if current_date_str in holidays_list:
days -= 1
elif current_date_str in shift_days_list:
if not is_weekend:
days += 1
elif is_weekend:
days -= 1
current_date += timedelta(days=1)
self.number_of_days = days
def remove_leading_zero(self, date_str):
month, day = date_str.split('月')
month = month.lstrip('0')
day = day.rstrip('日')
day = day.lstrip('0')
return f'{month}月{day}日'
def _compute_request_unit_hours(self):
if not self.env.context.get('no_change_request_unit_hours'):
+1 -1
View File
@@ -130,7 +130,7 @@
<group>
<field name="is_hour"/>
</group>
<group invisible="not is_hour">
<group invisible="not is_hour" col="2">
<group>
<field name="hour_leave_ids" invisible="not is_hour" string=" "
context="{