我在合作伙伴模型上有一个自定义字段,该字段将获取有关当前合作伙伴的所有签名记录(来自Sign应用程序),这是我的代码:
# Signatures
x_signatures_relation = fields.One2many("signature.request.item", "partner_id")
x_signatures = fields.One2many("signature.request", compute="_get_signed_documents")
@api.multi
def _get_signed_documents(self):
for record in self:
record.x_signatures = [(6, 0, record.x_signatures_relation.ids)]
这在xml部分:
<page string="Signatures" name="signatures">
<tree>
<field name="x_signatures" />
</tree>
</page>
该代码可以在本地计算机上正常运行,但是一旦我将其通过Github推送到odoo.sh,当我访问至少具有一个签名的合作伙伴时,我会收到此错误(对于没有签名的合作伙伴,不会发生此错误):
Error:
TypeError: val is undefined
https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/3826-7bbc86b/web.assets_backend.js:1264
Traceback:
_parseServerData/<@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/3826-7bbc86b/web.assets_backend.js:1264:545
_.forEach@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:12:558
_parseServerData@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/3826-7bbc86b/web.assets_backend.js:1264:288
_readMissingFields/</<@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/3826-7bbc86b/web.assets_backend.js:1275:445
_.forEach@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:12:558
_readMissingFields/<@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/3826-7bbc86b/web.assets_backend.js:1275:35
then/</</<@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:802:678
fire@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:796:281
fireWith@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:801:198
Deferred/</deferred[tuple[0]]@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:803:56
rpc/</<@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:3869:346
then/</</<@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:802:678
fire@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:796:281
fireWith@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:801:198
Deferred/</deferred[tuple[0]]@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:803:56
fire@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:796:281
fireWith@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:801:198
then/</</<@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:802:874
fire@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:796:281
fireWith@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:801:198
then/</</<@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:802:874
fire@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:796:281
fireWith@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:801:198
done@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:1192:86
callback@https://keydigital-tb-import-test-258937.dev.odoo.com/web/content/1751-3ead7e4/web.assets_common.js:1212:15
如果我删除了xml部分,它将正确显示伙伴,否则我将无法找到问题出在哪里,因为堆栈跟踪并没有真正的帮助,有什么主意吗?
答案 0 :(得分:1)
我认为这就足够了
<page string="Signatures" name="signatures">
<field name="x_signatures">
<tree>
<field name='your_filed_name'/>
<field name='your_filed_name_2'/>
</tree>
</field>
</page>
答案 1 :(得分:1)
The answer of sfx应该足够了,但我想分享更多有关您的错误的信息。
<page string="Signatures" name="signatures">
<tree>
<field name="x_signatures" />
</tree>
</page>
(我猜)您想让Odoo将签名显示为列表视图。这没有必要,因为另一个答案已经告诉了您。但是这里真正的错误是在字段上方使用<tree>
层次结构,应将其显示为列表子视图。
您必须在要显示为子视图的字段中使用<tree>
(或<kanban>
)。然后仅仅定义一个空的子视图还不够,只需要定义一个带有字段,标签等的子视图:
<page string="Signatures" name="signatures">
<field name="x_signatures">
<tree>
<field name="field_1" />
<field name="field_2" />
<field name="field_n" />
</tree>
</field>
</page>
答案 2 :(得分:0)
我通过如下编辑Python代码解决了它:
@api.depends('x_signatures_relation')
@api.multi
def _get_signed_documents(self):
for record in self:
ids = []
for signature in record.x_signatures_relation:
ids.append(signature.signature_request_id.id)
record.x_signatures = [(6, 0, ids)]
我仍然不知道为什么第一段代码无法在odoo.sh上运行并且在我的本地计算机上完美运行。