Skip to Content
Menu
This question has been flagged

I am trying to achieve something similar to the record rule used in "User: Own Documents Only Group" where a user in said group will only be able to view their sales order only.

The rule is as follows: 

['|',('user_id','=',user.id),('user_id','=',False)]
In my res.user model I have a new field called "Default Warehouse (warehouse_id)" What I want is for any user to able to view all sales order with "warehouse_id" on the sales order same as the 'warehouse_id' field set for the current user. 

Avatar
Discard
Best Answer

Hey Rashid,

You need to create a new record rule. Below will filter out records having warehouse_id set in Sales order.

Object : Sale Order Domain : [ ('warehouse_id', '=' , user.your_custom_field.id) ]

If you wish to see where warehouse_id is null then use the below domain.
Object : Sale Order Domain : [ '|' , ( 'warehouse_id' , '=' , user.your_custom_field.id ), ( 'warehouse_id' , '=' , False)]

Regards,
Pranjal G.

Avatar
Discard
Author

@Pranjal Gami When I try this I get the following error

Odoo Server Error

Traceback (most recent call last):

File "/home/odoo/src/odoo/odoo/addons/base/models/ir_http.py", line 237, in _dispatch

result = request.dispatch()

File "/home/odoo/src/odoo/odoo/http.py", line 683, in dispatch

result = self._call_function(**self.params)

File "/home/odoo/src/odoo/odoo/http.py", line 359, in _call_function

return checked_call(self.db, *args, **kwargs)

File "/home/odoo/src/odoo/odoo/service/model.py", line 94, in wrapper

return f(dbname, *args, **kwargs)

File "/home/odoo/src/odoo/odoo/http.py", line 347, in checked_call

result = self.endpoint(*a, **kw)

File "/home/odoo/src/odoo/odoo/http.py", line 912, in __call__

return self.method(*args, **kw)

File "/home/odoo/src/odoo/odoo/http.py", line 531, in response_wrap

response = f(*args, **kw)

File "/home/odoo/src/odoo/addons/web/controllers/main.py", line 1335, in search_read

return self.do_search_read(model, fields, offset, limit, domain, sort)

File "/home/odoo/src/odoo/addons/web/controllers/main.py", line 1354, in do_search_read

return Model.web_search_read(domain, fields, offset=offset, limit=limit, order=sort)

File "/home/odoo/src/odoo/addons/web/models/models.py", line 53, in web_search_read

records = self.search_read(domain, fields, offset=offset, limit=limit, order=order)

File "/home/odoo/src/odoo/odoo/models.py", line 4814, in search_read

records = self.search(domain or [], offset=offset, limit=limit, order=order)

File "/home/odoo/src/odoo/odoo/models.py", line 1698, in search

res = self._search(args, offset=offset, limit=limit, order=order, count=count)

File "/home/odoo/src/odoo/odoo/models.py", line 4487, in _search

self._apply_ir_rules(query, 'read')

File "/home/odoo/src/odoo/odoo/models.py", line 4268, in _apply_ir_rules

expression.expression(domain, self.sudo(), self._table, query)

File "/home/odoo/src/odoo/odoo/osv/expression.py", line 438, in __init__

self.parse()

File "/home/odoo/src/odoo/odoo/osv/expression.py", line 859, in parse

expr, params = self.__leaf_to_sql(leaf, model, alias)

File "/home/odoo/src/odoo/odoo/osv/expression.py", line 938, in __leaf_to_sql

assert not isinstance(right, BaseModel), \

Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):

File "/home/odoo/src/odoo/odoo/http.py", line 639, in _handle_exception

return super(JsonRequest, self)._handle_exception(exception)

File "/home/odoo/src/odoo/odoo/http.py", line 315, in _handle_exception

raise exception.with_traceback(None) from new_cause

AssertionError: Invalid value stock.warehouse(3,) in domain term ('warehouse_id', '=', stock.warehouse(3,))

Related Posts Replies Views Activity
2
Jan 24
929
2
Jun 24
974
2
May 24
457
3
Jan 24
622
2
Aug 23
1293