Server actions work on a Model, so one of the first things to do is to pick the Base Model we want to work with. In our example, we used Project Tasks.
Next, we should select the type of action to perform. There are a few options available:
- Execute Python Code allows you to write arbitrary code to execute, when none of the other options is flexible enough for what we need
- Create a new Record allows you to create a new record on the current or on another Model
- Update the Record allows you to set values on the current or on another record
- Send Email allows choosing an email template, and will be used to send out an email when the action is triggered
- Execute several actions can be used to trigger a client or window action, just like when a menu item is clicked on
- Add Followers allows to subscribe users or channels to the record
For our example, we used Update the Record to set some values on the current record. We set Priority to 1 to star the task, and set a value on the Deadline field. This one is more interesting, since the value to use is evaluated from a Python expression. Our example makes use of the datetime Python module (visit https://docs.python.org/2/library/datetime.html) to compute the date 3 days from today.
Arbitrary Python expression can be used there as well as in several of the other action types available. For security reasons, the code is checked by the safe_eval function implemented in odoo/openerp/tools/safe_eval.py. This means that some Python operations may not be allowed, but this rarely proves to be a problem.