Use Automated Actions for validation (in CRM)

This is an example of how to use Automated Actions to add validation.

The primary display in the CRM app is the “Pipeline” of Leads and Opportunities (as show below). It’s a Kanban view, and there are several stages, including “New”, “Qualified”, and “Proposition”.

As standard, users can freely move leads and opportunities between the stages:

1. By ‘drag and drop’ in the Kanban view

2. By clicking on the “pipeline status bar” in the Form View

However, you might want to have some controls.

In this example, we have added a “Financial Viability” check and a “Legal Approval” check. These are mandatory before the Lead / Opportunity can be moved to one of the later stages.

This is done by creating an Automated Action:

Python Code

# Require Financial Viability
if record.stage_id.name in ['Qualified', 'Proposition', 'Won'] and not record.x_studio_financial_viability:
    raise Warning('Please check Financial Viability for this Opportunity!')

# Require Legal Approval
if record.stage_id.name in ['Proposition', 'Won'] and not record.x_studio_legal_approval:
    raise Warning('Please check Legal Approval for this Opportunity!')

Odoo 14

Note that the syntax is slightly different in Odoo 14

raise UserError('Please check Legal Approval for this Opportunity!')

Results

Set the “Financial Viability” as checked, and stage can be changed:

Note: it would make sense to add further validation (for example, so that only selected users can set the “Financial Viability” check).

Validation is done when the stage is changed in the Kanban view (as above).

It’s also done in the Form View:

The check will be done everywhere and cannot be overridden.

It’s easy to add more stages and also to make the logic more complex.

One thought on “Use Automated Actions for validation (in CRM)

  1. Hello, is it possible to use this example to change the stage of a project?
    let’s say I have a many2one field in the lead card in which I show a list of projects, how can I change the project stage when changing the lead stage?

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s