关联 One2many 字段,在一个已经关联的字段上 - Odoo v8

Relate One2many field, on an already related one - Odoo v8

我需要关联一个位于另一个模型的 One2many 字段上的字段,到目前为止我试过这样:

field_many = fields.Many2one('other.model', string="Many field")
field_related = fields.Float(string="My field", related="field_many.one2manyfield.field")

但它让我震惊:

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'

关于如何实现这一点有什么想法吗?

但是您正在创建 one2many 字段中的相关字段?!!不要忘记 o2m 可以有多个记录,因此 odoo 在尝试 get 时会感到困惑 value .

 o2m_field.some_field  # witch record to access [like singleton error]

但错误显示 odoo 在 other.model 中找不到名为 one2manyfield 的字段是否也是相关字段。

如果是这样,我认为 odoo 找不到它,因为默认情况下相关字段未存储在数据库中。但是存储 one2many 字段的相关字段不仅仅是添加 store=True 我没有尝试过,但我们知道 o2many 字段在其他模型中应该有一个 many2one。

所以最好通过示例来解释你想要什么,我认为你需要使用计算域的力量。