3

我有制作新简单模块的教程OpenERP 6,我制作了 4 个文件:

1. __init__.py
2. __openerp__.py
3. sim.py
4. sim_view.xml

完成所有操作后,我重新启动了我的服务OpenERP,然后创建了一个新数据库并刷新了我的OpenERP. 然后我以管理员身份登录,但我找到了我的模块“sim”,但是当我尝试安装它时,出现"NameError: name 'osv' is not defined".错误是怎么回事?

真的需要你们的帮助!

__init__.py

import sim

sim.py

class student(osv.osv):
    _name = "sim.student"
    _description = "This table is for keeping personal data of student"
    _columns = {
        'name': fields.char('Registration Number',size=256,required=True),
        'student_name': fields.char('Student Name',size=256,required=True),
        'father_name': fields.char('Father Name',size=256),
        'gender':fields.selection([('male','Male'),('female','Female')],'Gender'),
        'contact_no':fields.char('Contact Number',size=256)
    }
student()

__openerp__.py

{
'name': 'Student Information Management',
'version': '0.1',
'category': 'Tools',
'description': """This module is for the Student Information Management.""",
'author': 'Mir Nauman Tahir',
'website': 'http://mirnauman.wordpress.com/',
'depends': ['base'],
'init_xml': [],
'update_xml': ['sim_view.xml'],
'demo_xml': [],
'installable': True,
}

sim_view.xml

<?xml version="1.0"?>
<openerp>
<data>
<!-- ============== student================= -->
<!-- 1st part of the sim_view start-->
<record model="ir.ui.view" id="student_form">
<field name="name">Student</field>
<field name="model">sim.student</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Student">
<field name="name"/>
<field name="student_name"/>
<field name="father_name"/>
<field name="gender"/>
<field name="contact_no"/>
</form>
</field>
</record>
<!-- 1st part of the sim_view end-->
<!--2nd part of the sim_view start-->
<record model="ir.ui.view" id="student_tree">
<field name="name">Student</field>
<field name="model">sim.student</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Student">
<field name="name"/>
<field name="student_name"/>
<field name="father_name"/>
<field name="gender"/>
<field name="contact_no"/>
</tree>
</field>
</record>
<!--2nd part of the sim_view end-->
<!-- 3rd part of the sim_view start-->
<record model="ir.actions.act_window" id="action_student">
<field name="name">Student</field>
<field name="res_model">sim.student</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<!--3rd part of the sim_view end-->
<!--4th part of the sim_view start-->
<menuitem&nbsp;name="SIM/Student/StudentInfo" id="menu_sim_student" action="action_student"/>
<!--4th part of the sim_view end-->
</data>
</openerp>
4

3 回答 3

4

从 6.1 开始,osv弃用。您的sim.py文件应以:

from openerp.osv import fields, orm

class student(orm.Model):
    #model definitions go here...
于 2013-01-04T09:40:40.413 回答
3

添加新字段还需要以下内容

from osv import osv,fields
于 2013-01-04T08:29:03.173 回答
2

from osv import osvsim.py文件中提到过吗?

请按照创建模块页面中的步骤进行操作。

注意:如果您在sim.py文件中导入 osv,则检查PYTHONPATH变量是否包含 openerp 的基本目录。

于 2013-01-04T07:48:20.063 回答