Odoo Help


How to manage search views in tables generated by a relationship between other two?

Juan Formoso
on 10/31/14, 9:06 AM 822 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"
    <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 name="view_id" ref="res_partner_link_category_history_tree_view" />
    <field name="target">current</field>

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" />

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">
            <filter name="partner_id" string="Current partner" domain="[('partner_id','=',context.get('default_partner_id', False))]"/>

Can anyone help me, please?

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 10/31/14, 9:06 AM
Seen: 822 times
Last updated: 3/16/15, 8:10 AM