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

Odoo15自定义模块安装报错:动作定义中模型名无效

Odoo15自定义模块安装报错:动作定义中模型名‘school.course’无效

我在Odoo15中创建自定义模块时,安装触发错误:“动作定义中模型名‘school.course’无效”。相关代码如下:

school/courses_action_menu.xml

<?xml version="1.0" encoding="UTF-8"?>
<odoo>
      <record id="courses_action" model="ir.actions.act_window">
        <field name="name">course</field>
        <field name="res_model">school.course</field>
        <field name="type">ir.actions.act_window</field>
        <field name="view_mode">tree,form</field>
        <field name="help" type="html">
          <p class="o_view_nocontent_smiling_face">
            Create a new course
          </p>
        </field>
      </record>
</odoo>

school/models/Course.py

from typing_extensions import Required
from odoo import fields, models

class shoolcourse(models.Model):
    _name = "school.course"
    _description = "Create a Course"

    title = fields.Char('Title',Required=True)
    description = fields.Char('Description')

school/models/init.py

(文件内容为空)

school/init.py

from . import models

manifest.py

{
    "name": "school",
    'depends': [
        ],
    'category': 'All',
    "sequence": 1,
    "data": [ 
              'views/courses_action_menu.xml',],
    "installable": True,
    "auto_install": False,
    "application": True,

}

问题原因及修复方案

1. 模型未被正确加载

school/models/__init__.py为空,Odoo无法识别并加载Course.py中的模型类。需要在该文件中导入模型:

from . import Course

2. 字段参数错误

  • 无需从typing_extensions导入Required,Odoo字段的必填参数为小写的required=True,而非Required=True
  • 模型类名建议使用大驼峰命名(如SchoolCourse),符合Python编码规范

修改后的Course.py:

from odoo import fields, models

class SchoolCourse(models.Model):
    _name = "school.course"
    _description = "课程信息"

    title = fields.Char('标题', required=True)
    description = fields.Char('描述')

3. XML文件路径不匹配

__manifest__.py中指定的XML路径为views/courses_action_menu.xml,但实际文件位于模块根目录,需修正路径:

{
    "name": "学校课程管理",
    'depends': [],
    'category': 'All',
    "sequence": 1,
    "data": [
        'courses_action_menu.xml',
    ],
    "installable": True,
    "auto_install": False,
    "application": True,
}

完成以上修改后,重新升级模块即可解决报错问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.21 19:12:20