Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to add fields to the search field suggestions?

By
Hannes Smit
on 4/3/13, 5:02 AM 12,263 views

When searching for customer invoices on the webclient (openerp 7), some partners appear in the search field after typing the first search keyword characters. I think this is a very useful feature!

In the python defintion of partner_id on account.invoice doesn't seem to be a special indication of this behaviour. Where is this behaviour added? How can I add such suggestions to my model definition? and, under which feature is this documented?

7
Hannes Smit
On 4/3/13, 5:19 AM

Found some XML code in the mean-time:

<record id="view_account_invoice_filter" model="ir.ui.view">
    <field name="name">account.invoice.select</field>
    <field name="model">account.invoice</field>
    <field name="arch" type="xml">
        <search string="Search Invoice">
            <field name="number"
                string="Invoice"
                filter_domain="['|','|','|', ('number','ilike',self), ('origin','ilike',self), ('supplier_invoice_number', 'ilike', self), ('partner_id', 'ilike', self)]"/>
            <filter name="draft"
                string="Draft"
                domain="[('state','=','draft')]" help="Draft Invoices"/>
            <filter name="proforma"
                string="Proforma"
                domain="[('state','=','proforma2')]" help="Proforma Invoices"
                groups="account.group_proforma_invoices"/>
            <filter name="invoices" string="Invoices"
                domain="[('state','not in',['draft','cancel'])]"
                help="Proforma/Open/Paid Invoices"/>
            <filter name="unpaid" string="Unpaid"
                domain="[('state','=','open')]"
                help="Unpaid Invoices"/>
            <separator/>
            <filter domain="[('user_id','=',uid)]" help="My Invoices" icon="terp-personal"/>
            <field name="partner_id"/>
            <field name="user_id" string="Salesperson"/>
            <field name="period_id" string="Period"/>
            <group expand="0" string="Group By...">
                <filter string="Partner" icon="terp-partner" domain="[]" 
                    context="{'group_by':'partner_id'}"/>
                <filter string="Responsible" icon="terp-personal" domain="[]"
                    context="{'group_by':'user_id'}"/>
                <filter string="Journal" icon="terp-folder-orange" domain="[]"
                    context="{'group_by':'journal_id'}"/>
                <filter string="Status" icon="terp-stock_effects-object-colorize"
                    domain="[]"  context="{'group_by':'state'}"/>
                <filter string="Period" icon="terp-go-month" domain="[]"
                    context="{'group_by':'period_id'}"/>
                <filter string="Invoice Date" icon="terp-go-month" domain="[]"
                     context="{'group_by':'date_invoice'}"/>
                <filter string="Due Date" icon="terp-go-month" domain="[]"
                     context="{'group_by':'date_due'}"/>
            </group>
       </search>
    </field>
</record>

And then, the documentation About Search View (doc.openerp.com/trunk/developers/server/03_module_dev_03/#search-views)

EDIT: The answer is in fact:

The question is about search-fields. With view (ir.ui.view) records you can specify <search> views. Every field that is added to a search-view will show up in the suggestions while typing in the search keyword.

<record id="view_account_invoice_filter" model="ir.ui.view">
    <field name="name">account.invoice.select</field>
    <field name="model">account.invoice</field>
    <field name="arch" type="xml">
        <search string="Search Invoice">
            <field name="partner_id"/>
            <field name="user_id" string="Salesperson"/>
       </search>
    </field>
</record>

A more advanced variant is the following:

<record id="view_account_invoice_filter" model="ir.ui.view">
    <field name="name">account.invoice.select</field>
    <field name="model">account.invoice</field>
    <field name="arch" type="xml">
        <search string="Search Invoice">
            <field name="number" string="Invoice"
                filter_domain="['|','|','|', ('number','ilike',self), ('origin','ilike',self), ('supplier_invoice_number', 'ilike', self), ('partner_id', 'ilike', self)]"/>
       </search>
    </field>
</record>

Here 'Invoice' suggestions appear when the search term is matched against either number, origin, supplier_invoice_number or partner_id. However, it is not yet clear to me why the field has name="number".. It seems you can add the same domain to name="partner_id". This is not explained in the given documentation link.

There is one more feature, I found in stock picking:

    <record id="view_move_search" model="ir.ui.view">
        <field name="name">stock.move.search</field>
        <field name="model">stock.move</field>
        <field eval="3" name="priority"/>
        <field name="arch" type="xml">
            <search string="Stock Moves">
                  <field name="partner_id" string="Partner"
                      filter_domain="[('picking_id.partner_id','ilike',self)]"/>
            </search>
        </field>
    </record>

Here, it seems you can also search through relations.

Thanks Sudhir!

Hannes Smit
on 4/3/13, 5:35 AM

Thanks Hannes! Indeed just adding a field in xml search view add a selection field to narrow the searched fields for the entered item. Have you look at the possibility to do that on a x2many field?

Gabriel
on 7/12/13, 1:59 PM

@Gabriel: No, I haven't. You?

Hannes Smit
on 7/18/13, 5:02 AM

I wanna add the possibility to search for phone number at quick search. Where can I edit this XML ?

Trung
on 8/21/13, 8:54 AM
0
mrpingu
On 2/9/15, 11:25 PM

How to add function "auto-complete" in top-right search box? 

EDIT: 

To answer why there is "name" in the <search>: The field "name" specify which field shown in the suggestion result.

I Found it myself, in Odoo 8, there is arrow-head shaped button that when clicked it expands the suggestion list. Thank you.

mrpingu
on 2/9/15, 11:31 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 4/3/13, 5:02 AM
Seen: 12263 times
Last updated: 3/16/15, 8:10 AM