Question

I have been developing a lot of modules and implementing openerp for a wild. But I am stuck in a functional implementation.

I have installed the module crm_todo, it is for have tasks on crm, this module add "My Tasks" menu under Sales.

I need to create a new Menu with a Domain Filter called "Department Tasks" where will show all the task to all the members of an specific Sales Team. The task is assigned to User A; User A belongs to Sales Team A; Sales Team A has 2 more members. This new Menu have to list the task Assigned to User A to all the members of Sales Team A.

I was trying to do with field.function, but something is wrong. I am trying to apply the domain on act_window using the openerp Action Windows Menu and assigning it to the new Menu.

Was it helpful?

Solution

Specifying the login user sale team as domain parameter is not possible but there is another way in which we can achieve this. ie; in my view action i specify the domain as:

<field name="domain">[('user_id.default_section_id', 'in', user_sale_team())]</field>

where user_id is the responsible user of the task. Now inherit read function of ir.actions.act_window and check if user_sale_team() is present in the domain of read result and replace this with the login user sale team id. This can be done as:

class ir_action_window(osv.osv):
_inherit = 'ir.actions.act_window'

def read(self, cr, uid, ids, fields=None, context=None, load='_classic_read'):
    user_pool = self.pool.get('res.users')
    obj_user = user_pool.browse(cr, uid, uid, context=context)
    res = super(ir_action_window, self).read(cr, uid, ids, fields=fields, context=context, load=load)
    if not isinstance(res, list):
        res = [res]
    sale_team_id = obj_user.default_section_id and obj_user.default_section_id.id or''
    for r in res:
        mystring = 'user_sale_team()'
        if mystring in (r.get('domain', '[]') or ''):
            r['domain'] = r['domain'].replace(mystring, str([sale_team_id]))
    if isinstance(ids, (int, long)):
        if res:
            return res[0]
        else:
            return False
    return res

ir_action_window()

This filters the result of the task to be displayed to each user based on his/her sale team.

Hope this helps.....

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top