This question has been flagged
1 Reply
17697 Views

H, I have the following code

class Sprint(models.Model):

    user_id = fields.Many2one('res.users', string='Assigned to',
         domain=[('id', 'in', self.team_ids.team_members.id)])

class Team(models.Model):
    team_members = fields.Many2many('res.users')
    sprint_ids = fields.Many2many('project_extension.sprint')

With the following error :

Odoo Server Error
Traceback (most recent call last):
File "/var/www/odoo10/odoo/odoo/http.py", line 638, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
File "/var/www/odoo10/odoo/odoo/http.py", line 689, in dispatch
    return self._json_response(result)
File "/var/www/odoo10/odoo/odoo/http.py", line 627, in _json_response
    body = json.dumps(response)
File "/usr/lib/python2.7/json/__init__.py", line 243, in dumps
    return _default_encoder.encode(obj) File "/usr/lib/python2.7/json/encoder.py", line 207, in encode chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencode
    return _iterencode(o, 0)
File "/usr/lib/python2.7/json/encoder.py", line 184, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: res.users() is not JSON serializable

 

I've tried many thing, both in python and xml files

What I wan't is to filter my field "Assigned to" on my Sprint view form with only user who are in a team attached to the sprint.


If someone have an idea thanks a lot !


Avatar
Discard
Author

Sorry I made a mistake (and can't edit my post), this error doesnt appear with this code

the domaine is like:

domain=lambda self: [(self.user_id,'=',self.team_ids.team_members.id)])

Author

Also if someone know how to filter based on user group, please tell me.

I tried

domain="[('user_id.groups_id','=',38)]"

where 38 should be project.group_project_user

Best Answer

Hi Evolutis Employee,

You were getting the error because of in the domain you are using 'in' operator which takes the list to check with and for that you need to provide ids instead of id.

Regarding your second question you can use 

self.user_has_groups('project.group_project_user')

to check the whether  current user has that group or not

Thanks

Avatar
Discard