Getting key value from user preferences in domain?

Hey i just added a new element in context with the following code

    def _get_preferences(cls, user, context_only=False):
        res = super(User, cls)._get_preferences(user,
        if user.employee:
                res['party_id'] =
        return res

the party_id is added to the dictionary but when i want to fetch the party_id using domain
[[ '','=',Eval('context').get('party_id')]]

this doesnt seems to work

not sure what i am doing wrong here any help is greatly appreciated

Could you explain what is not working? What you have coded and what you are trying to achieve.

I wrote this code in module/company/

print(res) output the following

{'name': 'john', 'password': 'xxxxxxxxxx', 'email': '', 'signature': '', 'menu': 2, 'menu.rec_name': 'Menu', 'pyson_menu': '{"res_model": "", "context_model": null, "context_domain": null, "id": 2, "limit": null, "name": "Menu", "type": "ir.action.act_window", "pyson_domain": "[[\\"parent\\", \\"=\\", null]]", "pyson_context": "{}", "pyson_order": "[[\\"sequence\\", \\"ASC NULLS FIRST\\"], [\\"id\\", null]]", "pyson_search_value": "[]", "domains": [], "views": [[3, "tree"]], "icon.": null}', 'actions': [], 'status_bar': 'john [rs]', 'warnings': [], 'applications': [], 'mobile': '', 'dashboard_layout': 'square', 'dashboard_actions': [], 'employee': 1, 'employee.rec_name': 'john', 'company': 1, 'company.rec_name': 'Test company', 'language': 'en', 'language_direction': 'ltr', 'groups': [4], 'roles': [], 'party_id': 1, 'main_company': 1, 'main_company.rec_name': 'Test company', 'employees': [1]}

but when i try to get the party_id in the following manner in record rule

seems like the domain does not work to fetch data based on party id

So I guess you are trying to write a record rule. You can not use the context for record rule because it is not safe. Any user can fill the context with any value.
If you need a specific value available in the evaluation context of record rule, you must override Rule._get_context.

class Rule(metaclass=PoolMeta):
     __name__ = 'ir.rule'

   def _get_context(cls):
        pool = Pool()
        User = pool.get('res.user')
        Party = pool.get('')
        context = super()._get_context()

        with Transaction().set_user(0):
            user = User(Transaction().user)

        if user.employee:
           context['party_id'] = EvalEnvironment(
                    Party(, Party)

        return context

i wrote this code but still no luck am i doing something wrong ?
an example would be greatly appreciated

So your rule should be written as: [('', '=', Eval('party_id', {}).get('id'))]

PS: It is strange to suffix an instance name with _id

that was life saving thanks

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.