我使用python和xml在openerp
中完成了简单的自定义模块。但我无法在openerp中导入。我的模块没有在openerp中显示。
这是__init__py
import os
os.environ['TZ'] = 'UTC' # Set the timezone...
import time # ... *then* import time.
del os
del time
# The hard-coded super-user id (a.k.a. administrator, or root user).
SUPERUSER_ID = 1
import addons
import cli
import conf
import loglevels
import modules
import netsvc
import osv
import pooler
import release
import report
import service
import sql_db
import tools
import workflow
import sim
# backward compatilbility
# TODO: This is for the web addons, can be removed later.
wsgi = service
wsgi.register_wsgi_handler = wsgi.wsgi_server.register_wsgi_handler
# Is the server running in multi-process mode (e.g. behind Gunicorn).
# If this is True, the processes have to communicate some events,
# e.g. database update or cache invalidation. Each process has also
# its own copy of the data structure and we don't need to care about
# locks between threads.
multi_process = False
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
这是__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,
'active': 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" version="7.0">
<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>
这个sim.py
from openerp.osv import fields
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中看不到我的模块。我该如何解决这个问题?
答案 0 :(得分:2)
要在OpenERP 7中查看自定义模块,它必须首先位于addons
目录中。
转到Settings
&gt; Modules
&gt; Update Modules List
点击Update
您必须为您登录的用户启用Technical Features
。
然后转到Settings
&gt; Modules
&gt; Installed Modules
删除[Installed]
过滤器并搜索您的自定义模块。
自定义模块不会出现在Settings
&gt; Modules
&gt; Apps
因为该视图只会显示在线找到的Modules/Apps
。
答案 1 :(得分:2)
我在这里看到的唯一问题是你的openerp.py
文件名不正确,名称应该是__openerp__
,而在__init__.py
文件中你应该导入sim.py
} file,并且无需导入您在那里编写的所有模块,只保留您需要的必要库和模块。
答案 2 :(得分:2)
这样可以正常工作。试试这个。更新所有文件。
__openerp__.py File
{
'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'],
'data': ['sim_view.xml'],
'demo': [],
'installable': True,
'auto_install': False,
'application': True,
}
__init__.py File
import sim
sim.py File
from openerp.osv import fields, osv
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()
sim_view.xml File
<?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" version="7.0">
<group>
<field name="name"/>
<field name="student_name"/>
<field name="father_name"/>
<field name="gender"/>
<field name="contact_no"/>
</group>
</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>
更新所有文件后,重新启动服务器,更新模块列表并找到您的 设置&gt;中的模块模块&gt;已安装的模块 - 从那里卸下安装并在那里写下你的模块名称(即sim)。
希望这肯定会奏效。
答案 3 :(得分:1)
再一次确保你已将你的模块放在addons目录中所有的所有
其他模块存在。不在服务器的插件内,它应该在主插件内。
Hope this will solve your problem
答案 4 :(得分:0)
正如@Zak所说,__init__.py
只需要导入sim
,这是您在模块中使用的python文件。在__openerp__.py
文件中,我找不到任何错误。我找到的问题是在sim.py
文件中!您只从fields
导入openerp.osv
。您的类现在继承了osv文件夹。您的类应该继承osv文件的osv类(类名:Model)。对于openerp功能,您必须从osv
导入openerp.osv
。请使用from openerp.osv import osv, fields
修改sim.py。
答案 5 :(得分:0)
转到设置&gt;模块&gt;更新模块列表
点击更新
您必须为您登录的用户启用技术功能。
然后转到设置&gt;模块&gt;已安装的模块
删除[已安装]过滤器并搜索自定义模块。
自定义模块不会出现在设置&gt;模块&gt;应用,因为该视图只会显示在线找到的模块/应用。