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 osvがありsim.pyますか?

[モジュールの作成]ページの手順に従ってください。

sim.py注:ファイルにosvをインポートする場合は、PYTHONPATH変数にopenerpのベースディレクトリが含まれていることを確認してください。

于 2013-01-04T07:48:20.063 に答える