Reputation: 131
There is an odoo system with a timesheet module (self-made) in it. I need to add some view filters in my xml file in the views section. I've made default one and it works:
<!-- tabel search view 1 -->
<record id="view_tabel_search1" model="ir.ui.view">
<field name="name">tabel.tabel.search1</field>
<field name="model">tabel.tabel</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Checker">
<filter
string="Last and following months"
name="filter1"
domain="[('write_date', '>=' ,(context_today()-relativedelta(months=2)+relativedelta(days=20)).strftime('%d-%m-%Y') )]"
help = "Press ALL to get all timesheets"/>
<field name="time_start_t" select="True"/>
<field name="id_ank" select="True"/>
</search>
</field>
</record>
But next one (which is pretty same) isn't displayed:
<!--tabel search view 2 -->
<record id="view_tabel_search2" model="ir.ui.view">
<field name="name">tabel.tabel.search2</field>
<field name="model">tabel.tabel</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Checker">
<filter
string="Current and following months"
name="filter2"
domain="[('time_end_t', '>=' ,(context_today()).strftime('%d-%m-%Y'))]"
help = "Press all to get all timesheets"/>
<field name="time_start_t" select="True"/>
<field name="id_ank" select="True"/>
</search>
</field>
</record>
So, the first one is displayed and works, the second one is not. The only difference between them (except the filter rule) is that filter1 is the default one, as stated at the actions section:
<record model="ir.actions.act_window" id="tabel_list_draft_action">
<field name="name">Tableman's sign</field>
<field name="res_model">tabel.tabel</field>
<field name="view_type">form</field>
<field name="domain">[('state','=', 'draft')]</field>
<field name="view_mode">tree,form,graph</field>
<field name="search_view_id" ref="view_tabel_search2"/>
<field name="context">{'search_default_filter1':1,'state':'draft'}</field>
</record>
Probably, I have to describe non-default filters as well, but I never saw any examples of how I can do that. So any advice is highly appreciated.
Upvotes: 1
Views: 2795
Reputation: 2314
Customizing Search Views in Odoo v8
What are search views in Odoo?
Whenever you are on a tree view, kanban view, or other view that can be searched Odoo uses an XML Search View definition to determine exactly how the search in Odoo should function for that specific model. For example, in the Sales Order tree view there are specfic options that will help you in locating a sales order in Odoo.
Here we can see how you have options to search by customer, salesperson, sales team, contract, or product. You can also see as we have expanded the search options that we have filters to restrict sales orders to only my sales orders, quotations, sales, To Invoice, Done, and New Mail. The Group By options that are available are also defined in the search view as well.
Do I have to know how to develop modules to customize search views?
This depends on exactly what you wish to do with your search views. Fortunately it is very easy to add extra fields you may wish to search for or remove options that are not appropriate for your specific business requirements. If however you wish to create specialized searches that are more complex it is possible you may need to write custom python code to meet your objects. Most often however you can accomplish most tasks by modifying the search views without the necessity of creating a module.
What is the basic format of a search view in Odoo?
Search views are stored in XML and are quite readable for someone with basic knoweldge of XML. Below is the basic search view:
<?xml version="1.0"?>
<search string="Search Sales Order">
<field name="name" string="Sales Order" filter_domain="['|',('name','ilike',self),('client_order_ref','ilike',self)]"/>
<field name="partner_id" operator="child_of"/>
<field name="user_id"/>
<field name="section_id" string="Sales Team" groups="base.group_multi_salesteams"/>
<field name="project_id"/>
<field name="product_id"/>
<filter string="My" domain="[('user_id','=',uid)]" name="my_sale_orders_filter"/>
<separator/>
<filter string="Quotations" name="draft" domain="[('state','in',('draft','sent'))]" help="Sales Order that haven't yet been confirmed"/>
<filter string="Sales" name="sales" domain="[('state','in',('manual','progress'))]"/>
<filter string="To Invoice" domain="[('state','=','manual')]" help="Sales Order ready to be invoiced"/>
<filter string="Done" domain="[('state','=','done')]" help="Sales Order done"/>
<separator/>
<filter string="New Mail" name="message_unread" domain="[('message_unread','=',True)]"/>
<group expand="0" string="Group By">
<filter string="Salesperson" domain="[]" context="{'group_by':'user_id'}"/>
<filter string="Customer" domain="[]" context="{'group_by':'partner_id'}"/>
<filter string="Order Month" domain="[]" context="{'group_by':'date_order'}"/>
</group>
</search>
Each element tells the Odoo engine exactly what options are available in the search.
Why would I want to modify the search views in Odoo?
As the number of records grow within your system, your users will spend more and more time finding the records they need to complete a given task. When you only have a few dozens sales orders in the system then locating data is not a problem. But as the data grows having search functions that make it easy for users to find records becomes more critical. Perhaps more than any other customization option within Odoo, the abiltity to customize search views has perhaps the greatest potential to improve user satisfaction and safe time in using the system.
Upvotes: 4