我在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 name="SIM/Student/StudentInfo" id="menu_sim_student" action="action_student"/>
<!--4th part of the sim_view end-->
</data>
</openerp>
答案 0 :(得分:4)
自6.1起,osv
为deprecated。您的sim.py
文件应以:
from openerp.osv import fields, orm
class student(orm.Model):
#model definitions go here...
答案 1 :(得分:3)
添加新字段
还需要以下内容from osv import osv,fields
答案 2 :(得分:2)
您是否在from osv import osv
文件中提到了sim.py
?
请按照Create Module页中的步骤进行操作。
注意:如果您在sim.py
文件中导入osv,请检查PYTHONPATH
变量是否包含openerp的基本目录。