Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
7 ตอบกลับ
41979 มุมมอง

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>

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ส.ค. 18
11777
0
ต.ค. 19
4405
2
ม.ค. 25
1275
4
ต.ค. 22
24107
3
ก.ค. 20
8963