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

时间:2017-06-30 13:39:31

标签: odoo odoo-10

如果没有给出链接,我试图在按钮上设置属性'invisible'。但它给我一个错误:

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 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
        }

这里有什么问题?

1 个答案:

答案 0 :(得分:1)

您可能未在树视图中包含link字段。将<field name="link" invisible="1"/> 字段添加到树视图中并使其不可见。

{{1}}