Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
42413 Lượt xem

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?

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks Sudhir!

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?

Tác giả

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

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

Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
8
thg 7 24
16325
2
thg 3 24
27900
2
thg 3 15
5717
3
thg 3 15
8754
0
thg 3 15
5843