Automation of calculated fields in Odoo

odoo automatisierung code ausfuehren
Contents

    Automated processes in Odoo – Calculated fields

    Einleitung

    In Odoo there are many ways to automate workflows and thus save time. One of these possibilities is the automatic calculation and filling of fields in data records. Whether you want to generate a customer number or other calculated values such as invoice numbers, internal IDs or compound names – Odoo offers you the flexibility to automate these tasks via automation rules and scheduled actions. In this article, I’ll show you how to implement these processes step by step and increase your efficiency in the process.

    Goal

    The aim of this guide is to show you how you can automatically fill calculated or composite fields in Odoo. In the example, we create a customer number for contacts. However, this procedure can easily be adapted to other use cases in which you want to automatically generate certain values and write them into fields.

    Procedure

    1. automation of fields for new data records

    To prevent you from having to manually enter a customer number or another value for each new contact, you can create an automation rule that does this for you.

    Step-by-step instructions:

    • Select model: Select the model to which the automation should be applied. In this example, we are using “Contact” (res.partner).
    • Set trigger: Set the trigger to “On save” so that the rule is executed every time a new data record is created or updated.
    • Define conditions: Define a condition that ensures that only data records for which the target field (e.g. the customer number) has not yet been set are taken into account.
    • Add follow-up action: Here you insert the code that calculates the customer number and writes it into the field.

    Example code:

    if record.id:
        record['x_studio_custom_field'] = 'K' + str(record.id)
    

    This code sets the customer number in the user-defined field “x_studio_custom_field” as soon as the contact is saved. The ID of the data record is used to generate a unique number.

    2. updating existing data records with planned actions

    If you already have existing data records that have not yet filled in the field, you can use Planned actions to calculate and enter these values retrospectively.

    Step-by-step instructions:

      • Select model: Here, too, we use “Contact” (res.partner) as the model.
      • Define permitted users: Define who is allowed to perform the action.
      • Determine the execution time: You can execute the action manually or schedule it at a fixed time interval (e.g. monthly).
    • Insert code: The code searches for existing data records and calculates the missing values.

    Example code:

    records = env['res.partner'].search([('is_company', '=', True), ('x_studio_custom_field', '=', False)])
    
    for record in records:
        if record.id:
            record.write({'x_studio_custom_field': 'K' + str(record.id)})
    

    This code searches for all contacts that are companies and for which the “Customer number” field is still empty. It then fills in these fields accordingly.

    Summary

    By automating calculated fields, you can drastically simplify recurring tasks in Odoo, such as entering customer numbers or IDs. Automation rules ensure that new records are filled correctly right away, while scheduled actions allow you to update existing records. These methods can be applied to a variety of use cases, making your workflows more efficient and error-free.

    Olbricht IT is an official Odoo partner and offers comprehensive solutions for the Odoo CRM system. With their expertise, they help companies to develop customized automations that make business processes more efficient. You can find more information about Olbricht IT’s Odoo services here. You can also find detailed instructions on setting up automations in Odoo in the Odoo documentation.

    Dieser Beitrag ist auch verfügbar auf: Deutsch (German)

    Updated on 9. July 2025
    Was this article helpful?

    Leave a Reply

    Your email address will not be published. Required fields are marked *