Enable Dark Mode!
automated-actions-automation-in-the-odoo-16-erp.jpg
By: Sruthi C Nair

Automated Actions (Automation) in the Odoo 16 ERP

Technical Odoo 16

You can use automated actions to trigger actions based on time conditions automatically. They can be used to automatically perform some operations on datasets that meet certain criteria and time constraints. Schedulers are automated actions that run automatically over a period of time and can do many things. It performs actions without manual intervention and makes background jobs a lot easier. Just insert a record into the ir.cron table, and Odoo will do it as defined.

Automated Actions and Server Actions, which are related, are a potent approach to extending the functionality of Odoo without having to write any code (or with only a few lines of Python code). Additionally, you cannot perform development or install add-ons from third parties when using Odoo Online, but you can use automated actions (and server actions).

Odoo functionality can be improved and customized in a number of ways through automated actions:

1. Simple workflow: based on rules, alter a document's "stage" automatically.

2. validation if a user tries to alter the "stage" manually.

3. Create follow-up tasks for users.

To make data entry easier and to cut down on mistakes, automatically assign values for fields based on rules. Validation to stop users from entering data incorrectly (e.g., Preventing duplicate products from being created)

On the creation, deletion, or update of a database record in the given Odoo Model (database table), automated actions may be initiated. They may also be based on form modification or a timed condition. In order to specify "business rules," automated actions can be conditioned on domains and/or "watched fields" (an action for one group of customers, or one type of product, etc.), and Python code can be used to implement more sophisticated logic.

Start by enabling developer mode and navigating to Settings, Technical, / Automated Actions.

automated-actions-(automation)-in-the-Odoo-16-erp-cybrosys

Installation

If you can't find this option, you may need to install the Automatic Action Rules module.

First, remove the “Apps” filter by clicking on the ‘X’:

automated-actions-(automation)-in-the-Odoo-16-erp-cybrosys

Schedulers are automated actions that run automatically over a time period and can do a lot of things. It performs actions without manual intervention and makes background jobs a lot easier. Just insert a record into the ir.cron table, and Odoo will do it as defined.

1. Creating the model and fields

The first step is to create a model (if you don’t have one yet) and to create some fields on this model:

an automated action can be configured with trigger conditions and domains to perform some actions automatically when certain conditions are met.

Trigger conditions are used to specify the conditions that need to be met for the automated action to be triggered. These conditions can be based on the values of the fields in the record or related records. When the trigger conditions are met, the automated action will be executed automatically.

Domains are used to filter the records on which the automated action should be executed. The domain is defined as a list of tuples, where each tuple specifies a condition that needs to be met by the record. Only the records that meet the conditions specified in the domain will be selected for the automated action.

Here's an example of how to define an automated action with trigger conditions and domains in Odoo 16:

Define the model: Let's say we have a custom model called my.model which has a field called state which can have two values: "draft" and "done".

from odoo import models, fields

class MyModel(models.Model):
    _name = 'my.model'
    
    name = fields.Char('Name')
    date = fields.Date('Date')
    amount = fields.Float('Amount')
    partner_id = fields.Many2one('res.partner', string='Partner')
    state = fields.Selection([
        ('draft', 'Draft'),
        ('done', 'Done'),
    ], default='draft', string='State')

2. Define the automated action: We want to create an automated action that sets the state field to "done" whenever the amount field of a record is greater than or equal to 100. We'll use the base.automation class to define the automated action.

from odoo.addons.base.models import ir_actions
from odoo import api

class MyAutomation(ir_actions.server.Action):

    @api.model
    def run(self, record):
        if record.amount >= 100:
            record.write({'state': 'done'})

    trigger_condition = fields.Char(
        string='Trigger condition',
        default='record.amount >= 100',
        help='The trigger condition for the action.'
    )

In the above code, we define the run method which checks if the amount field of the record is greater than or equal to 100. If it is, then it sets the state field to "done".

We also define the trigger_condition field which specifies the condition that needs to be met for the automated action to be triggered.

3. Register the automated action: Finally, we need to register the automated action using the ir.actions.server data model in an XML file in the module's data directory.

<odoo>
    <data>
        <record model="ir.actions.server" id="my_automation">
            <field name="name">My Automation</field>
            <field name="model_id" ref="model_my_model"/>
            <field name="state">code</field>
            <field name="code">MyAutomation().run(record)</field>
            <field name="type">ir.actions.server</field>
            <field name="trigger_condition">record.amount &gt;= 100</field>
        </record>
    </data>
</odoo>

In the above XML, we're setting the trigger_condition to record.amount >= 100.

Now, whenever the amount field of a record in my.model is greater than or equal to 100, the automated action will set the state field to "done".

In conclusion, automated actions in Odoo 16 are a powerful tool for extending the functionality of the software without having to write any code. With automated actions, you can trigger actions automatically based on time conditions or other criteria, making background jobs much easier. Additionally, with schedulers, you can automate tasks over a period of time without any manual intervention. Automated actions can be used for a variety of purposes, such as altering a document's stage, preventing incorrect data entry, and creating follow-up tasks for users. By enabling developer mode and navigating to Settings / Technical / Automated Actions, you can create automated actions and customize them according to your business needs. Overall, automated actions are a great way to improve the efficiency and accuracy of your business processes in Odoo 16.


If you need any assistance in odoo, we are online, please chat with us.



0
Comments



Leave a comment

 


whatsapp
location

Calicut

Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635

location

London

Cybrosys Limited
Alpha House,
100 Borough High Street, London,
SE1 1LB, United Kingdom

location

Kochi

Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.

location

Bangalore

Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message