在OpenERP的树形视图中有选择地显示或隐藏按钮 [英] Selectively display or hide button in the tree view in OpenERP

查看:95
本文介绍了在OpenERP的树形视图中有选择地显示或隐藏按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将按钮(图标为绿色箭头)放置在树状视图中.我只想在记录具有物料清单(BOM)时显示一个按钮.我确实知道如何找出答案,但不知道如何有选择地显示或隐藏按钮.

I have placed the buttons (icon is green arrow) in the treeview. I want to show a button only if the record has a Bill of Material (BOM). I do have logic how to find out that, but don't know how to selectively display or hide a button.

此外,在加载视图时,应该触发显示或隐藏按钮动作.由于没有像Visual Basic这样的view_on_load事件,我该怎么办?

Also, the display or hide button action should be triggered when the view is loaded. How I can do that since there is no view_on_load event like in Visual Basic for instance?

这是树状视图:

以下是在XML文件中定义按钮的方式:

Here is how the buttons are defined in XML file:

<!-- mrp_bom -->
        <record id="adamson_mrp_bom_form_view" model="ir.ui.view">
            <field name="name">adamson.mrp.bom.form.view</field>
            <field name="model">mrp.bom</field>
            <field name="type">form</field>
            <field name="inherit_id" ref="mrp.mrp_bom_form_view" />
            <field name="arch" type="xml">
                <xpath expr="//notebook/page[@string='Components']/field/tree[@string='Components']/field[@name='sequence']" position="before" >
                     <button class="oe_inline oe_stat_button" type="object" string="Go!" icon="gtk-go-forward" name="action_go"  />

                </xpath>

这是查找特定产品的BOM的逻辑.注意bom_ids列表很可能只有一个值.此逻辑用于按钮动作,但可以用于决定是否显示按钮.

Here is the logic how to find if there is a BOM or not for particular product. Note bom_ids list which most likely will have only one value. This logic is used for button action but it can be used for deciding to show button or not.

class mrp_bom_line(osv.osv):
    _inherit = 'mrp.bom.line'

    def action_go(self, cr, uid, ids, context=None):
        bom_obj = self.pool.get('mrp.bom')

        for bom_line in self.browse(cr, uid, ids, context=context):
            if bom_line.product_id.default_code > '300':
                bom_ids = bom_obj.search(cr, uid, [('product_id', '=', bom_line.product_id.id)], context=context)
                if bom_ids:

推荐答案

例如,您可以使用attrs

You may use attrs for example

attrs="{'invisible':[('selection_field_name','=','value')]}"

注意:我们需要提供存储在数据库中的值.

Note: we need to give value which is store in database.

尝试一下

<xpath expr="//notebook/page[@string='Components']/field/tree[@string='Components']/field[@name='sequence']" position="before" >
    <button class="oe_inline oe_stat_button" type="object" string="Go!" icon="gtk-go-forward" name="action_go" attrs="{'invisible':[('type','=','normal')]}"  />
</xpath>

这篇关于在OpenERP的树形视图中有选择地显示或隐藏按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆