【问题标题】:How to get the current id section in odoo 9?如何在 odoo 9 中获取当前的 id 部分?
【发布时间】:2016-10-03 09:12:24
【问题描述】:

当我点击一个列表的寄存器时,在 url 中会出现这样的内容:

http://myInstance:8069/web?&debug=#id=9&view_type=form&model=ext.test&action=544

我需要在python中捕获9(id的值),以便将其作为其他字段的默认值传递。

我不知道如何获取这个值。

我想要类似的东西:

@api.model
def default_get(self, vals):
    result = super(my_relation, self).default_get(vals)

    result['my_id'] = HERE_GOES_THE_VALUE_OF_THE_ID

    return result

我该怎么做?

【问题讨论】:

    标签: openerp odoo-9


    【解决方案1】:

    我找到了解决办法!

    我意识到“当前 id 部分”是“active_id”变量。 但是,如果我尝试在 python 代码中访问此变量,则值为 'None'。

    为了解决这个问题,我通过“上下文”发送了变量。在xml文件中:

    <field name="my_field_name" context="{'my_id': active_id}"/>
    

    然后,在 python 文件中,我可以这样做访问上下文:

    result['my_id'] = self._context['my_id']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多