ws_123
ws_123

Reputation: 5691

Making new simple module in OpenERP 6

I've tutorial to make new simple module in OpenERP 6, I made 4 files :

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

when I've finished all, I had restarted my service of OpenERP, and then made a new database and refresh my OpenERP. Then I have logged in as administration ,but I found my module 'sim', but when I tried to instal it, there is an error "NameError: name 'osv' is not defined". whats wrong?

Really need your help guys!

__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>

Upvotes: 3

Views: 2964

Answers (3)

OmaL
OmaL

Reputation: 5044

The following is also required for adding new fields

from osv import osv,fields

Upvotes: 3

Daniel Reis
Daniel Reis

Reputation: 13382

As of 6.1, osv is deprecated. Your sim.py file should begin with:

from openerp.osv import fields, orm

class student(orm.Model):
    #model definitions go here...

Upvotes: 4

Neel
Neel

Reputation: 21329

Have you mention from osv import osv in the sim.py file?

Please follow the steps in Create Module page.

Note: If you import the osv in sim.py file then check PYTHONPATH variable contains openerp's base directory.

Upvotes: 2

Related Questions