This question has been flagged
2 Replies
5736 Views

I just introduced a new problem now, the problem is as follows. I have a view (tree), which has the following columns:

department name description

I want is to filter the tree I agree to the department that I am logged in as user.

For example if I am logged in as user1, which belongs to the logistics department, I need to filter by department logistics.

What I did through a search, you agrege one domain (domain = logistics), which works but I need to be dynamic as I need to be agree to meet me logged department at that time.

Avatar
Discard
Best Answer

You could try extending the search function for that object:

from openerp.osv import osv, fields

class my_class(osv.osv)
    _name = 'my.class'
    # [normal class code here...]

    def search(cr, uid, domain, offset=0, limit=None, order=None, context=None, count=False):
        if context is None: context = {}

        # find the user's department (an example, I don't know your code)
        user_rec = self.pool.get('res.users').browse(cr, uid, uid, context)
        dept_id = user_rec.user_department.id

        # Append the domain to the existing one, and return the original search function
        domain += [('department_id','=',dept_id)]
        return super(my_class, self).search(cr, uid, domain, offset, limit, order, context, count)
Avatar
Discard
Author Best Answer

thanks so much,

I add my code for you to see and if run.

def search(self, cr, uid, ids,offset=0, limit=None, order=None, context=None, count=False):
    if context is None:
        context = {}

    pool_helper = self.pool.get('document.helper')
    department = pool_helper.get_department(cr, uid, ids, context=context)
    domain = [('dpt_dest', '=', department)]
    return super(documentary_step_move, self).search(cr, uid, domain, offset, limit, order, context, count)
Avatar
Discard

As long as get_department() is returning the id of the department record, it looks fine to me.

Author

that's right return name of department

def get_department(self, cr, uid, ids, context=None):

     pool_resource = self.pool.get('resource.resource')
     pool_employee = self.pool.get('hr.employee')

     resource_id = pool_resource.search(cr, uid, [('user_id', '=', uid)])
     employee_id = pool_employee.search(cr, uid, [('resource_id', '=', resource_id)])
     employee = pool_employee.browse(cr, uid, employee_id, context=context)

     department = ''
     for obj_employee in employee:
         department =  obj_employee.depar