What Are Server Actions?
Server actions execute logic without writing Python code. They run from buttons, scheduled actions, or automated action triggers. Perfect for: sending emails, updating fields, creating records, and executing Python snippets.
Server Action Types
| Type | Use Case | Example |
|---|---|---|
| Update Record | Change field values | Set stage to 'Won' when amount > $10K |
| Create Record | Generate new records | Create task when lead is qualified |
| Send Email | Send template email | Send welcome email on partner creation |
| Add Followers | Subscribe users | Add sales manager to high-value deals |
| Create Next Activity | Schedule follow-up | Schedule call 3 days after quote sent |
| Execute Code | Run Python | Complex logic, API calls, calculations |
| Send SMS | SMS notification | Appointment reminder via SMS |
Creating a Server Action
Via Settings (No-Code)
- Settings → Technical → Server Actions
- Click Create
- Select Model (e.g., Sale Order)
- Choose Action Type
- Configure parameters
- Save
Example: Update Record
# When: Sale order amount > 10,000
# Action: Set priority to 'High' and add tag 'VIP'
# Model: Sale Order (sale.order)
# Action Type: Update Record
# Fields to update:
# priority = '2' (High)
# tag_ids = [(4, ref('sale.tag_vip'))]Example: Create Record
# When: CRM lead reaches 'Qualified' stage
# Action: Create a project task for implementation planning
# Model: CRM Lead (crm.lead)
# Action Type: Create Record
# Target Model: Project Task (project.task)
# Values:
# name = "Implementation: " + record.name
# project_id = ref('project.implementation_project')
# partner_id = record.partner_id.id
# description = record.descriptionExample: Execute Code
# Available variables in code actions:
# record / records — the record(s) triggering the action
# env — the Odoo environment
# model — the model being acted on
# datetime, dateutil — date utilities
# time — time module
# log — logging function
# Warning — raise warning
# Example: Calculate commission and create record
for rec in records:
if rec.amount_total > 5000:
commission = rec.amount_total * 0.05
env['hr.expense'].create({
'name': f'Commission: {rec.name}',
'employee_id': rec.user_id.employee_id.id,
'total_amount': commission,
'product_id': env.ref('hr_expense.product_commission').id,
})
log(f"Created commission {commission} for {rec.name}")Automated Actions (Triggers)
Automated actions combine a trigger with a server action. The trigger fires automatically when conditions are met.
Trigger Types
| Trigger | When It Fires | Example |
|---|---|---|
| On Creation | Record is created | Send welcome email when customer created |
| On Update | Specific field changes | Notify manager when deal stage changes |
| On Creation & Update | Both | Validate data on every save |
| On Deletion | Record is deleted | Log deletion to audit trail |
| Based on Timed Condition | Time-based | Send reminder 3 days before due date |
| Based on Form Modification | Form changed (not saved) | Show warning before user saves |
Creating an Automated Action
- Settings → Technical → Automated Actions
- Select Model
- Choose Trigger
- Set Filter (when to trigger)
- Set Before Update Filter (for update triggers)
- Choose Action(s) to execute
Example: Auto-Assign Sales Team
# Trigger: On Creation of CRM Lead
# Filter: Country is United States
# Action: Update Record
# team_id = ref('sales_team.salesteam_us')
# user_id = ref('base.user_us_manager')
# Filter Domain: [('country_id.code', '=', 'US')]Example: Timed Reminder
# Trigger: Based on Timed Condition
# Model: Sale Order
# Date Field: validity_date (Expiration Date)
# Trigger: 3 days before
# Filter: state = 'draft' (only for quotations)
# Action: Send Email
# Template: "Your quotation expires in 3 days"Common Patterns
- Auto-assignment: Route leads to teams based on country, source, or product interest
- Escalation: If ticket not resolved in 24h, reassign to senior agent
- Notification: Email manager when invoice amount exceeds threshold
- Data validation: Prevent saving if required fields are empty
- Cross-module creation: Create project task when sale order is confirmed
- Follow-up: Schedule activity 7 days after quote sent if no response
Limitations
- Complex logic may be slow — use Python code actions or custom methods for heavy operations
- No error handling in code actions — wrap in try/except
- Timed actions check once per cron interval (default: 4 hours, configurable)
- Cannot trigger on computed field changes (only stored fields)
DeployMonkey
DeployMonkey's AI agent helps configure automated actions in natural language: "Send an email when an invoice is overdue by 15 days" → AI creates the automated action with correct trigger, filter, and email template.