How it works...

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 are flexible enough for what we need.
  • Create a new Record allows you to create a new record on the current model, or on another model.
  • Update the Record allows you to set values on the current record, or on another record.
  • Send Email allows you to choose an email template. It 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 users or channels to subscribe to the record.
  • Create Next Activity allows you create a new activity. This will be displayed in the chatter.

For our example, we used Update the Record to set some values on the current record. We set the Priority to 1 to star the task, and set a value on the Deadline field. This one is more interesting, because the value to use is evaluated from a Python expression. Our example makes use of the datetime Python module (https://docs.python.org/2/library/datetime.html) to compute the date three days from today.

Arbitrary Python expressions 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 the odoo/tools/safe_eval.py file. This means that some Python operations may not be allowed, but this rarely proves to be a problem.

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

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