Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
7 Odpowiedzi
42110 Widoki

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
Awatar
Odrzuć

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

Autor

inside models folder

Najlepsza odpowiedź

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

 

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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>

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
sie 18
11862
0
paź 19
4473
2
sty 25
1416
4
paź 22
24267
3
lip 20
9066