当前位置:首页>python>中篇Python(ODOO)篇 第三章 ODOO项目开发(四)添加业务部分模块 1.预约单

中篇Python(ODOO)篇 第三章 ODOO项目开发(四)添加业务部分模块 1.预约单

  • 2026-10-11 08:02:30
中篇Python(ODOO)篇 第三章 ODOO项目开发(四)添加业务部分模块 1.预约单
原始需求图:

预约情况

学员姓名:

王小二

手机:

1862323

日期:

2020/8/1

预约时间:

7:00:00

至

9:59:59

排档类:

手动挡

金额:

220

自备车:

否

上车地点:

上海浦东大道1111号

下车地点:

上海浦东大道22号

教练员

工号:

001

姓名:

顾总

车辆信息

车牌:

沪A7868

类型:

桑塔纳3000型

实际情况

学员姓名:

王小二

手机:

1862323

日期:

2020/8/1

陪驾时间:

7:00:00

至

9:59:59

排档类:

手动挡

金额:

220

自备车:

否

上车地点:

上海浦东大道1111号

下车地点:

上海浦东大道22号

教练员

工号:

001

姓名:

顾总

车辆信息

车牌:

沪99900A

类型:

桑塔纳3000型

新增数据模型

models目录新建appointment.py数据模型文件,代码如下:
from odoo import fields, models, apiclass NebulaAppointment(models.Model):    _name = "nebula.appointment"    _description = "预约管理"    _order = 'name'    active = fields.Boolean('预约有效', default=True)    complete = fields.Boolean('预约完成', default=False)    name = fields.Char('预约简情', size=30)    student_name = fields.Many2one('nebula.student', string='学员姓名',                                   index=True, size=8, copy=False)    student_seq = fields.Char('学员编号', related='student_name.seq', store=True)    student_mobile = fields.Char('学员手机', related='student_name.mobile')    appointment_begin_date = fields.Datetime('预约起始时间', required=True,                                             index=True,                                             default=fields.Datetime.now)    appointment_end_date = fields.Datetime('预约结束时间', required=True,                                           index=True,                                           default=fields.Datetime.now)    complete_begin_date = fields.Datetime('实际起始时间')    complete_end_date = fields.Datetime('实际结束时间')    auto_type_name = fields.Selection(selection='_select_auto_type', string='预约类型')    teacher_name = fields.Many2one('nebula.teacher', string='教练工号',                                   index=True, size=8, copy=False,                                   domain=[('active', '=', True)])    teacher_full_name = fields.Char('教练姓名', related='teacher_name.full_name',                                    store=True)    car_name = fields.Many2one('nebula.car', string='车辆编号', index=True,                               size=8, copy=False,                               domain=[('active', '=', True)])    license_plate = fields.Char('车辆牌照', related='car_name.license_plate',                                store=True)    car_type_name = fields.Selection(selection='_select_car_type', string='车型', related='car_name.car_type_name')    car_auto_type_name = fields.Selection(selection='_select_auto_type', string='排挡类', related='car_name.auto_type_name')    deposit = fields.Integer('学员缴费')    pay = fields.Integer('本次支付费用')    balance = fields.Integer('余额')    begin_address = fields.Text('上车地点')    end_address = fields.Text('下车地点')    user_id = fields.Many2one('res.users', string='创建人', index=True,                              readonly=True, default=lambda self: self.env.user)    date_docket = fields.Datetime('单据日期', required=True, readonly=True,                                  index=True, default=fields.Datetime.now)    @api.model    def _select_car_type(self):        records = self.env['nebula.car.type'].search([('active', '=', True)])        return [(r.name, r.name_type) for r in records]    def _select_auto_type(self):        records = self.env['nebula.auto.type'].search([])        return [(r.name, r.name_type) for r in records]    # TODO: 1.预约结束时间在预约开始时间修改后自动后推每节课时间    # 2.balance # 计算字段,学员缴费之和-本次支付费用之和    # 3.每次修改都要记录    # 4.学员筛选条件需要修改    # 5.如果是旧学员,显示旧预约列表,显示一条后复制原来信息
将该文件名添加到models目录下__init__.py文件中,之前已经有演示。

设置访问权限

在security目录下的ir.model.access.csv新增两行权限记录。
access_nebula_appointment,nebula.appointment,model_nebula_appointment,group_peijia_manager,1,1,1,1access_nebula_appointment_user,nebula.appointment,model_nebula_appointment,group_peijia_user,1,1,1,0

创建视图层

在views目录新增appointment_views.xml文件,先用默认方式展示即可,待模块加载成功后再逐步修改和完善文件,内容如下:
<?xml version="1.0" encoding="utf-8"?><odoo>    <act_windowid="peijia.action_appointment_views"name="预约管理"    res_model="nebula.appointment" view_mode="tree,form" /></odoo>
修改peijia目录下__manifest__.py文件中data段,在views/car_type_views.xml前新增views/appointment_views.xml文件名。
在views目录下car_views.xml文件,学员管理三级菜单下添加菜单指向预约管理子模块,代码:
<menuitem id="menu_appointment_views" name ="预约管理"          parent="menu_peijia_student_data" sequence="90"          action="peijia.action_appointment_views"/>
截图:
重启后,更新陪驾模块,查看是否已经有相关菜单和界面。正常后读者可继续修改视图层。

完善视图层

预约模块修改量较大,我们继续完成剩余部分模块界面后,最后再完善功能。

界面展示

列表效果:
表单效果:

最新文章

随机文章