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 manage search views in tables generated by a relationship between other two?

By
Juan Formoso
on 10/31/14, 9:06 AM 617 views

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?

And 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?

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/31/14, 9:06 AM
Seen: 617 times
Last updated: 3/16/15, 8:10 AM