Odoo Help


show filtered records in one2many field using Domain

Shaumyadeep Chaudhuri
on 8/29/13, 10:01 AM 16,390 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 ?

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 ?

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
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 :

    <!-- <field name="activity">
    <field name="activities"/>
    <field name="person"/>
    <field name="start"/>
    <field name="end"/>
    </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" />

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.

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)

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)

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


Timo Talvitie, Vizucom Oy

--Timo Talvitie, Vizucom Oy--
| 5 4 7
Tampere, Finland
--Timo Talvitie, Vizucom Oy--

Lead developer at Vizucom.

Timo Talvitie, Vizucom Oy
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.

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