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 filter a view when cliking on a parent element ?

By
Célia Couiller
on 11/29/16, 3:30 AM 181 views

Hi,

I can't understand the way when you click on a project (on the dashboard) the new view display only the tasks of this project. I want to do something similar. Can anyone help me, explaining the mechanism or linking some documentation ?

Thanks a lot.


1
Laurent OLIVIER
On 11/30/16, 6:02 AM

Hi,


The developper doc says you can use a type "action" in kanban box:

Buttons and fields
While most of the Kanban templates are standard QWeb, the Kanban view processes field, button and a elements specially:
    by default fields are replaced by their formatted value, unless they match specific kanban view widgets
    buttons and links with a type attribute become perform Odoo-related operations rather than their standard HTML function. Possible types are:
    action, object   standard behavior for Odoo buttons, most attributes relevant to standard Odoo buttons can be used.   ...


In the project_view.xml you find that the kanban project view is linked to an action called : act_project_project_2_project_task_all:

<div class="oe_kanban_project_list">

                                        <a t-if="record.use_tasks.raw_value" name="%(act_project_project_2_project_task_all)d" type="action" style="margin-right: 10px">                                           

                                        <t t-raw="record.task_count.raw_value"/> Tasks                                       

                                        </a>                                   

</div>


This action ( which is in the same module) filter the tasks of the active project :

<record id="act_project_project_2_project_task_all" model="ir.actions.act_window">

 <field name="name">Tasks</field>

 <field name="res_model">project.task</field>

 <field name="view_mode">kanban,tree,form,calendar,gantt,graph</field>

 <field name="context">{

    'search_default_project_id': [active_id],

    'default_project_id': active_id,

    'active_test': False,

 }</field>

...

 

Edit :

To use  'search_default_project_id', you must have a search view where one filter named "project_id" exists.

See more explanations here :https://www.odoo.com/forum/help-1/question/set-default-filter-value-in-search-view-5856


If I'm not wrong, the key 'default_project_id': active_id means that, if you create a task, its project_id will be automatically set to active_id ( ie the project you clicked in kanban view).


Hi, thanks a lot for this answer. Maybe my question wasn't precise enough. I saw this view, this action, and I manage do do something similar (displaying some element grouped like I wanted) but I don't understand from where the

" 'search_default_project_id': [active_id],

'default_project_id': active_id,"

syntax come. I tried to find a function that define it but I failed and I can't neither adapt it directly

(I tried :

<field name="context">{

'search_default_myclass_id': [active_id],

'default_myclass_id': active_id,

}</field>

)

Maybe I miss something ?

Célia Couiller
on 11/30/16, 7:35 AM

see my edit

Laurent OLIVIER
on 12/1/16, 12:46 AM

Thanks it works !

I just have one more problem, maybe you can help me :

I have a system of class like this :

class GrandParent(models.Model):

[...]

class Parent(models.Model):

grand_dad_id=fields.Many2One('GrandParent')

children_ids=fields.One2Many('Child)

[...]

class Child(models.Model):

dad_id=fields.Many2One('Parent')

[...]

And when cliking on a grandParent kanban card I would like to display his "family" : his grand children (class child) grouped by parent

I don't know how to acess the "grand_dad" property.

I tried something like :

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

[...]

<search string="User Stories">

<!-- <field name="dad_id.grand_dad_id"/> -->

[...]

</record>

With in the action on the grand_parent card :

{'search_default_parent':active_id}

Célia Couiller
on 12/1/16, 3:22 AM

Maybe you could create a field or filter (in the search view) using a domain like [('parent_id','child_of',[self])] (or something like that) and using it in you search_default_xxx context key ? (but not sure it's exactly what you need!)

May I suggest to open a new thread with this question ?

Laurent OLIVIER
on 12/1/16, 4:22 AM

Ok I'll do that

Thanks a lot for your help !

Célia Couiller
on 12/1/16, 4:30 AM

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

3 follower(s)

Stats

Asked: 11/29/16, 3:30 AM
Seen: 181 times
Last updated: 11/30/16, 10:46 AM