!2875 添加功能

Merge pull request !2875 from 李鹏宇/dev_zhou
This commit is contained in:
李鹏宇
2025-05-25 12:35:05 +00:00
committed by Gitee
4 changed files with 38 additions and 17 deletions
@@ -112,7 +112,7 @@
<field name="type">ir.actions.act_window</field>
<field name="res_model">soong.workflow.record</field>
<field name="view_mode">tree,kanban,search</field>
<field name="domain">[('users_ids', 'in', [uid])]</field>
<field name="domain">[('employee_ids.user_id', '=', uid)]</field>
<field name="search_view_id" ref="soong_workflow_record_search"/>
</record>
<record id="soong_workflow_hr_employee_action" model="ir.actions.act_window">
@@ -124,14 +124,14 @@ class SoongWorkflowCommentWizard(models.TransientModel):
next_is_automatic = workflow_id.node_ids.search([('name', '=', self.trans_link_id.name), ('workflow_id', '=', workflow_id.id)]).button_ids[0].is_automatic
employee_user_role_ids = employee_user_role_id = False
if link_users_id:
employee_user_role_ids = self.env['hr.employee'].search(['|', ('user_role_id', '=', link_users_id.id), ('user_role_ids', 'in', link_users_id.id), ('company_id', '=', self.env.user.company_id.id)]) # 自动匹配
employee_user_role_id = self.env['hr.employee'].search(['|', ('user_role_id', '=', link_users_id.id), ('user_role_ids', 'in', link_users_id.id),
employee_user_role_ids = self.env['hr.employee'].sudo().search(['|', ('user_role_id', '=', link_users_id.id), ('user_role_ids', 'in', link_users_id.id), ('company_id', '=', self.env.user.company_id.id)]) # 自动匹配
employee_user_role_id = self.env['hr.employee'].sudo().search(['|', ('user_role_id', '=', link_users_id.id), ('user_role_ids', 'in', link_users_id.id),
'|', ('department_id', '=', record_id.department_id.id), ('department_ids', 'in', record_id.department_id.id), ('company_id', '=', self.env.user.company_id.id)]) # 不自动匹配
elif link_users_group_ids:
# 不自动匹配
employee_user_role_ids = self.env['hr.employee'].search(['|', ('user_role_id', 'in', link_users_group_ids.user_role_ids.ids), ('user_role_ids', 'in', link_users_group_ids.user_role_ids.ids)])
employee_user_role_ids = self.env['hr.employee'].sudo().search(['|', ('user_role_id', 'in', link_users_group_ids.user_role_ids.ids), ('user_role_ids', 'in', link_users_group_ids.user_role_ids.ids)])
# 自动匹配
employee_user_role_id = self.env['hr.employee'].search([('id', 'in', employee_user_role_ids.ids),
employee_user_role_id = self.env['hr.employee'].sudo().search([('id', 'in', employee_user_role_ids.ids),
# ("user_role_ids", "in", employee_user_role_ids.id),
'|', ('department_id', '=', record_id.department_id.id),
('department_ids', 'in', record_id.department_id.id),
+26 -10
View File
@@ -376,24 +376,40 @@ class HolidaysRequestBatch(models.Model):
self.leave_ids.action_validate()
self.hour_leave_ids.action_validate()
@api.constrains('hour_leave_ids')
def _check_hour_leave_hours(self):
"""检查小时请假记录的小时数是否为0"""
number_hours = 0
@api.constrains('is_day', 'is_hour', 'leave_ids', 'hour_leave_ids')
def _check_leave_type_and_details(self):
"""检查请假类型和明细行是否符合要求"""
for record in self:
# 验证 is_day 和 is_hour 不能同时为空
if not record.is_day and not record.is_hour:
raise ValidationError(_("请选择按天请假或按小时请假!"))
# 验证 leave_ids 和 hour_leave_ids 不能同时为空
if not record.leave_ids and not record.hour_leave_ids:
raise ValidationError(_("请至少添加一条按天或按小时的请假记录!"))
# 验证按天请假时必须选择按天请假
if record.leave_ids and not record.is_day:
raise ValidationError(_("添加了按天请假记录,必须选择'按天请假'选项!"))
# 验证按小时请假时必须选择按小时请假
if record.hour_leave_ids and not record.is_hour:
raise ValidationError(_("添加了按小时请假记录,必须选择'按小时请假'选项!"))
# 原有的小时数验证逻辑(仅在按小时请假时有小时记录时执行)
if record.hour_leave_ids and not record.leave_ids:
number_hours = 0
for line in record.hour_leave_ids:
if line.request_date_from and line.request_hour_to:
# 使用正则表达式提取小时数
match = re.search(r'(\d+(?:\.\d+)?)', line.number_of_hours_text or '')
if match and float(match.group(1)) == 0:
raise ValidationError(_("请假小时数不能为0!"))
if record.company_id.name == '天河物管':
match = re.search(r'(\d+(?:\.\d+)?)', line.number_of_hours_text or '')
number_hours += float(match.group(1))
valid_hours = [2, 4, 6, 8]
if number_hours not in valid_hours:
raise ValidationError("休假时长必须为 2、4、6 或 8 小时才可以保存!")
if record.company_id.name == '天河物管':
match = re.search(r'(\d+(?:\.\d+)?)', line.number_of_hours_text or '')
if match:
number_hours += float(match.group(1))
# 天河物管的总小时数验证
if record.company_id.name == '天河物管' and number_hours:
valid_hours = [2, 4, 6, 8]
if number_hours not in valid_hours:
raise ValidationError(_("休假时长必须为 2、4、6 或 8 小时才可以保存!"))
@api.onchange('leave_ids', 'hour_leave_ids', 'employee_id')
def _onchange_leave_dates(self):
+7 -2
View File
@@ -49,8 +49,13 @@
<field name="number"/>
<field name="fee"/>
<field name="total"/>
<field name="start_date"/>
<field name="end_date"/>
<label for="start_date"/>
<div class="d-inline-flex w-100">
<field name="start_date" string="保期:" class="me-2"
style="max-width: 10rem !important;"/>至
<field name="end_date" string=" " class="ms-2"
style="max-width: 10rem !important;"/>
</div>
<field name="text"/>
<field name="documents_ids" widget="preview_many2many"/>
</group>