我正在关注构建模块的官方odoo-9教程。在Data Files部分之后,我将以下代码放入openacademy/demo/demo.xml
:
<openerp>
<data>
<record model="openacademy.course" id="course0">
<field name="name">Course 0</field>
<field name="description">Course 0's description
Can have multiple lines
</field>
</record>
<record model="openacademy.course" id="course1">
<field name="name">Course 1</field>
<!-- no description for this one -->
</record>
<record model="openacademy.course" id="course2">
<field name="name">Course 2</field>
<field name="description">Course 2's description</field>
</record>
</data>
</openerp>
但是,当我尝试安装我的模块时,我遇到以下错误:
...
File "D:\odoo-dev\odoo-9.0\openerp\tools\convert.py", line 630, in _tag_record
model = self.pool[rec_model]
File "D:\odoo-dev\odoo-9.0\openerp\modules\registry.py", line 84, in __getitem__
return self.models[model_name]
ParseError: "openacademy.course" while parsing file:///D:/odoo-dev/odoo-addons/openacademy/demo/demo.xml:3, near
<record model="openacademy.course" id="course0">
<field name="name">Course 0</field>
<field name="description">Course 0's description
Can have multiple lines
</field>
</record>
更新 我从xml文件中完全删除了撇号。但我仍然得到同样的错误。
<openerp>
<data>
<record model="openacademy.course" id="course0">
<field name="name">Course 0</field>
<field name="description">Course 0 description Can have multiple lines
</field>
</record>
<record model="openacademy.course" id="course1">
<field name="name">Course 1</field>
<field name="description">Description 2</field>
</record>
<record model="openacademy.course" id="course2">
<field name="name">Course 2</field>
<field name="description">Course 2 description</field>
</record>
</data>
</openerp>
错误:
...
ParseError: "openacademy.course" while parsing file:///D:/odoo-dev/odoo-addons/openacademy/demo/demo.xml:3, near
<record model="openacademy.course" id="course0">
<field name="name">Course 0</field>
<field name="description">Course 0 description Can have multiple lines
</field>
</record>
答案 0 :(得分:0)
答案 1 :(得分:0)
我解决了。我已经使用脚手架工具生成我的模块的结构,如官方文档中所述。脚手架工具生成以下结构:
odoo-addons/
|_ openacademy/
|_controllers/
|_demo/
|_models/
| |_ models.py
|
|_security/
|_views/
|_ __init__.py
|_ __openerp__.py
在__init__.py
我按照文档中的说明放置了以下内容:
from . import controllers
from . import models
在demo.xml
:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<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>
</openerp>
正如您所看到的,res_model
字段设置为openacademy.course
python无法找到,因为它未加载到__init__.py
文件中。将其更改为以下内容解决了我的问题:
from controllers import controllers
from models import models