Search code examples
pythonodooodoo-8openerp-8

KeyError: 'crm' when installing custom module in Odoo 8


I am building a module for Odoo 8 to add extra fields into default CRM module Opportunities section, but I am getting the following error message:

Traceback (most recent call last):
  File "/opt/odoo/odoo-server/openerp/http.py", line 540, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/odoo/odoo-server/openerp/http.py", line 577, in dispatch
    result = self._call_function(**self.params)
  File "/opt/odoo/odoo-server/openerp/http.py", line 313, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/odoo/odoo-server/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/odoo-server/openerp/http.py", line 310, in checked_call
    return self.endpoint(*a, **kw)
  File "/opt/odoo/odoo-server/openerp/http.py", line 806, in __call__
    return self.method(*args, **kw)
  File "/opt/odoo/odoo-server/openerp/http.py", line 406, in response_wrap
    response = f(*args, **kw)
  File "/opt/odoo/odoo-server/addons/web/controllers/main.py", line 948, in call_button
    action = self._call_kw(model, method, args, {})
  File "/opt/odoo/odoo-server/addons/web/controllers/main.py", line 936, in _call_kw
    return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
  File "/opt/odoo/odoo-server/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/odoo-server/openerp/addons/base/module/module.py", line 447, in button_immediate_install
    return self._button_immediate_function(cr, uid, ids, self.button_install, context=context)
  File "/opt/odoo/odoo-server/openerp/api.py", line 268, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/odoo/odoo-server/openerp/addons/base/module/module.py", line 495, in _button_immediate_function
    registry = openerp.modules.registry.RegistryManager.new(cr.dbname, update_module=True)
  File "/opt/odoo/odoo-server/openerp/modules/registry.py", line 370, in new
    openerp.modules.load_modules(registry._db, force_demo, status, update_module)
  File "/opt/odoo/odoo-server/openerp/modules/loading.py", line 355, in load_modules
    loaded_modules, update_module)
  File "/opt/odoo/odoo-server/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 "/opt/odoo/odoo-server/openerp/modules/loading.py", line 152, in load_module_graph
    models = registry.load(cr, package)
  File "/opt/odoo/odoo-server/openerp/modules/registry.py", line 163, in load
    model = cls._build_model(self, cr)
  File "/opt/odoo/odoo-server/openerp/models.py", line 595, in _build_model
    original_module = pool[name]._original_module if name in parents else cls._module
  File "/opt/odoo/odoo-server/openerp/modules/registry.py", line 102, in __getitem__
    return self.models[model_name]
KeyError: 'crm'

It seems like a dependencies error, but I already added 'crm' into my openerp.py file. I also provide my module files information:

__init__.py

import cant_neg_crm

__openerp__.py

{
    'name': 'Cant Neg CRM',
    'version': '1.0',
    'category': 'Customer Relationship Management',
    'summary': 'Leads, Opportunities, Phone Calls',
    'description': """

Info
====================================================

Added :
-------------------------------
* Hosting
""",
    'author': 'Gigabee',
    'website': 'https://gigabee.es',
    'depends': ['base','crm',],
    'data': [
        'cant_neg_crm.xml',
    ],
    'installable': True,
    'application': True,
    'auto_install': False,
}

cant_neg_crm.py

import openerp
from openerp.osv import fields, osv, orm
from openerp import models


class tipo_facturacion(models.Model):
  _name = "tipo_facturacion"
  name = fields.char('Tipo', required=True)

class cant_neg_opp(models.Model):  
        _name = "crm"
        _inherit = "crm"
        _columns = {
        'tiene_dominio': fields.boolean('Tiene dominio(s)'),
        'su_dominio': fields.char('Dominio(s)'),

        'modo_facturacion': fields.many2one('tipo_facturacion' ,'Tipo Facturacion'),   
    }

cant_neg_crm.xml

<?xml version="1.0"?>
<openerp>
    <data>
        <record id="crm_cant_neg_view" model="ir.ui.view">
            <field name="name">res.partner.cant_neg_crm.inherit</field>
            <field name="model">res.partner</field>
            <field name="inherit_id" ref="crm.crm_case_form_view_oppor" />
            <field name="arch" type="xml">
            <xpath expr="//page[@string='Internal Notes']" position="after">
                <page string="Dominios y Hosting">
                    <group string="Dominios y Hosting del Cliente">
                        <field string="¿Tiene dominio?" name="tiene_dominio"/>
                        <field string="Dominio" name="su_dominio" attrs="{'invisible':[('tiene_dominio', '!=', True)], 'required':[('tiene_dominio', '=', True)]}" />
                     </group>             
          </xpath>
          </field>
    </record>
    </data>
</openerp>

Thank you very much in advance for your help!

Kind regards,


Solution

  • You get KeyError: 'crm' because you write _inherit='crm' which means it checks crm object in database but it's not found.

    You need to improve following points.

    1. There is no crm object. It's crm.lead object. Remove name attribute.

      class cant_neg_opp(models.Model):  
          _inherit = "crm.lead"
          _columns = {
              'tiene_dominio': fields.boolean('Tiene dominio(s)'),
              'su_dominio': fields.char('Dominio(s)'),
      
              'modo_facturacion': fields.many2one('tipo_facturacion' ,'Tipo Facturacion'),   
          }
      
    2. Change view model name from res.partner to crm.lead

      <?xml version="1.0"?>
      <openerp>
          <data>
              <record id="crm_cant_neg_view" model="ir.ui.view">
                  <field name="name">crm.lead.cant_neg_crm.inherit</field>
                  <field name="model">crm.lead</field>
                  <field name="inherit_id" ref="crm.crm_case_form_view_oppor" />
                  <field name="arch" type="xml">
                  <xpath expr="//page[@string='Internal Notes']" position="after">
                      <page string="Dominios y Hosting">
                          <group string="Dominios y Hosting del Cliente">
                              <field string="¿Tiene dominio?" name="tiene_dominio"/>
                              <field string="Dominio" name="su_dominio" attrs="{'invisible':[('tiene_dominio', '!=', True)], 'required':[('tiene_dominio', '=', True)]}" />
                           </group>             
                </xpath>
                </field>
          </record>
          </data>
      </openerp>
      

    For more details, you may learn from Odoo 8 Documentation