The workflows in Odoo 19 determine the transaction and document life cycle, helping to facilitate controlled transfers from one state to another. Odoo 19 has an advanced and Pythonic approach in its working process as opposed to its previous versions, which used the old XML workflow engine. The workflow system in Odoo 19 works through the state fields, model inheritance, automated actions, and approvals.
How Workflows Work in Odoo 19?
In Odoo 19, Selection fields are used to specify states, Python methods to transition between these states, UI buttons to call the corresponding methods, and permissions to limit who can trigger each transition.
Here is an example of a state field:
state = fields.Selection([
('draft', 'Draft'),
('confirm', 'Confirmed'),
('done', 'Done'),
('cancel', 'Cancelled'),
], default='draft')
Two Core Workflow Patterns:
The Simple Workflows transfer an entity from one status to another through a sequence of activities without needing any sort of approvals. Simple Workflows are easy to develop and only need minimal coding, along with easy-to-manage access permissions. The only advantage is that they provide quick execution for large volume processing.
Approval Workflow involves transitions that require an authorization process. Approval workflows are commonly used where a compliance issue needs to be addressed.
Extending an Existing Workflow via Model Inheritance:
In Odoo 19, the most common method for workflow extension is via model inheritance with _inherit. To extend the functionality upon clicking the button for a particular record, you should implement model inheritance inside your custom module. This new overridden method can make use of the super() keyword and its own logic.
# models/sale_order.py
from odoo import models, fields
class SaleOrderExtended(models.Model):
_inherit = 'sale.order'
# Add a new custom state
state = fields.Selection(
selection_add=[('manager_approval', 'Manager Approval')],
ondelete={'manager_approval': 'set default'}
)
def action_confirm(self):
if self.state != 'manager_approval' and self.amount_total > 10000:
self.state = 'manager_approval'
return
return super().action_confirm()
def action_manager_approve(self):
if self.state != 'manager_approval':
raise UserError(_("Only orders in Manager Approval state can be approved."))
return super().action_confirm()
This is the first method of inheritance that makes it possible for modules to alter the behavior of a model from another module, and this is the one used more frequently than others in Odoo.
Extending Views to Add New Buttons:
After extending the model, change the form view by xpath inheritance in order to provide buttons specific to the states:
<!-- views/sale_order_views.xml -->
<record id="view_sale_order_form_extended" model="ir.ui.view">
<field name="name">sale.order.form.extended</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<xpath expr="//button[@name='action_confirm']" position="after">
<button name="action_manager_approve"
string="Manager Approve"
type="object" class="btn-success"
invisible="state != 'manager_approval'"/>
</xpath>
</field>
</record>
Automation Rules (No-Code Workflow Extension):
Odoo 19 provides a very strong ability for users not skilled in programming to perform no-code automation of their systems. In such automation rules, users can have one or more actions executed upon the appearance of certain trigger conditions. For instance, there can be a field with a certain value, and the rule can cause an activity creation, or 7 days of archiving a certain record, starting from the moment it was last updated.
Odoo provides users with abilities to edit such automation rules; they can add different conditions and triggers, as well as continue building the workflow in another module.
To create one: Settings > Technical > Automation Rules > New
Types of actions provided via Server Actions:
- Execute Python code
- Create or update records
- Send email / SMS
- Add followers
- Create an activity
- Chained actions execution
AI-Powered Workflow Extension (Odoo 19 Enterprise):
Odoo 19 now offers an important new functionality called AI Server Actions/Automation. One can write automation actions using natural language for purposes of record updates and workflow initiation without coding.
For instance, you can use text such as “If a manufacturing order is marked ‘In Progress’ and materials are ready, set the associated sales opportunity status to ‘Negotiation stage,’” and Odoo 19 will be able to automate it.
Best Practices for Extending Workflows in Odoo 19:
Always call super(). Ensures that the original functionality is retained within the workflow. Avoiding it can result in a malfunction of built-in features such as emailing notifications, stock movements, and journal entries managed by the parent function.
Use selection_add for new states. In cases where you add additional states to the original Selection field, selection_add adds your choices without replacing the original ones. Replacing the whole field will lead to issues upon upgrading.
Set visibility conditions (like invisible="state != 'draft'") on buttons to make sure they show up based on context and avoid irrelevant buttons within the user interface.
Wrap data records in noupdate="1". Any custom workflow data records (automation rules, server actions, access rules) defined in XML should live inside a <data noupdate="1"> block. This prevents Odoo upgrades from reverting your customizations back to module defaults.
Add access rules via ir.rule Sensitive workflow transitions such as financial approval or overrides of the states should be done through record-level rules, ensuring that only those with proper authorization can change states.
Odoo 19 represents an innovative method for managing workflow through the replacement of the legacy Workflow Engine by State fields, Python functions, model inheritance, and automation mechanisms. Whether you want to introduce your own approvals, states within the process, or automated tasks, Odoo allows numerous options for enhancing your workflows without breaking compatibility with the platform itself. Following recommendations such as using selection_add, calling super() in your code, applying access rights appropriately, and utilizing Automation Rules where necessary can help in developing flexible, robust, and upgradeable custom workflows.
To read more about How to Configure Simple and Approval Workflows in Odoo 19, refer to our blog How to Configure Simple and Approval Workflows in Odoo 19.