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 apply domain filter in one2many field?

By
Stephen Raj
on 11/27/13, 9:14 AM 3,433 views

Hi,

As known the customer can have multiple contacts. The contacts are created by the different users. I would like to make a filter that works in the following way logged-in user can see all the customers but not all the contacts of that particular customer (shown in kanban view down in the customer view). He can only see the contacts created by him. So I applied domain filter in the child_ids(type = one2many) field.

I tried the below possibilities but not succeeded yet.

Try 1: XML

<field name="child_ids" domain="[('create_uid', '=', context.get('uid'))]" context="{'default_parent_id': active_id}" mode="kanban">

Try 2: Python

'child_ids': fields.one2many('res.partner', 'parent_id', 'Contacts', domain="[('create_uid', '=', context.get('uid'))]"),

Try 3: Fields_view_get method

def fields_view_get(self, cr, user, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
    if (not view_id) and (view_type=='form') and context and context.get('force_email', False):
        view_id = self.pool.get('ir.model.data').get_object_reference(cr, user, 'base', 'view_partner_simple_form')[1]
    res = super(res_partner,self).fields_view_get(cr, user, view_id, view_type, context, toolbar=toolbar, submenu=submenu)

    if view_type == 'form':
        res['arch'] = self.fields_view_get_address(cr, user, res['arch'], context=context)
    eview = etree.fromstring(res['arch'])
    if view_type:
        for node in eview.xpath("//field[@name='child_ids']"):
            user_filter =  "[('create_uid', '='," + str(user) + " )]"
            node.set('domain',user_filter)
    res['arch'] = etree.tostring(eview)
    return res

Kindly clarify me with this regard. Thanks a lot for your time.

0
Julio Serna
On 11/28/13, 8:31 PM

You may try this: Create a record rules Object: res.partner Use this Rule definition (Domain Filter): ['|', ('parent_id', '=', False ), ('create_uid', '=', user.id)] In the "Acces Rights" section: check all

Best Regards

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: 11/27/13, 9:14 AM
Seen: 3433 times
Last updated: 3/16/15, 8:10 AM