Home > Back-end >  Invalid model name in action definition
Invalid model name in action definition

Time:08-25

I am trying to create custom module in odoo 15. when doing install it raise an error "Invalid model name 'school.course' in action definition"

My code as following:

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 >
            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

empty

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,

}

CodePudding user response:

To load the course model to database, you can add the following line to the module __init__.py file or move Course.py to models and add the import there:

from . import Course

To make a field required, you just need to set the required parameter to True.

required (bool) – whether the value of the field is required (default: False)

  • Related