簡體   English   中英

無法在openERP中導入自定義模塊

[英]Can not import customize module in openERP

我在openerp中使用python和xml完成​​了簡單的自定義模塊。 但我無法在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&nbsp;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中看不到我的模塊。 我怎樣才能解決這個問題?

要在OpenERP 7中查看自定義模塊,它必須首先位於addons目錄中。

轉至Settings > Modules > Update Modules List

單擊Update

您必須為您登錄的用戶啟用Technical Features

然后轉到Settings > Modules > Installed Modules

刪除[Installed]過濾器並搜索自定義模塊。

自定義模塊不會出現在Settings > Modules > Apps因為該視圖將僅顯示在線找到的Modules/Apps

我在這里看到的唯一問題是你的openerp.py文件名不正確,名稱應該是__openerp__ ,再加上__init__.py文件,你應該導入sim.py文件,而不需要導入所有那些模塊你在那里寫的,只保留你需要的必要的庫和模塊。

這樣可以正常工作。 試試這個。 更新所有文件。

__openerp__.py   File

{
'name': 'Student Information Management',
'version': '0.1',
'category': 'Tools',
'description': """This module is for the Student Information Management.""",
'author': 'Mir Nauman&nbsp;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>

更新完所有文件后,重新啟動服務器,更新模塊列表並在設置>模塊>已安裝模塊中找到您的模塊 - 從那里刪除已安裝並在那里寫下您的模塊名稱(即SIM卡)。

希望這肯定會奏效。

再次確保您已將模塊放在addons目錄中的所有位置
其他模塊存在。 不在服務器的插件內,它應該在主插件內。

   Hope this will solve your problem

正如@Zak所說, __init__.py init__.py只需要導入sim ,這是你在模塊中使用的python文件。 __openerp__.py文件中,我找不到任何錯誤。 我發現的問題是在sim.py文件中! 您只導入openerp.osv fields 您的類現在繼承了osv文件夾。 您的類應該繼承osv文件的osv類(類名:Model)。 對於OpenERP的功能,你必須輸入osvopenerp.osv 請使用from openerp.osv import osv, fields修改sim.py。

如果您想在OpenERP 7中看到自定義模塊,它必須首先位於addons目錄中。

轉至設置>模塊>更新模塊列表

單擊更新

您必須為您登錄的用戶啟用技術功能。

然后轉到設置>模塊>已安裝的模塊

刪除[已安裝]過濾器並搜索自定義模塊。

自定義模塊不會出現在設置>模塊>應用程序中,因為該視圖將僅顯示在線找到的模塊/應用程序。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM