Set Default Values (copy)
✏️

Set Default Values

Abstract

This article explores the benefits of setting default values in Odoo, highlighting how they enhance efficiency, reduce errors, ensure consistency, and improve user experience across business processes.


What are Default Values

In Odoo, default values refer to predefined values automatically filled in certain fields when creating new records. Default values can be set for almost any field in Odoo and have many benefits to their usage.

Why to use default values?

  • simplify data entry by providing a baseline that can be modified if needed. 
  • ensuring consistency across data entries
  • enhancing efficiency, accuracy, and consistency within business processes.
  • ensure smoother workflows and minimize manual input errors

How Default Values Work:

  • Default Values on Forms: When you open a form to create a new record (e.g., an invoice, a sales order, or a contact), some fields might already have values filled in. These are default values.
  • Example: If you're creating a new sale order, the default currency, company, and order date fields might ​already be pre-filled based on the configuration.

Predefined Odoo Defaults:

  • Odoo comes with built-in default values for several fields based on system configuration. For example:
    • The company field on records defaults to the company of the logged-in user.
    • The currency field defaults to the company’s base currency.
    • Date fields may default to the current date.

Practical Use Cases:

  • Default Payment Terms: Automatically set a default payment term for all new customers.
  • Default Salesperson: Assign a default salesperson for each new sales order.
  • Default Warehouse: Set a default warehouse for stock moves or sales orders.

Limitations:

Default values in Odoo are useful for streamlining data entry, but they do come with some limitations. Here are the main limitations of default values in Odoo:

1. Static Nature

  • Default values are static once set, meaning they don’t change dynamically based on certain conditions unless additional logic is added (like context-based defaulting).
  • For example, a default value set for a particular field will be the same for all records unless manually updated or customised through development.

2. Not Suitable for Complex Logic

  • Default values are generally meant for simple, pre-filled data. They cannot handle complex business logic without customisation.
  • If you need different default values based on specific conditions (like user roles, customer types, or sales regions), you will need to create custom server actions, automate processes, or write custom Python code.

3. Context Dependency

  • Odoo uses context to determine default values in some cases, but this can become complicated if there are multiple layers of contexts being applied.
  • In some cases, the wrong default value might be applied if the context is not correctly configured, especially if multiple customisations or modules affect the same fields.

4. Overriding Necessary Customisations

  • Setting default values for functions like pricelists may override specific customer preferences or contract terms. If a customer has a negotiated or custom pricelist, a default value can lead to discrepancies in pricing, potentially causing revenue loss or customer dissatisfaction.


How to set Default Values

Option 1 (directly via form view)

Warning: This might create data on a production if you forget to discard afterwards. 

Suggestion: Do this on staging and then export/import the created defaults.

  1. Enable Debug Mode
  2. Open Form View where you want to set a default (e.g. Contacts)
  3. Enter values that should be set as default in desired fields (e.g. a default country/language for a customer)
  4. Click on Bug Icon --> Set Defaults
    1. Choose from list of filled in fields what should be set as default
    2. Its possible to select available conditions
    3. Choose if the default value should apply to current user only or to all users
  5. To manage this default value: Go to Settings --> User Defined Defaults
  6. Discard the creation of the object when doing this on production (contact)

Option 2 (via Settings)

  1. Go to Settings --> Technical --> User-defined Defaults --> New
  2. Select the field you wanna set the default for.
  3. Set the Default Value as JSON Format. 
  4. Relational fields → ID of the related object
  5. Date → YYYY-MM-DD
  6. Text → Text 



Created by: Simon Stappen - simon.stappen@muchconsulting.de
Author: Simon Stappen - simon.stappen@muchconsulting.de
Created At: 2021-02-11T12:35:08.857Z
Updated At: 2024-10-18T14:20:41.875Z
Location: consulting/odoo-smart/set-default
Tags: default, user-defined default