You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Odoo 16.0中为Hr.attendance创建日历视图

在Odoo 16.0中为Hr.attendance添加日历视图

错误原因

直接在动作视图类型中添加日历视图时出现报错,是因为Odoo的日历视图必须依赖至少两个日期/时间字段来定义事件的开始和结束。默认的hr.attendance模型虽有check_in和check_out这两个符合要求的datetime字段,但未在日历视图配置中指定它们,导致系统无法识别可用的时间字段。

实现步骤

通过自定义模块来添加日历视图,具体操作如下:

1. 创建自定义模块结构

假设模块名为hr_attendance_calendar,目录结构如下:

hr_attendance_calendar/
├── __init__.py
├── __manifest__.py
└── views/
    └── hr_attendance_views.xml

2. 配置模块清单(manifest.py)

确保模块依赖hr_attendance基础模块:

{
    'name': 'HR Attendance Calendar View',
    'version': '16.0.1.0.0',
    'author': 'Your Name',
    'depends': ['hr_attendance'],
    'data': [
        'views/hr_attendance_views.xml',
    ],
    'installable': True,
    'auto_install': False,
}

3. 编写日历视图XML(hr_attendance_views.xml)

定义日历视图并更新原考勤动作,添加日历视图选项:

<odoo>
    <!-- 定义日历视图 -->
    <record id="hr_attendance_calendar_view" model="ir.ui.view">
        <field name="name">hr.attendance.calendar.view</field>
        <field name="model">hr.attendance</field>
        <field name="arch" type="xml">
            <calendar 
                string="Employee Attendances" 
                date_start="check_in" 
                date_stop="check_out" 
                color="employee_id"
            >
                <field name="employee_id"/>
                <field name="check_in"/>
                <field name="check_out"/>
                <field name="worked_hours"/>
            </calendar>
        </field>
    </record>

    <!-- 更新原考勤动作,添加日历视图 -->
    <record id="hr_attendance_action" model="ir.actions.act_window">
        <field name="view_mode">kanban,tree,form,calendar</field>
        <field name="views" eval="[(False, 'kanban'), (False, 'tree'), (False, 'form'), (ref('hr_attendance_calendar_view'), 'calendar')]"/>
    </record>
</odoo>

4. 安装模块并验证

  • 将模块放入Odoo的addons目录
  • 开启开发者模式,搜索并安装HR Attendance Calendar View模块
  • 进入「员工」->「考勤」菜单,即可看到新增的日历视图选项

关键配置说明

  • date_start="check_in":指定考勤记录的开始时间字段
  • date_stop="check_out":指定考勤记录的结束时间字段
  • color="employee_id":按员工区分日历事件的颜色,提升可读性
  • 更新原动作的view_mode和views字段,让系统加载新的日历视图

内容的提问来源于stack exchange,提问作者Pragnesh Gajjar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 12:57:38