Skip to content
Advertisement

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

I have a tree where in the “jumlah” column there is a value of 0, so I want the rows that in the “jumlah” column have 0 not to be displayed in the tree. here’s a picture of the tree I have. kolom jumlah

and here is the xml view of the table above

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

edited: sorry I still don’t really understand, I have given the domain to ir.actions.window with a reference to the view that will be filtered, but the number 0 is still there

Advertisement

Answer

for this tree view, you will have an action window

model="ir.actions.act_window"

in that action add domain

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

But this will not let you see those records at all you will not have the option to see them or not see them as long as the view is called from this action. Use other method provided if you want to have the option to view or not depending on the filter

Advertisement