无法在 Odoo10 中使用 url 小部件在按钮上设置不可见 属性

Cannot set invisible property on button with url widget in Odoo10

如果未提供 link,我将尝试在按钮上设置属性 'invisible'。但它 returns 我出错了:

Uncaught Error: Unknown field link in domain [["link","=",false]]

我想,问题是因为我试图引用的字段有小部件 "url"。

设置字段'link'的表单视图。

<record id="documents_form" model="ir.ui.view">
    <field name="model">documents.example</field>
    ...
        <field name="link" widget="url" placeholder="e.g. www.example.com"/>
    ...
</record>

它发生的树视图:

<record id="documents_tree" model="ir.ui.view">
    <field name="model">documents.example</field>
    <field name="arch" type="xml">
        <tree string="Documents">
            ...
            <button name="open_link" type="object" attrs="{'invisible': [('link', '=', False)]}"/>
            ...
        </tree>
    </field>
</record>

class本身:

class Documents(models.Model):
    ...
    _name = 'documents.example'
    link = fields.Char("Link")
    ...

    def open_link(self):
        return {
            'name':         'Go to website',
            'res_model':    'ir.actions.act_url',
            'type':         'ir.actions.act_url',
            'target':       'new',
            'url':          self.link
        }

这里有什么问题?

您可能没有在树视图中包含 link 字段。将 link 字段添加到树视图并使其不可见。

<field name="link" invisible="1"/>