Enable Dark Mode!
automated-actions-in-odoo-17.jpg
By: Ayana KP

Automated Actions in Odoo 17

Technical Odoo 17

Automated actions in Odoo 17 enable users to set predefined actions triggered automatically by specified conditions or events. These actions include sending emails, creating records, updating fields, and triggering notifications. By automating repetitive tasks, businesses enhance efficiency, accuracy, and productivity.

Automated Actions and Server Actions in Odoo offer a potent way to extend functionality without extensive coding. Even in Odoo Online, where development is limited, automated actions remain accessible, empowering users to optimize workflows effectively.

There are several ways in which Odoo's functionality can be enhanced and customized through automated actions:

1. Streamlined Workflow: Automatically adjust a document's "stage" based on predefined rules, simplifying and streamlining your business processes.

2. Validation Mechanisms: Implement validation checks to prevent users from manually altering the "stage" inappropriately, ensuring data integrity and adherence to business rules.

3. Task Automation: Automatically generate follow-up tasks for users based on specific triggers or events, facilitating task management and ensuring that critical actions are not overlooked.

To simplify data entry and minimize errors, automate the assignment of field values based on predefined rules. Implement validation checks to prevent users from entering incorrect data, such as avoiding the creation of duplicate products.

Automated actions can be triggered upon the creation, deletion, or update of records within a specified Odoo Model (database table). These actions may also be triggered by form modifications or time-based conditions. Business rules can be defined using domains and "watched fields" (actions specific to certain customer groups or product types), and more complex logic can be implemented using Python code.

To configure automated actions, start by enabling developer mode and navigating to Settings -> Technical -> Automated Actions. From there, you can define the rules and conditions that trigger automated actions to streamline your workflow and improve data accuracy.

Automated Actions in Odoo 17-cybrosys

Installation

If you are unable to locate this option, you may need to install the Automatic Action Rules module.

To do so, begin by removing the "Apps" filter. Simply click on the 'X' icon next to it.

Schedulers are automated processes that execute at predefined intervals without requiring manual intervention. They perform various tasks in the background, simplifying the execution of background jobs. To schedule a task, simply insert a record into the ir.cron table, and Odoo will execute it according to the defined schedule.

To configure an automated action with trigger conditions and domains in Odoo 17, follow these steps:

1. Create Model and Fields: Begin by creating a model if one does not already exist. Define fields on this model as needed. Automated actions are configured to perform specific actions automatically when certain conditions are met.

2. Define Trigger Conditions: Specify trigger conditions that must be met for the automated action to be executed. These conditions are based on field values in the record or related records. When trigger conditions are satisfied, the automated action triggers automatically.

3. Set Domains: Use domains to filter records on which the automated action should operate. Domains are defined as a list of tuples, with each tuple specifying a condition that records must meet. Only records meeting the conditions specified in the domain are selected for the automated action.

Below is an instance illustrating the configuration of an automated action with trigger conditions and domains in Odoo 17:

Assuming we have a custom model named "my.model" with a field called "state" having 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')

We aim to establish an automated action wherein the state field transitions to "done" when the amount field of a record equals or exceeds 100. We'll employ the base.automation class for this purpose.

from odoo import api
class ServerAction(models.Model):
   _inherit = "ir.actions.server"
    @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 provided code snippet, the 'run' method is established to verify whether the 'amount' field of the record surpasses or equals 100. Should this condition hold true, the 'state' field is then assigned the value "done". Additionally, the 'trigger_condition' field is defined to delineate the prerequisite condition for activating the automated action.

<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 conclusion, automated actions with in Odoo 17 serve as a potent means to enhance the software's capabilities effortlessly, sans the need for coding. By leveraging automated actions, one can seamlessly initiate predefined actions based on time parameters or specified criteria, simplifying the execution of background tasks. Furthermore, schedulers enable the automation of tasks over designated timeframes, eliminating the need for manual intervention.


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

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