跳至内容
菜单
此问题已终结
1 回复
19029 查看

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 !


形象
丢弃
编写者

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)])

编写者

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

最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
3
5月 24
18178
0
2月 25
18
1
7月 19
5128
1
9月 16
4100
2
3月 15
6932