跳至内容
菜单
此问题已终结
7 回复
41837 查看

I have installed Odoo 10 on Ubuntu and it works fine

I'm following the tutorial 'building a module' from the Odoo website  

https://www.odoo.com/documentation/10.0/howtos/backend.html#build-an-odoo-module

I have created an empty module with the the command:

odoo-bin scaffold openacademy addons


but when I try to import a module in to the xml file openacademy.xml I get the following error: 


Model not found: openacademy.course
Error context:
View `course.form`[view_id: 4867, xml_id: n/a, model: openacademy.course, parent_id: n/a]None" while parsing /opt/odoo/odoo-10.0/addons/openacademy/views/openacademy.xml:6, near<record model="ir.ui.view" id="course_form_view"> <field name="name">course.form</field> <field name="model">openacademy.course</field> <field name="arch" type="xml"> <form string="Course Form"> <sheet> <group> <field name="name"/> <field name="description"/> </group> </sheet> </form> </field> </record>

here is my files:


openacademy.xml:

<?xml version="1.0" encoding="utf-8"?>

<odoo>

<data>

      <record model="ir.ui.view" id="course_form_view">

         <field name="name">course.form</field>

         <field name="model">openacademy.course</field>

         <field name="arch" type="xml">

              <form string="Course Form">

                    <sheet>

                          <group> <field name="name"/> <field name="description"/> </group>

                  </sheet>   

          </form>

      </field>

    </record>  

     </data>

</odoo> 


models.py

from odoo import models, fields, api
class Course(models.Model):
_name = 'openacademy.course'
name = fields.Char(string="Title", required=True)description = fields.Text()


__init__.py

from . import models
形象
丢弃

where is your models.py file residing path? I mean inside models folder or outside?

编写者

inside models folder

最佳答案

just create a module with your code, and it installed smoothly,. .

just change the indent of the models.py.
from odoo import models, fields
class Course(models.Model):
     _name = 'openacademy.course'
     name = fields.Char(string="Title", required=True)
     description = fields.Text("Description")
   

just add a  __manifest__.py file. .

__manifest__.py

{    
    'name': 'test',
    'version': '1.0',
    'category': 'test',
    'description': """test""",
    # 'website': 'https://www.odoo.com/page/accounting',
    'depends': ['base'],
    'data': [ 'openacademy.xml' ],
    'installable': True,
}

 

形象
丢弃
最佳答案

arrange everything like this and then try,

openacademy/models/models.py

from odoo import models, fields, api
class Course(models.Model):
    _name = 'openacademy.course'
    name = fields.Char(string="Title", required=True)
    description = fields.Text()

openacademy/views/openacademy.xml

<odoo>    
    <data>
        <record model="ir.actions.act_window" id="course_list_action">
            <field name="name">Courses</field>
            <field name="res_model">openacademy.course</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="help" type="html">
                <p class="oe_view_nocontent_create">Create the first course</p>
            </field>
        </record>
     
        <menuitem id="main_openacademy_menu" name="Open Academy"/>
        <menuitem id="openacademy_menu" name="Open Academy" parent="main_openacademy_menu"/> 
        <menuitem id="courses_menu" name="Courses" parent="openacademy_menu" action="course_list_action"/>
     </data>
</odoo>

openacademy/__manifest__.py

{
     'name': "Open Academy",
     'author': "My Company",
     'version': '0.1',
     'depends': ['base'],
     'data': [
         'views/openacademy.xml',
     ],
     'demo': []

openacademy/models/__init__.py

from . import models

openacademy/__init__.py

from . import models

I hope this will help you.

形象
丢弃
最佳答案

You simply need to restart your Odoo server. It will solve the problem.

形象
丢弃
最佳答案

Have you started the server with the option --dev=all ?

形象
丢弃
编写者 最佳答案

I've added the indentation,

added 'views/openacademy.xml' into __manifest__.py

but still the view can't recognize the model !!


ParseError: "Invalid model name u'openacademy.course' in action definition.

None" while parsing /opt/odoo/odoo-10.0/addons/openacademy/views/openacademy.xml:5, near

<record model="ir.actions.act_window" id="course_list_action">

    <field name="name">Courses</field>

    <field name="res_model">openacademy.course</field>

    <field name="view_type">form</field>

    <field name="view_mode">tree,form</field>

    <field name="help" type="html">

        <p class="oe_view_nocontent_create">Create the first course</p>

    </field>

</record>

形象
丢弃
相关帖文 回复 查看 活动
2
8月 18
11666
0
10月 19
4331
2
1月 25
1148
4
10月 22
23943
3
7月 20
8834