3

当我要卸载自己的模块时,它会出错。(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()
4

3 回答 3

1

我的后端中的数据映射似乎有问题。所以我以管理员身份登录到 openerp 并创建新数据库并将我的模块迁移到那里。现在它的作品完美

谢谢大家

希望任何遇到此错误的人都能从此答案中获得帮助

于 2013-03-19T10:03:05.270 回答
1

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

于 2013-11-12T07:58:39.670 回答
-1

升级基本模块将摆脱数据库中的旧引用,并可能有助于卸载您的模块。

如果这仍然不起作用,您可以自担风险尝试这个独立的脚本。做好备份!

编辑:链接更新

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 的原因,还有其他一些原因

于 2014-03-04T21:37:58.977 回答