Skip to Content
Menu
This question has been flagged

I need to relate a field which is on a One2many field of another model, so far I've tried like this:

    

    field_many = fields.Many2one('other.model', string="Many field")

    field_related = fields.Float(string="My field", related="field_many.one2manyfield.field"


But it throws me:

  • Traceback (most recent call last):

  •   File "werkzeug\serving.py", line 177, in run_wsgi

  •   File "werkzeug\serving.py", line 165, in execute

  •   File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\service\server.py", line 294, in app

  •     return self.app(e, s)

  •   File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\service\wsgi_server.py", line 216, in application

  •     return application_unproxied(environ, start_response)

  •   File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\service\wsgi_server.py", line 202, in application_unproxied

  •     result = handler(environ, start_response)

  •   File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\http.py", line 1299, in __call__

  •     return self.dispatch(environ, start_response)

  •   File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\http.py", line 1273, in __call__

  •     return self.app(environ, start_wrapped)

  •   File "werkzeug\wsgi.py", line 579, in __call__

  •   File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\http.py", line 1444, in dispatch

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

  •   File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\http.py", line 355, in registry

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

  •   File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\modules\registry.py", line 339, in get

  •     update_module)

  •   File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\modules\registry.py", line 370, in new

  •     openerp.modules.load_modules(registry._db, force_demo, status, update_module)

  •   File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\modules\loading.py", line 357, in load_modules

  •     registry.setup_models(cr)

  •   File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\modules\registry.py", line 194, in setup_models

  •     model._setup_fields(cr, SUPERUSER_ID)

  •   File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\api.py", line 268, in wrapper

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

  •   File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\api.py", line 372, in old_api

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

  •   File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\models.py", line 3010, in _setup_fields

  •     field.setup(self.env)

  •   File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\fields.py", line 468, in setup

  •     self._setup_related(env)

  •   File "C:\Program Files (x86)\Odoo 8.0-20170914\server\openerp\fields.py", line 514, in _setup_related

  •     field = recs._fields[name]

  • KeyError: 'one2manyfield'


Any ideas on how to achieve this?

Avatar
Discard
Best Answer

Related field example:


from openerp import models, fields

class MyModel(models.Model):
    _name = 'my.model'

    partner_id = fields.Many2one('res.partner', string='Partner')
    partner_credit_limit = fields.Float(string='Partner Credit Limit', related='partner_id.credit_limit')
Avatar
Discard
Related Posts Replies Views Activity
1
May 24
744
1
Apr 23
3490
6
Jun 18
4528
1
Nov 17
5881
1
Sep 17
3224