I need some help. I want to ensure that if the user is not named ‘Marcos’ or ‘admin’, the records in the party will only show the records where the party name is equal to the name of the logged-in user else when user.name are ‘Marcos’ or ‘admin’ , all the records will be visible on party module.
Here is the Xml code that i have add
<field name="domain" eval="(
('name', '=', Eval('_user', {}).get('name')) if Eval('_user', {}).get('name') not in ('Marcos', 'admin') else ()
)" pyson="1"/>
You can not use Python if is a PYSON statement, you must use the If() of PYSON.
The action domain is evaluated by the client, but the _user keyword is just the user id. If you want to evaluate against more data, you need to put them in the user context so they will be available as Eval('context', {}).get(...)
I didn’t get well the idea must i also use record rule ?? For me, I am looking just for the visibility control of parties records based on the user.name
user is not in the context and even less as a dictionary.
You must fill yourself the context for example by extending res.user and add name to _context_fields.
I see that you put also an access rule, but as I said this is going to be very difficult to implement because you need to enforce the rule to all models that use party as reference.
Any way in record rule, you must add the user to the Rule._get_context in order to have user in the evaluation context. And you must also add the user to the Rule._get_cache_key.
Then the domain should look like [('name', '=', Eval('user', {}).get('name'))].
Okay now i have deleted the access rule, I thought it’s obligatory to do it to control visibility? so i need to confirm is it obligatory because i deleted it ? and i tested with your domain suggestion
The access rule is required if you really forbid any user to see any other parties. But as I said this will make Tryton mostly unusable because almost every model is linked to a party in some way.
Is the name in the user context? Did you re-login?