如果字段为 0,如何删除或隐藏 odoo 树中的行

how to remove or hide rows in odoo tree if field is 0

我有一棵树,其中“jumlah”列中的值为 0,因此我希望“jumlah”列中的值为 0 的行不显示在树中。这是我的树的照片。

这是上面 table 的 xml 视图

   <?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="product_product_tree_view2" model="ir.ui.view">
        <field name="name">product.product.tree</field>
        <field name="model">product.product</field>
        <field name="arch" type="xml">
            <tree string="Kartu Stok" create="false">
                <field name="name" string="Type"/>
                <field name="product_merk" string="Merk"/>
                <field name="master_type_id" string="Jenis"/>
            </tree>
        </field>
    </record>

    <record id="stock_move_gg_tree" model="ir.ui.view">
        <field name="name">stock.move.gg.tree</field>
        <field name="model">stock.move.gg</field>
        <field name="arch" type="xml">
            <tree string="Kartu Stok" create="false" default_order="dt_real desc">
                <field name="name"/>
                <field name="location_id"/>
                <field name="dt_real"/>
                <field name="origin"/>
                <field name="inv_id"/>
                <field name="person"/>
                <field name="qty_char"/>
                <field name="start_stock"/>
                <field name="end_stock"/>
            </tree>
        </field>
    </record>

    <record id="stock_ordered_gg_tree" model="ir.ui.view">
        <field name="name">stock.ordered.gg.tree</field>
        <field name="model">stock.move</field>
        <field name="arch" type="xml">
            <tree string="Terpesan" create="false" default_order="date desc">
                <field name="picking_id" string="DO"/>
                <field name="origin"/>
                <field name="inv_validate" string="Faktur"/>
                <field name="location_id"/>
                <field name="date"/>
                <field name="responsible_person"/>
                <field name="product_qty" string="Jumlah"/>
                <field name="state"/>
            </tree>
        </field>
    </record>

    <record id="stock_ordered_gg_form" model="ir.ui.view">
        <field name="name">stock.ordered.gg.form</field>
        <field name="model">stock.move</field>
        <field name="arch" type="xml">
            <form string="Detail Stock" create="false" edit="false" delete="false">
                <sheet>
                    <div class="oe_title">
                        <h1>
                            <field name="product_id" readonly="1"/>
                        </h1>
                    </div>
                    <group>
                        <field name="picking_id" string="DO"/>
                        <field name="origin"/>
                        <field name="inv_validate" string="Faktur"/>
                        <field name="location_id"/>
                        <field name="date"/>
                        <field name="responsible_person"/>
                        <field name="product_qty" string="Jumlah"/>
                        <field name="state"/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>


    <record id="product_normal_form_view2" model="ir.ui.view">
        <field name="name">product.product.form</field>
        <field name="model">product.product</field>
        <field name="arch" type="xml">
            <form string="Kartu Stok" create="false" edit="false">
                <sheet>
                    <div class="oe_button_box" name="button_box">
                        <button name="open_stock_move_gg" type="object" class="oe_stat_button"
                                icon="fa-pencil-square-o">
                            <field name="count_stock_move_gg" string="Histori" widget="statinfo"/>
                        </button>
                    </div>
                    <group>
                        <field name="name" string="Type"/>
                        <field name="product_merk" string="Merk"/>
                        <field name="master_type_id" string="Jenis"/>
                    </group>
                    <notebook>
                        <page string="Histori Transaksi">
                            <field name="sm_id" string="Detail">
                                <tree default_order="dt_real desc" >
                                    <field name="name"/>
                                    <field name="location_id" />
                                    <field name="dt_real" />
                                    <field name="origin" />
                                    <field name="inv_id" />
                                    <field name="person"/>
                                    <field name="qty_char" />
                                    <field name="start_stock" />
                                    <field name="end_stock"/>
                                </tree>
                                <form>
                                    <sheet>
                                        <group>
                                            <group>
                                                <field name="name"/>
                                                <field name="location_id"/>
                                                <field name="dt_real"/>
                                                <field name="origin"/>
                                                <field name="inv_id"/>
                                                <field name="person"/>
                                                <field name="sp_id" string="ID Ref"
                                                       attrs="{'invisible': [('sp_id', '=', False)]}"/>
                                                <field name="si_id" string="ID Ref"
                                                       attrs="{'invisible': [('si_id', '=', False)]}"/>
                                            </group>
                                            <group>
                                                <field name="qty_char"/>
                                                <field name="start_stock"/>
                                                <field name="end_stock"/>
                                            </group>
                                        </group>
                                    </sheet>
                                </form>
                            </field>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>


    <record id="action_stock_card" model="ir.actions.act_window">
        <field name="name">Kartu Stok</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">product.product</field>
        <field name="view_mode">tree,form</field>
        <field name="view_type">form</field>
        <field name="domain">['|',('qty_char','!=','0'),('qty_char','!=','+0.0')]</field>
        <field name="context">{"search_default_consumable":1}</field>
        <field name="search_view_id" ref="stock.product_template_search_form_view_stock"/>
        <field name="help" type="html">
            <p class="oe_view_nocontent_create">
                <!-- Add Text Here -->
            </p>
            <p>
                <!-- More details about what a user can do with this object will be OK -->
            </p>
        </field>
    </record>
    <record id="action_stock_card_tree" model="ir.actions.act_window.view">
        <field name="view_mode">tree</field>
        <field name="view_id" ref="product_product_tree_view2"/>
        <field name="act_window_id" ref="action_stock_card"/>
    </record>
    <record id="action_stock_card_form" model="ir.actions.act_window.view">
        <field name="view_mode">form</field>
        <field name="view_id" ref="product_normal_form_view2"/>
        <field name="act_window_id" ref="action_stock_card"/>
        <field name="domain">['|',('qty_char','!=','0'),('qty_char','!=','+0.0')]</field>
    </record>
    <menuitem id="stock_card" name="Kartu Stok" parent="stock.menu_warehouse_report"
              action="action_stock_card" sequence="116"/>


</odoo>

已编辑:对不起,我还是不太明白,我已经将域名给了 ir.actions.window 并引用了将被过滤的视图,但数字 0 仍然存在

您可以为树视图创建自定义过滤器。

<filter string="Jumlah not zero" name="jumlah_filter" domain="[('qty_char','!=','0')]"/>

之后,您可以自定义导致此树视图的操作 window 始终将过滤器设置为默认值。

<field name="context">{'search_default_jumlah_filter': 1}</field>

对于此树视图,您将有一个操作 window

model="ir.actions.act_window"

在该操作中添加域

<record model="ir.actions.act_window" id="action_stock_move_gg">
            <field name="name">Name</field>
            <field name="res_model">stock.move.gg</field>
            <field name="view_mode">tree,form</field>
            <field name="domain">[('qty_char','!=','0')]</field> 
</record>

但这根本不会让您看到这些记录,只要从此操作调用视图,您就无法选择查看或不查看它们。 如果您想根据过滤器选择是否查看,请使用提供的其他方法