Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

KeyError: 'partner_id' when trying to inherit by delegation from res.partner

By
Nehemias Herrera
on 2/21/15, 7:32 PM 2,206 views

I am unsuccesfully trying to inherit by delegation from model res.parter the same way res.user does as it can be seen in https://github.com/odoo/odoo/blob/8.0/openerp/addons/base/res/res_users.py#L143-L145 , I am getting the following error from the following sample model

My model:

# -*- coding: utf-8 -*-
from openerp import fields
from openerp import models

class Example (models.Model):
    _name = 'example.prueba'
    _inherits = {
        'res.partner': 'partner_id',
    }

    sample_field = fields.Char(string="Field")

The error:

Traceback (most recent call last):

  File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 177, in run_wsgi

    execute(self.server.app)

  File "/usr/lib/python2.7/dist-packages/werkzeug/serving.py", line 165, in execute

    application_iter = app(environ, start_response)

  File "/usr/lib/python2.7/dist-packages/openerp/service/server.py", line 281, in app

    return self.app(e, s)

  File "/usr/lib/python2.7/dist-packages/openerp/service/wsgi_server.py", line 216, in application

    return application_unproxied(environ, start_response)

  File "/usr/lib/python2.7/dist-packages/openerp/service/wsgi_server.py", line 202, in application_unproxied

    result = handler(environ, start_response)

  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1239, in __call__

    return self.dispatch(environ, start_response)

  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1213, in __call__

    return self.app(environ, start_wrapped)

  File "/usr/lib/python2.7/dist-packages/werkzeug/wsgi.py", line 588, in __call__

    return self.app(environ, start_response)

  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1371, in dispatch

    ir_http = request.registry['ir.http']

  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 331, in registry

    return openerp.modules.registry.RegistryManager.get(self.db) if self.db else None

  File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 315, in get

    update_module)

  File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 346, 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 365, in load_modules

    registry.setup_models(cr)

  File "/usr/lib/python2.7/dist-packages/openerp/modules/registry.py", line 174, in setup_models

    model._setup_fields(cr, SUPERUSER_ID, partial=partial)

  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 237, in wrapper

    return old_api(self, *args, **kwargs)

  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 332, in old_api

    result = method(recs, *args, **kwargs)

  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 2971, in _setup_fields

    field.setup(self.env)

  File "/usr/lib/python2.7/dist-packages/openerp/fields.py", line 411, in setup

    self._setup(env)

  File "/usr/lib/python2.7/dist-packages/openerp/fields.py", line 417, in _setup

    self._setup_related(env)

  File "/usr/lib/python2.7/dist-packages/openerp/fields.py", line 449, in _setup_related

    field = recs._fields[name]

KeyError: 'partner_id'

any help would be appreciated, thanks.

 

2

Cyril Gaspard (GEM)

--Cyril Gaspard (GEM)--
4136
| 5 6 8
Paris, France
--Cyril Gaspard (GEM)--

Forum contributor since 2008

Cyril Gaspard (GEM)
On 2/21/15, 10:14 PM

Hi,

you must had field partner_id in your code, like it is made in class res users.

Bye

2

Atchuthan - Technical Consultant, Sodexis Inc

--Atchuthan - Technical Consultant, Sodexis Inc--
3918
| 5 3 8
Puducherry, India
--Atchuthan - Technical Consultant, Sodexis Inc--
Passionate coder in Python/Odoo(formerly known as OpenERP).

Contact me via GMail: atchuthantu@gmail.com via Skype: atchuthan_skype
via Linkedin: http://in.linkedin.com/in/atchuthantu
Atchuthan - Technical Consultant, Sodexis Inc
On 2/23/15, 2:09 AM


In inherits delegation, you define a dictinary that implies the object and the column name in current table.

from openerp import fields
from openerp import models

class Example (models.Model):
    _name = 'example.prueba'
    _inherits = {
        'res.partner': 'partner_id',
    }

    sample_field = fields.Char(string="Field")
    partner_id = fields.Many2one('res.partner',
ondelete='cascade',required=True)
# Need to define the key defined at _inherits

 

Hi, no need to repeat the same answer I done one day before you this is the second time, see : https://www.odoo.com/forum/help-1/question/xpath-for-order-line-field-in-sale-order-view-75925#answer-75933 . thanks

Cyril Gaspard (GEM)
on 2/23/15, 6:29 PM

Your answer was pointed correctly but no sufficient explanation was available with it. So, i added an answer that is easier for Odoo forum newbies.

Atchuthan - Technical Consultant, Sodexis Inc
on 2/24/15, 12:02 AM

Check the datetime stamp of xpath question that have 2 answers: Mine(2/10/15, 3:58 PM) and Ivan(2/10/15, 4:06 PM). I think we both added an answer simultaneously.

Atchuthan - Technical Consultant, Sodexis Inc
on 2/24/15, 12:15 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/21/15, 7:32 PM
Seen: 2206 times
Last updated: 3/16/15, 8:10 AM