Python 无法卸载模块-Openerp
当我要卸载自己的模块时,它会给出一个错误。(开场白7)在我的课堂上,我也输入了不同的修改。但我没有清除所有内容,只保留下面的代码。请帮我找出问题所在。。 现在,当我尝试安装通讯录模块时,也出现了这个错误Python 无法卸载模块-Openerp,python,xml,module,openerp,Python,Xml,Module,Openerp,当我要卸载自己的模块时,它会给出一个错误。(开场白7)在我的课堂上,我也输入了不同的修改。但我没有清除所有内容,只保留下面的代码。请帮我找出问题所在。。 现在,当我尝试安装通讯录模块时,也出现了这个错误 File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/modules/registry.py", line 218, in new openerp.modules.load_modules(registry.d
File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/modules/registry.py", line 218, in new
openerp.modules.load_modules(registry.db, force_demo, status, update_module)
File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/modules/loading.py", line 416, in load_modules
pool.get('ir.module.module').module_uninstall(cr, SUPERUSER_ID, mod_ids_to_remove)
File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/addons/base/module/module.py", line 439, in module_uninstall
ir_model_constraint._module_data_uninstall(cr, uid, constraint_ids, context)
File "/home/priyan/Software/openerp-7.0-20130309-002120/openerp/addons/base/ir/ir_model.py", line 533, in _module_data_uninstall
WHERE cs.contype=%s and cs.conname=%s and cl.relname=%s""", ('f', name, model_obj._table))
AttributeError: 'NoneType' object has no attribute '_table'
这是我的view.xml文件
<?xml version="1.0"?>
<openerp>
<data>
<!-- 1st part of the sim_view start -->
<record model="ir.ui.view" id="worker_form">
<field name="name">Basic Data</field>
<field name="model">checkroll.plucker</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Worker_test">
<field name="reg_no" />
<field name="worker_name" />
<field name="spouse_name" />
<field name="gender" />
<field name="epf_no" />
</form>
</field>
</record>
<!--2nd part of the sim_view start -->
<record model="ir.ui.view" id="worker_tree">
<field name="name">Basic Data</field>
<field name="model">checkroll.plucker</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Worker_test"><!-- which columns need to shows in OpenERP List View -->
<field name="reg_no" />
<field name="worker_name" />
<field name="spouse_name" />
</tree>
</field>
</record>
<!-- 3rd part of the sim_view start -->
<record model="ir.actions.act_window" id="action_worker_reg">
<field name="name">Worker Registration</field><!-- This shows what should
screen caption in form/tree views -->
<field name="res_model">checkroll.plucker</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
</data>
</openerp>
我的后端中的数据映射似乎有问题。因此我以管理员身份登录到openerp,创建新数据库并将模块迁移到那里。 现在它可以完美地工作了 谢谢大家
希望任何出现此错误的人都能从这个答案中获得帮助检查您是否在openerp.py中提供了所有必要的依赖项。这为我解决了问题。升级基本模块将删除数据库中的旧引用,并可能有助于卸载您的模块 如果这仍然不起作用,你可以自己冒险尝试。备份 编辑:链接已更新 EDIT2:在此处粘贴卸载\u module.py,使其不会消失 如果要使用此功能,请备份数据。通过传入数据库名称然后传入模块名称来调用脚本。下面是一个例子:
chaouche@karabeela ~/CODE/OPENERP/TEST $ python uninstall_module.py test helloworld
No handlers could be found for logger "openerp.modules.graph"
data browse_record(ir.model.constraint, 352)
data.name newfield_country_id_fkey
data browse_record(ir.model.constraint, 353)
data.name newfield_res_partner_category_rel_partner_id_fkey
data browse_record(ir.model.constraint, 354)
data.name newfield_res_partner_category_rel_category_id_fkey
data browse_record(ir.model.constraint, 355)
data.name newfield_title_fkey
data browse_record(ir.model.constraint, 356)
data.name newfield_parent_id_fkey
data browse_record(ir.model.constraint, 357)
data.name newfield_user_id_fkey
data browse_record(ir.model.constraint, 358)
data.name newfield_company_id_fkey
data browse_record(ir.model.constraint, 359)
data.name newfield_section_id_fkey
data browse_record(ir.model.constraint, 360)
data.name newfield_state_id_fkey
chaouche@karabeela ~/CODE/OPENERP/TEST $
下面是卸载模块.py:
import openerp
import logging
import sys
import argparse
_logger = logging.getLogger(__name__)
class ModuleRemover:
_logger = logging.getLogger(__name__)
uid = openerp.SUPERUSER_ID
def __init__(self,database,module_name):
"""
"""
self.module_name = module_name
self.pool = openerp.modules.registry.RegistryManager.get(database)
self.cr = self.pool.db.cursor()
def uninstall(self):
"""
"""
module = self.pool.get("ir.module.module")
constraint = self.pool.get("ir.model.constraint")
model_data = self.pool.get('ir.model.data')
module_id = module.search(self.cr,self.uid,[("name","=",self.module_name)])[0]
module_name = module.browse(self.cr,self.uid,module_id).name
ids = constraint.search(self.cr, self.uid, [('module', '=', module_id)])
self.cleanup(constraint,ids)
model_data._module_data_uninstall(self.cr,self.uid,[module_name])
module.write(self.cr, self.uid, module_id, {'state': 'uninstalled'})
def cleanup(self,constraint,ids):
"""
"""
for data in constraint.browse(self.cr,self.uid,ids):
print "data",data
model = data.model.model
model_obj = type("tmp",(),{})()
model_table = model
name = openerp.tools.ustr(data.name)
print "data.name",name
typ = data.type
if typ in ("u",'f'):
# test if FK exists on this table (it could be on a related m2m table, in which case we ignore it)
SQL = """SELECT 1 from pg_constraint cs JOIN pg_class cl ON (cs.conrelid = cl.oid)
WHERE cs.contype=%s and cs.conname=%s and cl.relname=%s""" % (typ, name, model_table)
print SQL
self.cr.execute(SQL)
if self.cr.fetchone():
SQL = 'ALTER TABLE "%s" DROP CONSTRAINT "%s"' % (model_table, name)
print SQL
self.cr.execute(SQL)
print 'Dropped FK CONSTRAINT %s@%s' % (name, model)
constraint.unlink(self.cr, self.uid, ids)
def main():
argparser = argparse.ArgumentParser()
argparser.add_argument("database", help="openerp database" ,type=str, )
argparser.add_argument("module" , help="module to uninstall" ,type=str, )
args = argparser.parse_args(sys.argv[1:])
ModuleRemover(args.database,args.module).uninstall()
if __name__ == "__main__":
main()
对于这个轶事,这就是为什么我放弃了openerp/oodoo,以及。您创建了一个模型,但在创建过程中更改了它的名称,而openerp似乎不知道如何处理这个问题。我不知道如何解决这个问题,我也处于同样的情况。当然,你可以从一个新的数据库开始,在那里导入模块,但这是一个解决办法。链接万岁!感谢@Odedra,刚刚更新了该页面存档版本的链接。
import openerp
import logging
import sys
import argparse
_logger = logging.getLogger(__name__)
class ModuleRemover:
_logger = logging.getLogger(__name__)
uid = openerp.SUPERUSER_ID
def __init__(self,database,module_name):
"""
"""
self.module_name = module_name
self.pool = openerp.modules.registry.RegistryManager.get(database)
self.cr = self.pool.db.cursor()
def uninstall(self):
"""
"""
module = self.pool.get("ir.module.module")
constraint = self.pool.get("ir.model.constraint")
model_data = self.pool.get('ir.model.data')
module_id = module.search(self.cr,self.uid,[("name","=",self.module_name)])[0]
module_name = module.browse(self.cr,self.uid,module_id).name
ids = constraint.search(self.cr, self.uid, [('module', '=', module_id)])
self.cleanup(constraint,ids)
model_data._module_data_uninstall(self.cr,self.uid,[module_name])
module.write(self.cr, self.uid, module_id, {'state': 'uninstalled'})
def cleanup(self,constraint,ids):
"""
"""
for data in constraint.browse(self.cr,self.uid,ids):
print "data",data
model = data.model.model
model_obj = type("tmp",(),{})()
model_table = model
name = openerp.tools.ustr(data.name)
print "data.name",name
typ = data.type
if typ in ("u",'f'):
# test if FK exists on this table (it could be on a related m2m table, in which case we ignore it)
SQL = """SELECT 1 from pg_constraint cs JOIN pg_class cl ON (cs.conrelid = cl.oid)
WHERE cs.contype=%s and cs.conname=%s and cl.relname=%s""" % (typ, name, model_table)
print SQL
self.cr.execute(SQL)
if self.cr.fetchone():
SQL = 'ALTER TABLE "%s" DROP CONSTRAINT "%s"' % (model_table, name)
print SQL
self.cr.execute(SQL)
print 'Dropped FK CONSTRAINT %s@%s' % (name, model)
constraint.unlink(self.cr, self.uid, ids)
def main():
argparser = argparse.ArgumentParser()
argparser.add_argument("database", help="openerp database" ,type=str, )
argparser.add_argument("module" , help="module to uninstall" ,type=str, )
args = argparser.parse_args(sys.argv[1:])
ModuleRemover(args.database,args.module).uninstall()
if __name__ == "__main__":
main()