This question has been flagged
6 Replies
5657 Views

How to add a default filter in odoo12 Community Version

How to add the default filter with branch as CS selected defaultly in the filter...

My model for branch is:-

class StudentBranch(models.Model):
    _name = 'student.branch'
    _rec_name = 'branchname'
   
    branchname = fields.Char(string = 'BranchName')
    branchcode = fields.Integer(string = 'Branch Code')
    subname = fields.One2many('student.subject', 'branch_id',
        string = 'Subject Name',store=True)
And View of branch is:-

<!-- Tree View of branch -->
<record id="view_tree_studentbranch" model="ir.ui.view">
            <field name="name">Branch.tree</field>
            <field name="model">student.branch</field>
            <field name="arch" type="xml">
                <tree string="Branch Tree">
                    <field name="branchname"/>
                    <field name="branchcode"/>
                    <field name="subname"/>
                </tree>
            </field>
        </record><!-- Kanban View of Branch -->
<record id="studentbranch_kanban_view" model="ir.ui.view">
            <field name="name">StudentBranch Kanban</field>
            <field name="model">student.branch</field>
            <field name="arch" type="xml">
                <kanban>
                  
                    <templates>
                        <t t-name="kanban-box">
                            <div class="oe_kanban_global_click">
                                <div class="oe_kanban_details">
                                <ul>
                                    <li><field name="branchname"/></li>
                                    <li><field name="branchcode"/></li>
                                 </ul> 
                                </div>
                            </div>
                        </t>
                    </templates>
                </kanban>
            </field>
        </record>

<!--Branch Generic View -->
<record id="studentbranch_menu_action" model="ir.actions.act_window">
            <field name="name">Branch</field>
            <field name="res_model">student.branch</field>
            <field name="view_type">form</field>
            <field name="view_mode">kanban,tree,form</field>
            <field name="domain">[]</field>
            <field name="help" type="html">
                <p class="oe_view_nocontent_create">Create The First Branch
                </p>
            </field>
</record>

Please Help

Thanks in Advance..

Avatar
Discard

+1 to the reply from Cyrosys, this is a Google search away. Besides of this your questions are usually rather vague, please try to explain them more. Do you want to apply a default filter on a new search view? Do you want to filter on a field? Do you want to filter on a field with a specific value in the field?

Author

I want to filter on a field with a specific value in the field

Author

selected defaultly in the filter

Author

My question is very clear I have mentioned it above as

'How to add the default filter with branch as CS selected defaultly in the filter...'

Best Answer

Hi Aswathy,

you can do like this:

<!-- Search View of branch -->
<record id="view_search_studentbranch" model="ir.ui.view">
    <field name="name">Branch.tree</field>
    <field name="model">student.branch</field>
    <field name="arch" type="xml">
        <search string="Branch Search">
            <field name="branchname"/>
            <filter name="Branch" string="Branch" domain="[('branchname', 'ilike', 'CL')]"/>
        </search>
    </field>
</record>

<!--Branch Generic View -->
<record id="studentbranch_menu_action" model="ir.actions.act_window">
    <field name="name">Branch</field>
    <field name="res_model">student.branch</field>
    <field name="view_type">form</field>
    <field name="view_mode">kanban,tree,form</field>
    <field name="context">{'search_default_Branch': 1, 'default_Branch': 'CL'}</field>
    <field name="domain">[]</field>
    <field name="help" type="html">
        <p class="oe_view_nocontent_create">Create The First Branch
        </p>
    </field>
</record>


Try this, i will work.

Avatar
Discard
Author

Thank You:)