获取当前记录ID

时间:2018-08-08 15:55:53

标签: python xml odoo

我正在研究供应商表单视图(合作伙伴模型)。  我尝试通过以下代码获取当前记录的ID:

current_id=fields.Integer(compute='get_current_id')
@api.multi
def get_current_id(self):
    print self.id
    self.current_id=self.id

使用此代码,我遇到错误:“ ValueError:预期单例:res.partner(1,50)”这很奇怪,因为50是我当前的记录ID,但我不知道为什么它也得到ID 1 。当我在pgAdmin中寻找它时,我发现1是“ company_id”。为什么当前记录(视图表单)有两个ID? 谢谢。

1 个答案:

答案 0 :(得分:2)

您正在使用@api.multi,因此self可以是多个记录。

您可以尝试:

@api.multi
def get_current_id(self):
    for instance in self:
        instance.current_id = instance.id

或者:

@api.one
def get_current_id(self):
    self.current_id = self.id
相关问题