!5956 添加功能

Merge pull request !5956 from 李鹏宇/dev_zhou
This commit is contained in:
李鹏宇
2025-10-25 07:48:11 +00:00
committed by Gitee
4 changed files with 53 additions and 15 deletions
+1 -1
View File
@@ -69,7 +69,7 @@ class HrAttendance(models.Model):
"""
att_ids = self.sudo().env['hr.attendance']
# 补充假期橙色逻辑,班次逻辑
for emp in self.sudo().env['hr.employee'].search([]):
for emp in self.sudo().env['hr.employee'].search([('user_state', '!=', 'withdraw')]):
test1 = att_ids.search([('current_data', '=', fields.Date.today()), ('employee_id', '=', emp.id)])
resource_user_ids = emp.resource_calendar_id.resource_user_ids.ids
is_resource_user = True if emp.id in resource_user_ids else False
@@ -178,10 +178,7 @@ class YuthonVacationReports(models.Model):
if rec.employee_id and rec.vacation_date:
year = rec.vacation_date.year
month = rec.vacation_date.month
days_in_month = calendar.monthrange(year, month)[1]
month_start = date(year, month, 1)
month_end = date(year, month, days_in_month)
leave_days, holiday_days = rec._create_leave_record(rec.employee_id, month_start, month_end)
entry_date = rec.employee_id.entry_date
if not entry_date or month_start > entry_date:
start_day = 1
@@ -232,13 +229,17 @@ class YuthonVacationReports(models.Model):
actual_attendance = actual_attendance - total_leave_days - is_abnormal
employee = rec.employee_id
print(employee.name)
contract = employee.contract_id
is_outside = employee.user_role_id.name == '外派'
month_start = date(year, month, 1)
month_end = date(year, month, calendar.monthrange(year, month)[1])
start_date = max(rec.employee_id.contract_id.date_start, month_start)
if rec.employee_id.contract_id.date_end:
end_date = min(rec.employee_id.contract_id.date_end, month_end)
else:
end_date = month_end
# 计算start_date:外派且无合同时用month_start,否则取合同开始日与month_start的最大值
start_date = month_start if (is_outside and not contract) else max(contract.date_start, month_start)
# 计算end_date:外派且无合同时用month_end;有合同且有结束日则取最小值;其他情况用month_end
end_date = month_end if (is_outside and not contract) else (min(contract.date_end, month_end) if contract.date_end else month_end)
leave_days, statutory_days = rec._create_leave_record(rec.employee_id, start_date, end_date)
probation_contract = self.env['hr.contract'].search([
('employee_id', '=', rec.employee_id.id),
@@ -82,6 +82,7 @@ class YuthonWillTask(models.Model):
document_ids = fields.Many2many('ir.attachment', string="附件")
address = fields.Char(string='地点')
start_date = fields.Date(string='开始日期', default=fields.Date.today)
task_time = fields.Char(string='任务时间', compute='_compute_task_time')
is_this_company = fields.Boolean(string='本公司', default=True)
task_state = fields.Selection([('will', '待办'), ('done', '已办'), ('cancel', '取消')], default='will', string='状态', store=True)
@@ -105,6 +106,44 @@ class YuthonWillTask(models.Model):
store=True, default=lambda self: [(6, 0, [self.env.user.id])]
)
@api.depends('start_date', 'request_hour_from', 'request_hour_to')
def _compute_task_time(self):
for record in self:
date_str = ""
if record.start_date:
date_str = record.start_date.strftime("%Y/%m/%d")
hour_mapping = {
'0': '0:00', '0.5': '0:30',
'1': '01:00', '1.5': '01:30',
'2': '02:00', '2.5': '02:30',
'3': '03:00', '3.5': '03:30',
'4': '04:00', '4.5': '04:30',
'5': '05:00', '5.5': '05:30',
'6': '06:00', '6.5': '06:30',
'7': '07:00', '7.5': '07:30',
'8': '08:00', '8.5': '08:30',
'9': '09:00', '9.5': '09:30',
'10': '10:00', '10.5': '10:30',
'11': '11:00', '11.5': '11:30',
'12': '12:00', '12.5': '12:30',
'13': '13:00', '13.5': '13:30',
'14': '14:00', '14.5': '14:30',
'15': '15:00', '15.5': '15:30',
'16': '16:00', '16.5': '16:30',
'17': '17:00', '17.5': '17:30',
'18': '18:00', '18.5': '18:30',
'19': '19:00', '19.5': '19:30',
'20': '20:00', '20.5': '20:30',
'21': '21:00', '21.5': '21:30',
'22': '22:00', '22.5': '22:30',
'23': '23:00', '23.5': '23:30'
}
from_time = hour_mapping.get(record.request_hour_from, "")
to_time = hour_mapping.get(record.request_hour_to, "")
if date_str and from_time and to_time:
record.task_time = f"{date_str} ({from_time}--{to_time})"
else:
record.task_time = ""
@api.onchange('employee_ids', 'user_id')
def _onchange_employee_ids(self):
@@ -10,9 +10,8 @@
decoration-info="priority == 'urgent'"
decoration-primary="priority == 'general'"
decoration-success="priority == 'important'">
<field name='start_date' required="1"/>
<field name="request_hour_from" string=" "/>
<field name="request_hour_to" string=" "/>
<field name='start_date' column_invisible="1"/>
<field name='task_time' />
<field name='name' required="1"/>
<field name="user_id" optional="hide"/>
<field name='employee_ids' widget="many2many_tags" required="1" options="{'no_create': True}"/>
@@ -122,9 +121,8 @@
decoration-info="priority == 'urgent'"
decoration-primary="priority == 'general'"
decoration-success="priority == 'important'" create="false" edit="false" js_class="custom_task_tree_button">
<field name='start_date' required="1"/>
<field name="request_hour_from" string=" "/>
<field name="request_hour_to" string=" "/>
<field name='start_date' column_invisible="1"/>
<field name='task_time' />
<field name='name' required="1"/>
<field name="user_id" optional="hide"/>
<field name='employee_ids' widget="many2many_tags" required="1"/>