forvas
forvas

Reputation: 10189

How to pass variables to a search view in OpenERP7?

I have created a button in res.partner form, which calls an action.

This action opens a tree view of other different model, res.partner.link.category (with fields partner_id, link_category_id, type, date and observations) ---this table is the relationship between res.partner and other table called link.category.---

I created a search view for res.partner.link.category too.

What I need now is: if I am looking a partner, and click on the button, see the res.partner.link.category tree view with only the records which have that partner_id I was looking at the moment of the click. How can I use context in that case?

How can I pass that context (with the partner_id) to the search view? I tried a lot of things but I was not able to manage my target.

Here is the code of the button:

<button name="%(res_partner_extended.action_view_history_res_partner_link_category)d"
    string="View whole history" type="action" context="{'default_partner_id': active_id}"/>

This is the action it calls:

<record id="action_view_history_res_partner_link_category"
    model="ir.actions.act_window">
    <field name="name">View whole history</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">res.partner.link.category</field>
    <field name="view_type">form</field>
    <field name="view_mode">tree</field>
    <field name="context">{'default_partner_id': context.get('default_partner_id', False)}</field>
    <field name="view_id" ref="res_partner_link_category_history_tree_view" />
    <field name="target">current</field>
</record>

The tree view:

<record id="res_partner_link_category_history_tree_view" model="ir.ui.view">
    <field name="name">res.partner.link.category.history.tree</field>
    <field name="model">res.partner.link.category</field>
    <field name="type">tree</field>
    <field name="arch" type="xml">
        <tree string="Link categories" create="false">
            <field name="partner_id" />
            <field name="link_category_id" />
            <field name="type" />
            <field name="date" />
            <field name="observations" />
        </tree>
    </field>
</record>

And the search view:

<record id="res_partner_link_category_history_search_view" model="ir.ui.view">
    <field name="name">res.partner.link.category.history.search</field>
    <field name="model">res.partner.link.category</field>
    <field name="type">search</field>
    <field name="arch" type="xml">
        <search>
            <filter name="partner_id" string="Current partner" domain="[('partner_id','=',context.get('default_partner_id', False))]"/>
        </search>
    </field>
</record>

Can anyone help me, please?

Upvotes: 0

Views: 510

Answers (1)

ifixthat
ifixthat

Reputation: 6295

Try adding the domain on the action that is opend by the button :

<field name="domain">[('partner_id','=',active_id)]</field>

and if you wanna trigger the default filter in the search then in context on the button pass the value of the filter name with default set true, which will trigger the default fitelr applied when you open the window. Sample Code:

<button name="%(res_partner_extended.action_view_history_res_partner_link_category)d"
    string="View whole history" type="action" context="{'search_default_partner_id': 1}"/>

Hope this will help.

Upvotes: 1

Related Questions