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

Tree filter dynamic for department

By
edgard pimentel rojas
on 10/20/13, 2:47 AM 1,716 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.

0

Brett Lehrer

--Brett Lehrer--
1252
| 5 4 8
Milwaukee, United States
--Brett Lehrer--
Director of IT and open source enthusiast.
Brett Lehrer
On 10/21/13, 10:41 PM

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)
0
edgard pimentel rojas
On 10/22/13, 2:48 PM

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)

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

Brett Lehrer
on 10/22/13, 9:05 PM

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
edgard pimentel rojas
on 10/25/13, 1:21 PM

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

0 follower(s)

Stats

Asked: 10/20/13, 2:47 AM
Seen: 1716 times
Last updated: 3/16/15, 8:10 AM