There's more...

When defining a context, you have access to some variables, the most important one being uid, which evaluates to the current user's ID. You'll need this to set default filters (refer to the next recipe, Defining filters on record lists – Domain). Further more, you have access to the context_today function and the current_date variable, where the first is a date object that represents the current date, as seen from the user's time zone, and the latter is the current date as seen in UTC, formatted as YYYY-MM-DD. To set a default value for a date field to the current date, use current_date and, for default filters, use context_today().

Further more, you can do some date calculations with a subset of Python's datetime, time, and relativedelta classes.

Most of the domains are evaluated on the client side. The server-side domain evaluation is restricted for security reasons. When client-side evaluation was introduced, the best option in order to not break the whole system was to implement a part of Python in JavaScript. There is a small JavaScript Python interpreter built into Odoo that works well for simple expressions, and that is usually enough.
Beware of use of the context variable in the <act_window /> shortcut. These are evaluated at installation time, which is nearly never what you want. If you need variables in your context, use the <record /> syntax.

We can add buttons in the same way as we added context keys in our action. This causes the function or action the button calls to be run in the context given.

Most form element attributes that are evaluated as Python also have access to the context dictionary. The invisible and readonly attributes are examples of these. So, in cases where you want an element to show up in a form some times, but not at other times, set the invisible attribute to context.get('my_key'). For actions that lead to a case in which the field is supposed to be invisible, set the context key to my_key: True. This strategy enables you to adapt your form without having to rewrite it for different occasions.

You can also set a context on relational fields, which influences how the field is loaded. By setting the form_view_ref or tree_view_ref keys to the full XML ID of a view, you can select a specific view for this field. This is necessary when you have multiple views of the same type for the same object. Without this key, you get the view with the lowest sequence number, which might not always be desirable.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset