添加功能
This commit is contained in:
@@ -796,11 +796,11 @@ class HrAttendance(models.Model):
|
||||
'is_approval': True,
|
||||
})
|
||||
|
||||
class card_remind_form(models.Model):
|
||||
_name = 'card.remind.form'
|
||||
_description = '测试表单'
|
||||
class card_remind_form(models.Model):
|
||||
_name = 'card.remind.form'
|
||||
_description = '测试表单'
|
||||
|
||||
name = fields.Char(string='姓名')
|
||||
start_time = fields.Datetime(string='时间')
|
||||
shift = fields.Char(string='班次')
|
||||
department = fields.Char(string='部门')
|
||||
name = fields.Char(string='姓名')
|
||||
start_time = fields.Datetime(string='时间')
|
||||
shift = fields.Char(string='班次')
|
||||
department = fields.Char(string='部门')
|
||||
|
||||
@@ -76,6 +76,18 @@ class PlanningSlotTemplate(models.Model):
|
||||
}
|
||||
return action
|
||||
|
||||
def template_timing_details(self):
|
||||
name_pattern = f'%{self.department_id.name}%{self.planning_name}%打卡提醒%'
|
||||
domain = [('name', 'ilike', name_pattern)]
|
||||
action = {
|
||||
'name': '班次打卡详情',
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'ir.cron',
|
||||
'view_mode': 'tree',
|
||||
'domain': domain,
|
||||
}
|
||||
return action
|
||||
|
||||
# @api.depends("planning_name")
|
||||
# def _compute_display_name(self):
|
||||
# super()._compute_display_name()
|
||||
|
||||
@@ -11,9 +11,19 @@
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
<record id="view_tree_card_search" model="ir.ui.view">
|
||||
<field name="name">card.remind.search</field>
|
||||
<field name="model">card.remind.form</field>
|
||||
<field name="arch" type="xml">
|
||||
<search>
|
||||
<field name="name"/>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
<record id="view_action_card_remind" model="ir.actions.act_window">
|
||||
<field name="name">考勤提醒表单</field>
|
||||
<field name="res_model">card.remind.form</field>
|
||||
<field name="view_mode">tree</field>
|
||||
<field name="context">{'group_by': ['name', 'department']}</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -12,6 +12,7 @@
|
||||
<field name="end_time2" widget="float_time"/>
|
||||
<field name="day2"/>
|
||||
<button name="template_details" string="详情" type="object" class="btn btn-primary"/>
|
||||
<button name="template_timing_details" string="定时" type="object" class="btn btn-primary"/>
|
||||
<field name="color" widget="color_picker" optional="show"/>
|
||||
</xpath>
|
||||
</field>
|
||||
|
||||
@@ -36,16 +36,34 @@ class ResGroups(models.Model):
|
||||
if employee.user_id:
|
||||
all_user_ids.add(employee.user_id.id)
|
||||
# 2. 添加选中部门及其子部门的所有员工对应的用户
|
||||
def get_department_employees(department_id):
|
||||
def get_department_employees(department_id, is_initial_call=False):
|
||||
"""
|
||||
递归获取指定部门及其所有子部门的员工对应的用户ID
|
||||
is_initial_call: 是否为初始调用(控制是否使用id.origin)
|
||||
"""
|
||||
valid_user_ids = set()
|
||||
employee_ids = self.env['hr.employee'].search([('department_id', '=', department_id.id)])
|
||||
# 处理不同类型的department_id输入
|
||||
if isinstance(department_id, int):
|
||||
dept_id = department_id
|
||||
elif hasattr(department_id, 'id'):
|
||||
if is_initial_call and hasattr(department_id.id, 'origin'):
|
||||
dept_id = department_id.id.origin
|
||||
else:
|
||||
dept_id = department_id.id
|
||||
else:
|
||||
return valid_user_ids # 无效输入,返回空集
|
||||
# 查询当前部门的员工
|
||||
employee_ids = self.env['hr.employee'].search([('department_id', '=', dept_id)])
|
||||
valid_user_ids.update([user.user_id.id for user in employee_ids if user.user_id])
|
||||
child_ids = self.env['hr.department'].search([('parent_id', '=', department_id.id)])
|
||||
# 查询子部门并递归处理
|
||||
child_ids = self.env['hr.department'].search([('parent_id', '=', dept_id)])
|
||||
for child in child_ids:
|
||||
valid_user_ids.update(get_department_employees(child))
|
||||
valid_user_ids.update(get_department_employees(child, is_initial_call=False))
|
||||
return valid_user_ids
|
||||
all_user_ids = set()
|
||||
for department_id in self.department_ids:
|
||||
all_user_ids.update(get_department_employees(department_id))
|
||||
all_user_ids.update(get_department_employees(department_id, is_initial_call=True))
|
||||
|
||||
# 3. 添加选中角色对应的用户
|
||||
for user_role in self.user_role_ids:
|
||||
user_employee_ids = self.env['hr.employee'].search(
|
||||
|
||||
Reference in New Issue
Block a user