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

Odoo 9.0 - Dynamic Custom Search Filter

By
Dared
on 10/4/16, 6:19 AM 347 views

Hi guys,

I have to create a dynamic custom search filter in order to filter results based on criterion set to the domain. The value set on criterion has to be dynamic and recovered by context.

In particular, I have a many2many field in wizard and when I insert a value, Odoo opens another wizard where it is possible search/filter/group by and select elements to add in field.


Many2many field is defined as follows:

<field name="pricelist_item_ids" context="{'search_default_pricelist': 1, 'pricelist_id_id': 12}">


My custom filter is defined as follows:

<record model="ir.ui.view" id="view_filter1">

            <field name="model">model</field>

            <field name="type">search</field>

            <field name="arch" type="xml">

                    <search string="">

                        <filter string="Selected Pricelist" name="pricelist" domain="[('pricelist_id','=', DYNAMIC VALUE)]"/>

                    </search>

            </field>

</record>

In DYNAMIC VALUE I would recover "pricelist_id_id" in context but Odoo return a KeyError because it can't find key "pricelist_id_id" in the context.


If I try to insert a static value in domain, my custom filter works in a right way!

domain="[('pricelist_id','=', 12)]


Any solutions? 

Thanks

0
Mai Ecarde
On 10/6/16, 10:17 AM

[EDIT] This doesn't work. I believe its because the _domain_pricelist function executes without awareness of context.


A domain function on your pricelist field of the wizard should work.

@api.model

def _domain_pricelist(self):
return [('pricelist_id', '=', self._context.get('pricelist_id_id')]
pricelist = fields.Many2many(..., domain=_domain_pricelist)

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

1 follower(s)

Stats

Asked: 10/4/16, 6:19 AM
Seen: 347 times
Last updated: 10/6/16, 10:17 AM