This question has been flagged
3 Replies
25509 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?

Avatar
Discard

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

Author

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>

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

Author

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

Best Answer

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>
Avatar
Discard
Author

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

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

Author

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

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

Author

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

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

Author

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

Best Answer

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.

Avatar
Discard
Best Answer

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

Avatar
Discard