Skip to Content
Menu
This question has been flagged
2 Replies
2039 Views

Hello,


I added many2many field with res.users object related in journals page and I want only selected users to view the journal. I used a domain with:  [('accountant_ids','=',user.id)]

it didn't work as well as I tried this one:  ['|',('accountant_ids','=',user.id),('accountant_ids','=',False)] , but still didn't work. Is there any solution?


Waiting for a response. Thanks in andvance!

Avatar
Discard
Author Best Answer

Thank you Kiran for helping it worked. I added this field to my model.py file and get it solved:

user_id = fields.Many2one('res.users', string='User', track_visibility='onchange', readonly=True, 
states={'draft': [('readonly', False)]}, default=lambda self: self.env.user)

and I used this rule.

['|','|',('accountant_ids','in', [user.id]),('user_id','=',user.id),('user_id','=',False)].


Avatar
Discard
Best Answer

Hi Asma,

Try,

[('accountant_ids', 'in', [user.id])]


Avatar
Discard
Author

it gives an error:
Odoo Server Error
Traceback (most recent call last):
File "/odoo/odoo-server/odoo/http.py", line 624, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/odoo/odoo-server/odoo/http.py", line 310, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/odoo/odoo-server/odoo/tools/pycompat.py", line 14, in reraise
raise value
File "/odoo/odoo-server/odoo/http.py", line 669, in dispatch
result = self._call_function(**self.params)
File "/odoo/odoo-server/odoo/http.py", line 350, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/odoo/odoo-server/odoo/service/model.py", line 94, in wrapper
return f(dbname, *args, **kwargs)
File "/odoo/odoo-server/odoo/http.py", line 339, in checked_call
result = self.endpoint(*a, **kw)
File "/odoo/odoo-server/odoo/http.py", line 915, in __call__
return self.method(*args, **kw)
File "/odoo/odoo-server/odoo/http.py", line 515, in response_wrap
response = f(*args, **kw)
File "/odoo/odoo-server/addons/web/controllers/main.py", line 1339, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/odoo/odoo-server/addons/web/controllers/main.py", line 1331, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/odoo/odoo-server/odoo/api.py", line 390, in call_kw
result = _call_kw_multi(method, model, args, kwargs)
File "/odoo/odoo-server/odoo/api.py", line 377, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "/odoo/odoo-server/odoo/models.py", line 2951, in read
raise ValueError("Invalid field %r on model %r" % (name, self._name))
ValueError: Invalid field 'user_id' on model 'account.journal'

So you need to apply domain for a many2one field of journal_id, not define record rules?

If its like that try,

journal_id = fields.Many2one( "account.journal", string="Journal", domain=lambda self: [("accountant_ids", "in", [self.env.user.id])])

Related Posts Replies Views Activity
1
Dec 22
4181
6
May 24
68933
3
May 24
4119
0
Aug 22
1478
2
Feb 22
6442