This question has been flagged

We're adding additional phone fields to Leads (crm.leads) and Partners (res.partner). When the module is installed, fields are added and that seems to work properly. The problem shows up when we try to uninstall the module.

We get the following error message:

2015-01-30 20:55:43,899 1873 ERROR DB openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 530, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 567, in dispatch
    result = self._call_function(**self.params)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 303, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 300, in checked_call
    return self.endpoint(*a, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 796, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 396, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 953, in call_button
    action = self._call_kw(model, method, args, {})
  File "/usr/lib/python2.7/dist-packages/openerp/addons/web/controllers/main.py", line 941, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/base/module/wizard/base_module_upgrade.py", line 105, in upgrade_module
    openerp.modules.registry.RegistryManager.new(cr.dbname, update_module=True)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 366, in new
    openerp.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 351, in load_modules
    force, status, report, loaded_modules, update_module)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 255, in load_marked_modules
    loaded, processed = load_module_graph(cr, graph, progressdict, report=report, skip_modules=loaded_modules, perform_checks=perform_checks)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/loading.py", line 152, in load_module_graph
    models = registry.load(cr, package)
  File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 162, in load
    model = cls._build_model(self, cr)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 591, in _build_model
    original_module = pool[name]._original_module if name in parents else cls._module
  File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 101, in __getitem__
    return self.models[model_name]
KeyError: 'crm.lead'

 

If we remove the 'crm.lead' portion, and leave only res.partner, we have no problem uninstalling the module.

Note: The views seem to work fine. The issue seems to be related to the inheritance from 'crm.lead'.

Any pointers as to where the problem could be?

 

Relevant code follows...

Extra_Phones.py:

from openerp.osv import osv, orm, fields
from openerp import models
from openerp.tools.translate import _

class crm_lead(orm.Model):
    _name = 'crm.lead'
    _inherit = 'crm.lead'
    _columns = {
        'phone2': fields.char('Phone2', help=""),
        'phone3': fields.char('Phone3', help=""),
        'phone4': fields.char('Phone4', help=""),
        'phone5': fields.char('Phone5', help=""),
    }

crm_lead()

class res_partner(orm.Model):
    _name = 'res.partner'
    _inherit = 'res.partner'
    _columns = {
        'phone2': fields.char('Phone2', help=""),
    }

res_partner()

Extra_Phones_Views.xml:

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>
    <record model="ir.ui.view" id="CRM_extra_phones_view">
        <field name="name">CRM_Extra_Phones</field>
        <field name="model">crm.lead</field>
        <field name="inherit_id" ref="crm.crm_case_form_view_leads"/>
        <field name="arch" type="xml">
                <xpath expr="//field[@name='phone']" position="replace">
                        <label for="phone" string="Phones"/>
                        <div>
                            <field name="phone"/>
                            <field name="phone2"/>
                            <field name="phone3"/>
                            <field name="phone4"/>
                            <field name="phone5"/>
                        </div>
                </xpath>
        </field>
    </record>
    <record model="ir.ui.view" id="partner_extra_phones_view">
        <field name="name">Partner_Extra_Phones</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base.view_partner_form"/>
        <field name="arch" type="xml">
                <xpath expr="//field[@name='phone']" position="replace">
            <label for="phone" string="Phones"/>
            <div>
                <field name="phone"/>
                <field name="phone2"/>
            </div>
                </xpath>
        </field>
    </record>
    </data>
</openerp>

 

 

Edit:

We still have the same problem after updating to the v8 format.

Updated to v8 Extra_Phones.py:

from openerp import models, fields

class crm_lead(models.Model):
    _inherit = 'crm.lead'

    phone2 = fields.Char(string='Phone2', help='')
    phone3 = fields.Char(string='Phone3', help='')
    phone4 = fields.Char(string='Phone4', help='')
    phone5 = fields.Char(string='Phone5', help='')


class res_partner(models.Model):
    _inherit = 'res.partner'

    phone2 = fields.Char(string='Phone2', help='')

 

Avatar
Discard
Author

Thank you, John, for your answer. We still have the same problem. Changing to the v8 format doesn't make a difference. Unless we are missing something somewhere. Module installs and works fine, but we're unable to cleanly uninstall when we inherit from 'cmr.lead'. And yes, we found out that it is easier/faster to clone the DB, and drop it, than to try and fix the tables when a module breaks Odoo.

Try changing this: class crm_lead(models.Model): to this: class crm_lead_extra_phones(models.Model): and this: class res_partner(models.Model): to this: class res_partner_extra_phones(models.Model): Naming it the same as crm.lead and res.partner overwrites these in the DB, the only way to uninstall would be to uninstall crm.lead and res.partner... This is my opinion but it is very similar to the problem that I had, that's why I showed "my_crm_lead" calls name below.

**class name, sorry.

Author

Thanks John. I'm pretty sure that we tried that before. But, just to be completely sure, we did so again. Not good. Same error message when uninstalling. Based on the little I have read about Odoo design, there is no need to change the class name for inheritance. If we remove the 'crm.lead' portion from our module (and keep 'res.partner' only), the module will install and uninstall properly. The problem seems to be inheriting from 'crm.lead'.

Author Best Answer

Fixed! And we hope this helps someone who might be having the same issue (and anyone writing their custom modules).

It seems that 'depends', in __openerp__.py, is not only important to install a module (and its dependency), but also to uninstall it. Even if, like us, you don't get errors when installing your module.

We were able to fix this issue simply by changing 'depends' in __openerp__.py from:

'depends': ['base'],

to:

'depends': ['base','crm'],

 

How? We copied some Python code, from one of the standard odoo modules, that was installing and uninstalling properly. But that code was not working in our module. So, that pointed to a problem "outside" the Python file, and that's when we realized that we didn't have 'crm' on the 'depends'.

Avatar
Discard

Hi. I tried this but sI till can't remove the module. I don't know what else to do. Any other suggestions?

I posted here about it

Best Answer

I had that issue when naming my addons the same too.

try this in the V8 API:

from openerp import models, fields, api

class my_crm_lead(models.Model):

    _inherit='crm.lead'

(any other code)

Avatar
Discard

oh by the way, I had to delete my DB and start a new one to fix it. :(