无法卸载Module - Openerp

时间:2013-03-19 03:08:46

标签: python xml module openerp

当我要卸载我自己的module.its时会出错。 (OpenErp ver 7)在我班上我也进入了不同的不同修改。但是我不清楚所有的东西,只保留下面的代码。请帮我找到这个问题.. 现在当我尝试安装address_book模块时也发生了这个错误

  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>

这是我的班级文件

from openerp.osv import fields, osv
import random

class checkroll(osv.osv):
    _name = "checkroll.plucker"
    _description = "This table is for keeping personal data of plucker"
    _columns = {
        'reg_no': fields.char('Registration Number', size=256, required=True),
        'worker_name': fields.char('Worker Name', size=256, required=True),
        'spouse_name': fields.char('Spouse Name', size=256),
        'gender' : fields.selection((('male', 'Male'), ('female', 'Female'), ('middle', 'Test')), 'Gender', required=True),
        'epf_no':fields.char('EPF Number', size=256)
    }

checkroll()

3 个答案:

答案 0 :(得分:1)

似乎在我的后端数据映射问题。所以我以admin&amp;登录到openerp。创建新数据库&amp;将我的模块迁移到那里。 现在它完美无缺

感谢所有

希望任何一个人得到这个错误都会得到这个答案的帮助

答案 1 :(得分:1)

检查您是否在 openerp .py中提供了所有必需的依赖项。这解决了我的问题。

答案 2 :(得分:-1)

升级基础模块将删除数据库中的旧引用,并可能有助于卸载模块。

如果仍然无效,您可以自行承担standalone script的风险。做个备份!

编辑 :链接已更新

EDIT2 :粘贴 uninstall_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 $

这是 uninstall_module.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以及some other reasons的原因。