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

show filtered records in one2many field using Domain

By
Shaumyadeep Chaudhuri
on 8/29/13, 10:01 AM 11,541 views

Hi, Can i show only selected records in a one2many field using a domain, I have tried this

<field name="func_details_inno" nolabel="1" context="{'functional_dep' : 'Innovation'}" domain="[('functional_dep','=','Innovation')]">

where func_details_inno is a one2many field with functional_dep a char field in the model for func_details_inno

How can i do it?

You haven't closed the balise "/>". This is wanted ?

Xsias
on 8/29/13, 11:01 AM

Yes this is wanted and intentional, i'm defining the tree view and the form view inside for the one2many field, something like <field name="func_details_inno" nolabel="1" context="{'functional_dep' : 'Innovation'}" domain="[('functional_dep','=','Innovation')]"><tree>...</tree><form>...</form></field>

Shaumyadeep Chaudhuri
on 8/29/13, 11:43 AM

This is what i was thinking, but now i'm sure. Can you, for clarify, put all the field in the question please ?

Xsias
on 8/29/13, 12:19 PM

Its a bit long i have pastebinned the most relevant part of it and here is the link http://pastebin.com/PJqY6uwk Hope that helps to solve the problem

Shaumyadeep Chaudhuri
on 8/30/13, 3:21 AM
1
Xsias
On 9/2/13, 4:44 AM

Add :

<field name="functional_dep" invisible="True"/>

In the tree view of the "func_details_inno" field like that :

<tree>
    <!-- <field name="activity">
    <tree>
    <field name="activities"/>
    <field name="person"/>
    <field name="start"/>
    <field name="end"/>
    </tree>
    </field> -->
    <field name="functional_dep" invisible="True"/>
    <field name="activity"/>
    <field name="yes"/>
    <field name="no"/>
    <field name="na"/>
    <field name="reason" />
    <field name="risks" />
</tree>

Thanks for your reply but the problem is not that i want to hide a particular column, it can simply be achieved by not including the field in the tree view at all. The problem is i want to filter rows in the tree view and hence the requirement for using domains

Shaumyadeep Chaudhuri
on 9/2/13, 5:31 AM

Yes, but in my memories, if you want to filter on a field, you need to have this field in the tree view.

Xsias
on 9/2/13, 5:32 AM

the functional_dep field is already there and it doesn't need to be invisible, i want to show only those rows which belong to a particular functional field, innovation in this case, there might be other records in the table which have some other functional_dep value

Shaumyadeep Chaudhuri
on 9/2/13, 5:37 AM

functional_dep field is not in the tree. (not in the code you post on pastebin)

Xsias
on 9/2/13, 9:27 AM

oh sorry, i had added it later after posting it. but it doesn't help

Shaumyadeep Chaudhuri
on 9/2/13, 9:47 AM

Ok, can you post again your code on pastebin ? (To have the latest version)

Xsias
on 9/2/13, 10:23 AM

yes sure, but theere aren't many big changes, here's the code http://pastebin.com/uVEReG7P

Shaumyadeep Chaudhuri
on 9/6/13, 4:13 AM
0
Purnendu Singh (psi)
On 3/31/14, 4:15 AM

class one2many_mod2(fields.one2many):

def get(self, cr, obj, ids, name, user=None, offset=0, context=None, values=None):
    if context is None:
        context = {}
    if not values:
        values = {}
    res = {}
    for id in ids:
        res[id] = []
    ids2 = obj.pool.get(self._obj).search(cr, user, [(self._fields_id,'in',ids),('state', '=', 'open')], limit=self._limit)
    for r in obj.pool.get(self._obj)._read_flat(cr, user, ids2, [self._fields_id], context=context, load='_classic_write'):
        res[r[self._fields_id]].append( r['id'] )
    return res

class res_partner(osv.osv):

_inherit = 'res.partner'
_columns = {
    'partner_scheduled_calls': one2many_mod2('crm.phonecall', 'partner_id', 'Scheduled Calls', ),

}

this will filter the scheduled calls(('state', '=', 'open')) only from all call logs.

Hope this will help

0
Timo Talvitie
On 1/5/14, 8:17 PM

This post at Launchpad discusses the issue, but it doesn't make it clear whether it is really a bug or simply by design. I had the same issue and tried two possible solutions:

1) Change the field to many2many if you have control over the field types. Domain filtering works fine with m2m fields, or

2) Follow this post by Andreas Brueckl that shows a way to do o2m filtering with a functional field and its fnct_inv parameter

They both worked, but converting relationships that clearly should be o2m to m2m just to get access to filtering functionality feels a bit wrong, so I ended up using solution #2.

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: 8/29/13, 10:01 AM
Seen: 11541 times
Last updated: 3/16/15, 8:10 AM