简体   繁体   中英

Unable to uninstall Module - Openerp

when I'm going to uninstall my own module.its gives a error. (OpenErp ver 7)in my class i entered different different modification also.but not i clear all that stuffs and keep below codes only.please help me to find what is the issue with this.. now when i try to install address_book module also occured this error

  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'

here is my view.xml file

<?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>

here is my class file

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()

seems issue with data mappings in my backend.so i logged to openerp as admin & create new database & migrate my modules to there. now its works perfectly

thanks for all

hope any one get this error will get help from this answer

Check if you have provided all the necessary dependencies in your openerp .py. This fixed the problem for me.

Upgrading base module will get rid of old references in the database and may help in uninstalling your module.

If that still doesn't work, you can try this standalone script at your own risk. Make a backup !

EDIT : link updated

EDIT2 : pasting uninstall_module.py here so it doesn't go away.

Backup your data if you want to use this. You call the script by passing in a database name then your module name. Here's an example :

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 $

Here's 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()

For the anecdote this is what made me drop openerp/oodoo, along with some other reasons .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM