【问题标题】:odoo 8 selection field self always emptyodoo 8 选择字段自身始终为空
【发布时间】:2016-10-18 03:55:31
【问题描述】:

我必须根据其他列创建一个选择字段。我的意思是数据来自其他表,但基于当前表列值。所以我创建了一个选择字段如下:

pull_location = fields.Selection(selection='_get_pull_locations',string='Pull Location')

功能如下:

@api.multi
def _get_pull_locations(self):
    data=[]
    ** Get the values from other table based on current record ** 
    return [('value1', 'String 1'), ('value2', 'String 2')]

当我调试时,我总是将 self 作为空类对象 (stock.test())。场景是我在 stock.test 中有一个名为 zone 的列,我有另一个名为 stock.location 的表,因此对于当前记录,我检查 stock.location 表,其中列 pull_zone == stock.test 的区域,如果是,则附加选择(pull_location) 具有该值。 但对象总是空的。 我尝试了@api.one、@api.multi、@api.model,没有任何反应。

请帮忙。 谢谢,

【问题讨论】:

标签: openerp odoo-8


【解决方案1】:

用以下代码替换您的代码:

@api.multi
def _get_pull_locations(self):
    ** Get the values from other table based on current record ** 
    return [
        ('value1', 'String 1'), 
        ('value2', 'String 2')
    ]

pull_location = fields.Selection('_get_pull_locations', string='Pull Location')

之后,重启 Odoo 服务器并升级你的模块。

【讨论】:

  • 嗨 odedra,self 对象仍然是空的。我想在 self 对象中获取记录
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-07-18
  • 2020-06-04
  • 2016-03-27
  • 1970-01-01
  • 2015-07-24
  • 2020-07-19
  • 1970-01-01
相关资源
最近更新 更多