Odoo 树视图仅显示一条计算记录
Odoo tree view only show one record with compute
我试图在他的页面上显示用户签名的文档(来自 "Sign app"),所以我将其添加到继承模型中:
x_signatures_relation = fields.One2many("signature.request.item", "partner_id")
x_signatures = fields.One2many("signature.request", compute="_get_signed_documents")
@api.one
def _get_signed_documents(self):
ids = []
for signature in self.x_signatures_relation:
ids.append(signature.signature_request_id)
self.x_signatures = ids
"signature.request.item" 是 table 将合作伙伴(用户)与 "signature.request" 实际签名相关联。
然而,即使当前用户有两个签名,这个 return 也是一个空视图,但是如果我替换 :
self.x_signatures = ids
与 :
self.x_signatures = ids[0]
或:
self.x_signatures = ids[1]
显示记录了,这是怎么回事?
Odoo 有一套非常具体的规则,关于您如何 "allowed" 操作 One2many
和 Many2Many
字段。
另见 my recent answer, which gives a detailed explanation of all options and when/how to use them. The Odoo documentation also explains it。
在您的例子中,您是在计算方法中设置值,因此您想要完全替换任何现有值。
# Instead of
# self.x_signatures = ids
# Try this, which uses the special number 6 to mean
# "replace any existing ids with these ids"
self.x_signatures = [(6, 0, ids)]
此外,您可以简化计算方法:
@api.one
def _get_signed_documents(self):
self.x_signatures = [(6, 0, self.x_signatures_relation.ids)]
我试图在他的页面上显示用户签名的文档(来自 "Sign app"),所以我将其添加到继承模型中:
x_signatures_relation = fields.One2many("signature.request.item", "partner_id")
x_signatures = fields.One2many("signature.request", compute="_get_signed_documents")
@api.one
def _get_signed_documents(self):
ids = []
for signature in self.x_signatures_relation:
ids.append(signature.signature_request_id)
self.x_signatures = ids
"signature.request.item" 是 table 将合作伙伴(用户)与 "signature.request" 实际签名相关联。 然而,即使当前用户有两个签名,这个 return 也是一个空视图,但是如果我替换 :
self.x_signatures = ids
与 :
self.x_signatures = ids[0]
或:
self.x_signatures = ids[1]
显示记录了,这是怎么回事?
Odoo 有一套非常具体的规则,关于您如何 "allowed" 操作 One2many
和 Many2Many
字段。
另见 my recent answer, which gives a detailed explanation of all options and when/how to use them. The Odoo documentation also explains it。
在您的例子中,您是在计算方法中设置值,因此您想要完全替换任何现有值。
# Instead of
# self.x_signatures = ids
# Try this, which uses the special number 6 to mean
# "replace any existing ids with these ids"
self.x_signatures = [(6, 0, ids)]
此外,您可以简化计算方法:
@api.one
def _get_signed_documents(self):
self.x_signatures = [(6, 0, self.x_signatures_relation.ids)]