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. orm
services data_display

orm

Odoo 19 services — orm (core)

Live preview Interactive
Source excerpt web/static/src/core/orm_service.js
import { registry } from "@web/core/registry";
import { rpc } from "@web/core/network/rpc";
import { user } from "@web/core/user";
import { Domain } from "@web/core/domain";

/**
 * This ORM service is the standard way to interact with the ORM in python from
 * the javascript codebase.
 */

// -----------------------------------------------------------------------------
// ORM
// -----------------------------------------------------------------------------

/**
 * One2many and Many2many fields expect a special command to manipulate the
 * relation they implement.
 *
 * Internally, each command is a 3-elements tuple where the first element is a
 * mandatory integer that identifies the command, the second element is either
 * the related record id to apply the command on (commands update, delete,
 * unlink and link) either 0 (commands create, clear and set), the third
 * element is either the ``values`` to write on the record (commands create
 * and update) either the new ``ids`` list of related records (command set),
 * either 0 (commands delete, unlink, link, and clear).
 */
export const x2ManyCommands = {
    // (0, virtualID | false, { values })
    CREATE: 0,
    create(virtualID, values) {
        delete values.id;
        return [x2ManyCommands.CREATE, virtualID || false, values];
    },
    // (1, id, { values })
    UPDATE: 1,
    update(id, values) {
        delete values.id;
        return [x2ManyCommands.UPDATE, id, values];
    },
    // (2, id[, _])
    DELETE: 2,
    delete(id) {
        return [x2ManyCommands.DELETE, id, false];
    },
    // (3, id[, _]) removes relation, but not linked record itself
    UNLINK: 3,
    unlink(id) {
        return [x2ManyCommands.UNLINK, id, false];
    },
    // (4, id[, _])
    LINK: 4,
    link(id) {
        return [x2ManyCommands.LINK, id, false];
    },
    // (5[, _[, _]])
    CLEAR: 5,
    clear() {
        return [x2ManyCommands.CLEAR, false, false];
    },
    // (6, _, ids) replaces all linked records with provided ids
    SET: 6,
    set(ids) {
        return [x2ManyCommands.SET, false, ids];
    },
};

function validateModel(value) {
    if (typeof value !== "string" || value.length === 0) {
        throw new Error(`Invalid model name: ${value}`);
    }
}
function validatePrimitiveList(name, type, value) {
    if (!Array.isArray(value) || value.some((val) => typeof val !== type)) {
        throw new Error(`Invalid ${name} list: ${value}`);
    }
}
function validateObject(name, obj) {
    if (typeof obj !== "object" || obj === null || Array.isArray(obj)) {
        throw new Error(`${name} should be an object`);
    }
}
function validateArray(name, array) {
    if (!Array.isArray(array)) {
        throw new Error(`${name} should be an array`);
    }
}

export const UPDATE_METHODS = [
    "unlink",
    "create",
    "write",
    "web_save",
    "web_save_multi",
    "action_archive",
    "action_unarchive",
];

export class ORM {
    constructor() {
        this.rpc = rpc; // to be overridable by the SampleORM
        /** @protected */
        this._silent = false;
        this._cache = false;
    }

    /** @returns {ORM} */
    get silent() {
        return Object.assign(Object.create(this), { _silent: true });
    }

    /**
     * @param {object} options
     * @returns {ORM}
     */
    cache(options = {}) {
        return Object.assign(Object.create(this), { _cache: options });
    }

    /**
     * @param {string} model
Registry / API
Registry name
orm
Category
services
Module
web
Slug
orm
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