Skip to Content
Logo of RG Logo of RG
  • Home
  • Shop
  • Events
  • Courses
  • Company
    • News
    • Success Stories
  • Odoo Docs 19
  • Appointment
  • Jobs
  • Contact us
  • 0
  • 0
  • +1 555-555-5556
  • Sign in
Logo of RG Logo of RG
  • 0
  • 0
    • Home
    • Shop
    • Events
    • Courses
    • Company
      • News
      • Success Stories
    • Odoo Docs 19
    • Appointment
    • Jobs
    • Contact us
  • +1 555-555-5556
  • Sign in
Odoo Docs 19
Home Components Guides Classes Search
418 components
Data Display
  • action
  • Action Container
  • Action Helper
  • Action Menus
  • Animated Number
  • Attach Document
  • Attach Document Widget
  • Barcode Video Scanner
  • Base Settings
  • Block UI
  • Block UI
  • Breadcrumbs
  • Burger Menu
  • Button Box
  • calendar
  • Calendar Common Renderer
  • Calendar Controller
  • Calendar Filter Section
  • Calendar Mobile Filter Panel
  • Calendar Quick Create
  • Calendar Renderer
  • Calendar Side Panel
  • Calendar Year Renderer
  • Code Editor
  • Color List
  • Column Progress
  • command
  • Command Palette
  • Control Panel
  • Copy Button
  • Crop Overlay
  • currency
  • Custom Favorite Item
  • Custom Group By Item
  • Debug Menu Basic
  • Default Command Item
  • Demo Data
  • Display Exception
  • Display Notification
  • Documentation Link
  • Domain Selector
  • Dropzone
  • effect
  • emoji
  • Emoji Picker
  • error
  • Error Handler
  • Export All
  • Expression Editor
  • field
  • File Upload
  • File Upload Progress Bar
  • File Upload Progress Container
  • File Upload Progress Record
  • File Viewer
  • form
  • Form Controller
  • Form Label
  • Form Renderer
  • Form Status Indicator
  • Graph Controller
  • Graph Renderer
  • Group Config Menu
  • Highlight Text
  • home
  • hotkey
  • Hotkey Command Item
  • http
  • Input
  • In Range
  • Install Kiosk
  • Install Kiosk Pwa
  • Install Prompt
  • Install Scoped App
  • Install Scoped App
  • kanban
  • Kanban Column Quick Create
  • Kanban Controller
  • Kanban Header
  • Kanban Quick Create Controller
  • Kanban Record
  • Kanban Record Quick Create
  • Kanban Renderer
  • Lazy Component
  • Lazy Session
  • list
  • List Controller
  • List Renderer
  • Loading Indicator
  • Loading Indicator
  • localization
  • Main Components Container
  • menu
  • Model Field Selector
  • Model Selector
  • Multi Record Selector
  • Multi Selection Buttons
  • name
  • Name And Signature
  • Notebook
  • orm
  • Overlay Container
  • Pager
  • Pager Indicator
  • Pager Indicator
  • Pivot Controller
  • Pivot Renderer
  • profiling
  • Profiling Item
  • Properties Group By Item
  • Rainbow Man
  • Range
  • Record Selector
  • reload
  • reload Company
  • Reload Context
  • Report Action
  • Report View Measures
  • Res Config Dev Tool
  • Res Config Edition
  • Res Config Invite Users
  • Resizable Panel
  • Ribbon Widget
  • Search Bar
  • Search Bar Menu
  • Search Bar Toggler
  • Search Panel
  • Select
  • Selection Box
  • Select Menu
  • Setting
  • Settings App
  • Settings Block
  • Settings Page
  • share Target
  • signature
  • Signature Widget
  • Soft Reload
  • sortable
  • Status Bar Buttons
  • swallow All Visitor Errors
  • Switch Company Item
  • Switch Company Menu
  • Switch Company Menu
  • Tags List
  • Time Picker
  • title
  • Transition
  • Tree Editor
  • Tree Processor
  • ui
  • User Invite
  • User Menu
  • User Menu
  • User Switch
  • User Switch
  • view
  • View Button
  • View Scale Selector
  • Web Client
  • Web Ribbon
  • Week Days
  • Widget
  • With Search
  1. Components
  2. Expression Editor
OWL data_display

Expression Editor

Odoo 19 OWL component — Expression Editor (core)

Live preview Interactive
Source excerpt web/static/src/core/expression_editor/expression_editor.js
import { Component, onWillStart, onWillUpdateProps } from "@odoo/owl";
import { getExpressionDisplayedOperators } from "@web/core/expression_editor/expression_editor_operator_editor";
import { _t } from "@web/core/l10n/translation";
import { ModelFieldSelector } from "@web/core/model_field_selector/model_field_selector";
import { condition } from "@web/core/tree_editor/condition_tree";
import { expressionFromTree } from "@web/core/tree_editor/expression_from_tree";
import { TreeEditor } from "@web/core/tree_editor/tree_editor";
import { getOperatorEditorInfo } from "@web/core/tree_editor/tree_editor_operator_editor";
import { getDefaultValue } from "@web/core/tree_editor/tree_editor_value_editors";
import { treeFromExpression } from "@web/core/tree_editor/tree_from_expression";
import { getDefaultPath } from "@web/core/tree_editor/utils";

export class ExpressionEditor extends Component {
    static template = "web.ExpressionEditor";
    static components = { TreeEditor };
    static props = {
        resModel: String,
        fields: Object,
        expression: String,
        update: Function,
    };

    setup() {
        onWillStart(() => this.onPropsUpdated(this.props));
        onWillUpdateProps((nextProps) => this.onPropsUpdated(nextProps));
    }

    async onPropsUpdated(props) {
        this.filteredFields = Object.fromEntries(
            Object.entries(props.fields).filter(([_, fieldDef]) => fieldDef.type !== "properties")
        );
        try {
            this.tree = treeFromExpression(props.expression, {
                getFieldDef: (name) => this.getFieldDef(name, props),
                distributeNot: !this.isDebugMode,
                generateSmartDates: false,
            });
        } catch {
            this.tree = null;
        }
    }

    getFieldDef(name, props = this.props) {
        if (typeof name === "string") {
            return props.fields[name] || null;
        }
        return null;
    }

    getDefaultCondition() {
        const defaultPath = getDefaultPath(this.filteredFields);
        const fieldDef = this.filteredFields[defaultPath];
        const operator = getExpressionDisplayedOperators(fieldDef)[0];
        const value = getDefaultValue(fieldDef, operator);
        return condition(fieldDef.name, operator, value);
    }

    getDefaultOperator(fieldDef) {
        return getExpressionDisplayedOperators(fieldDef)[0];
    }

    getOperatorEditorInfo(fieldDef) {
        const operators = getExpressionDisplayedOperators(fieldDef);
        return getOperatorEditorInfo(operators, fieldDef);
    }

    getPathEditorInfo(resModel, defaultCondition) {
        if (resModel !== this.props.resModel) {
            throw new Error(
                `Expression editor doesn't support tree as value so resModel has to be props.resModel`
            );
        }
        return {
            component: ModelFieldSelector,
            extractProps: ({ value, update }) => ({
                path: value,
                update,
                resModel: this.props.resModel,
                readonly: false,
                filter: (fieldDef) => fieldDef.name in this.filteredFields,
                showDebugInput: false,
                followRelations: false,
                isDebugMode: this.isDebugMode,
            }),
            isSupported: (value) => [0, 1].includes(value) || value in this.filteredFields,
            // by construction, all values received by the path editor are O/1 or a field (name) in this.props.fields.
            // (see _leafFromAST in condition_tree.js)
            stringify: (value) => this.props.fields[value].string,
            defaultValue: () => defaultCondition.path,
            message: _t("Field properties not supported"),
        };
    }

    get isDebugMode() {
        return !!this.env.debug;
    }

    onExpressionChange(expression) {
        this.props.update(expression);
    }

    resetExpression() {
        this.props.update("True");
    }

    update(tree) {
        const expression = expressionFromTree(tree, {
            getFieldDef: (name) => this.getFieldDef(name),
            generateSmartDates: false,
        });
        this.props.update(expression);
    }
}
Registry / API
Registry name
ExpressionEditor
Category
—
Module
web
Slug
expression-editor
Nav group
data_display
Follow us

250 Executive Park Blvd, Suite 3400
San Francisco CA 94134

  • +1 555-555-5556
  • info@yourcompany.example.com
Copyright © Company name
Powered by Odoo - The #1 Open Source eCommerce