How to uninstall manually openerp module
Question: I have installed a module on openerp v7 that I would like to uninstall.

Using the interface fails, i get an error during the uninstall process.

Is there a 'manual' way to uninstall a module ? Is it sufficient to remove the
module folder under `addons/` or is there any other things to do, to make it
in the cleanest way ?

Here is the error I get when i try to uninstall a module through the
interface:

    
    
    Client Traceback (most recent call last):
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/addons/web/http.py", line 204, in dispatch
        response["result"] = method(self, **self.params)
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/addons/web/controllers/main.py", line 1132, in call_button
        action = self._call_kw(req, model, method, args, {})
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/addons/web/controllers/main.py", line 1120, in _call_kw
        return getattr(req.session.model(model), method)(*args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/addons/web/session.py", line 42, in proxy
        result = self.proxy.execute_kw(self.session._db, self.session._uid,     self.session._password, self.model, method, args, kw)
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/addons/web/session.py", line 30, in proxy_method
        result = self.session.send(self.service_name, method, *args)
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/addons/web/session.py", line 103, in send
        raise xmlrpclib.Fault(openerp.tools.ustr(e), formatted_info)
    
    
    Server Traceback (most recent call last):
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/addons/web/session.py", line 89, in send
        return openerp.netsvc.dispatch_rpc(service_name, method, args)
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/netsvc.py", line 292, in dispatch_rpc
        result = ExportService.getService(service_name).dispatch(method, params)
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/service/web_services.py", line 626, in dispatch
        res = fn(db, uid, *params)
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/osv/osv.py", line 188, in execute_kw
        return self.execute(db, uid, obj, method, *args, **kw or {})
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/osv/osv.py", line 131, in wrapper
        return f(self, dbname, *args, **kwargs)
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/osv/osv.py", line 197, in execute
        res = self.execute_cr(cr, uid, obj, method, *args, **kw)
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/osv/osv.py", line 185, in execute_cr
        return getattr(object, method)(cr, uid, *args, **kw)
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/addons/base/module/module.py", line 495, in button_immediate_uninstall
        return self._button_immediate_function(cr, uid, ids, self.button_uninstall,     context=context)
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/addons/base/module/module.py", line 475, in _button_immediate_function
        _, pool = pooler.restart_pool(cr.dbname, update_module=True)
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/pooler.py", line 39, in restart_pool
        registry = RegistryManager.new(db_name, force_demo, status, update_module)
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/modules/registry.py", line 218, in new
        openerp.modules.load_modules(registry.db, force_demo, status, update_module)
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/modules/loading.py", line 354, in load_modules
        loaded_modules, update_module)
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/modules/loading.py", line 256, in load_marked_modules
        loaded, processed = load_module_graph(cr, graph, progressdict, report=report,     skip_modules=loaded_modules, perform_checks=perform_checks)
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/modules/loading.py", line 188, in load_module_graph
        load_data(module_name, idref, mode)
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/modules/loading.py", line 76, in <lambda>
        load_data = lambda *args: _load_data(cr, *args, kind='data')
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-    py2.7.egg/openerp/modules/loading.py", line 124, in _load_data
        tools.convert_xml_import(cr, module_name, fp, idref, mode, noupdate, report)
      File "/usr/local/lib/python2.7/dist-packages/openerp-7.0_20131016_232725-py2.7.egg/openerp/tools/convert.py", line 945, in convert_xml_import
        relaxng.assert_(doc)
      File "lxml.etree.pyx", line 3027, in lxml.etree._Validator.assert_     (src/lxml/lxml.etree.c:129517)
    AssertionError: Did not expect text in element record content, line 33
    

Sorry for this long trace..

At first I suspected one of the xml files to wrong, but as I get the same
error when I try to install a module manually, I think something else is going
wrong but I can't see what.

Cheers


Answer: Removing the module's code from `addons/`is not enough - this will break
OpenERP.

**Solution 1 - Try to resolve the error you have during normal uninstall**

This method is recommended because OpenERP does the job cleanly. Look at the
error you have during uninstallation and try to imagine what could be the
problem. Post the error trace here for further help.

**Solution 2 - Manual uninstall**

My procedure is based on OpenERP v6.0 but it should be very similar in OpenERP
v7.

  1. Backup your database :). Do it. It's very probable that you break something during this procedure.

  2. Find what records were created during the installation or the update of the module.

     * Look at `__openerp__.py` to see which XML files are taken into account when installing and updating the module. Alternatively, consider all XML files in the module's directories. 

     * Search for records created by this modules during install or update. There should be XML elements like `<record ...model='...'>` inside these files. The `model` attribute tells you in which datatable the record resides. If you are using a Unix-like system, you can try the following command in the module's root directory:

`grep -r -n -A 5 --include="*.xml" \<record *`

  3. Delete these records. You'll use some database interface tool such as `PgAdmin` or `pqsl` and find the records discovered in the previous step. 

For example, the following XML line defines a record in the `ir_cron`
datatable:

`<record model="ir.cron" id="ir_cron_account_fiscalyear_close">`

Knowing that, you can find the record based on the data defined for this
record in the XML file.

  4. Find and delete all the menu items defined by the module. As above, search the XML files for `<menuitem ...>` elements. Look for related records in the `ir_ui_menu` datatable.

  5. Discover which `models` were defined by the module. Try the following command:

`grep -r -n -C 5 --include="*.py" "_name = " *`

Only pay attention to models defined in objects that derive from `osv.osv`
(`osv.Model` in OpenERP v7). They define persistent models stored in the
database. Objects descendant from `osv.osv_memory` (`osv.TransientModel` in
v7) are not stored in the database.

Be careful and avoid deleting models defined in parent objects. Look at the
`_inherit` property of the object to give you an idea about that. In this
case, you want to only delete the columns added by your module.

Once you discover the models defined by your module, try to delete the
corresponding datatables. For example, the model with

`_name = "bg_vat.bg_vat"`

will have a corresponding table in the database named 'bg_vat_bg_vat'.

  6. Finally, remove or just deactivate the module. Look for a record corresponding to your module in `ir_module_module` datatable. You can delete the record or just set the `state` field to `uninstalled`.

If you like, you can now delete the module's directory from `addons` but I
don't see a reason to do this.

I'm sure I missed some cleaning actions (like the records in the `ir_model*`
datatable family). I'm also pretty sure this procedure can easily break your
OpenERP installation. Make a backup first. :)

