Managing customer invoice emails manually can consume a significant amount of time, especially when handling a large number of invoices daily. Delays in sending invoices can also impact customer experience and accounting workflows.
In this blog, we will see how to automate invoice email sending in Odoo using Scheduled Actions (Cron Jobs) together with Automation Rules to trigger the process instantly when an invoice is posted.
Why Improve the Default Odoo Invoice Email Flow?
Odoo provides a built-in scheduled action called “Send Invoices Automatically”, which processes invoices in the background. However, this cron job runs periodically, which can cause delays between invoice posting and email delivery.
To improve this, we can trigger the process instantly when an invoice is posted using Automation Rules.
With the Automation Rule, we can populate the sending_data field automatically when the invoice status changes from Draft → Posted
Understanding Odoo Invoice Email Flow
When the Send & Print button is clicked manually:
- Odoo fills the sending_data field
- The scheduled action processes the invoice
- Email is sent asynchronously
The cron is typically based on a domain like:
[
('sending_data', '!=', False),
('state', '=', 'posted'),
]
The cron usually processes invoices in batches (for example, 10 invoices per execution).
Solution Overview
To improve this flow, we will:
- Create an Automation Rule
- Execute Python code automatically
- Queue invoices when they are posted
- Trigger the cron immediately
Step 1: Create an Automation Rule in Odoo
Navigate to:
Settings → Technical → Automation → Automation Rules
Create a new automation rule for the Journal Entry model.
Domain Configuration
Before Update Domain
[
('state', '=', 'draft'),
('move_type', 'in', ['out_invoice', 'out_refund']),
('sending_data', '=', False),
('commercial_partner_id.email', '!=', False),
]
Apply On Domain
[
('state', '=', 'posted'),
('move_type', 'in', ['out_invoice', 'out_refund']),
('sending_data', '=', False),
('commercial_partner_id.email', '!=', False),
]
Step 2: Add Execute Python Code Action
Choose: Action To Do → Execute Code
Add the following Python code:
How This Works
1. Invoice Gets Posted
When an invoice moves from Draft → Posted, the automation rule is triggered.
2. Validation Checks Run
The script validates:
- The invoice is posted
- The invoice type is a customer invoice or a credit note
- Customer email exists
- The invoice is not already queued
3. Invoice is Queued for Sending
The script writes data into the sending_data field, which marks it for email processing.
4. Cron Execution is Triggered
Instead of waiting for the next scheduled run, _trigger() initiates the cron execution process immediately.
Important Notes
Preventing Duplicate Emails
The condition ('sending_data', '=', False) ensures invoices are not queued multiple times.
When to Use This Approach
This automation is especially useful for:
- Businesses sending a high volume of invoices daily
- Teams wanting instant invoice delivery after validation
- Reducing the manual email sending workload
- Improving operational efficiency in accounting workflows
Conclusion
By combining:
- Automation Rules
- Scheduled Actions
- Python Server Actions
You can build a fully automated invoice email system in Odoo without heavy customisation of core modules.
This improves efficiency, reduces manual workload, and ensures customers receive invoices immediately after validation.