Skip to content
ERPForAll DocsDevelopment

    Actions and menus

    Status: implemented. Addon base has the action models (ir.actions.act_window, act_url, client, server), their key table ir.actions.actions, the contextual-action lookup get_bindings and the menu model ir.ui.menu; server actions run (see “Running server actions”), including code actions. The web client’s /web/action/load and load_menus are not served yet. Design: docs/design/m2-s3.md §3, §6; ADR 0058 (the shared id sequence). Specs: SPEC-DATA-062, 063, 064 in docs/specs/data/data-views-api.md.

    Field names are Odoo’s, so the data files you port from Odoo load unchanged:

    <record id="action_partner" model="ir.actions.act_window">
    <field name="name">Contacts</field>
    <field name="res_model">res.partner</field>
    <field name="view_mode">list,form,kanban</field>
    <field name="path">contacts</field>
    </record>
    <menuitem id="menu_contacts" name="Contacts" action="action_partner" sequence="10"/>

    Each action type has its own table (ir_act_window, ir_act_url, ir_act_client, ir_act_server), and all of them draw their ids from one sequence, ir_actions_id_seq (#[model(..., id_sequence = ACTIONS_ID_SEQUENCE)], see models.md). So an action id names exactly one action of any type, as in Odoo. The key table ir_actions (ir.actions.actions) has one row per action: its id, type (the typed model, e.g. ir.actions.act_window), name, path and the binding columns. The typed models’ create and write keep it in step in the same statement batch, and a follow-delete trigger on every typed table removes the key rows of every deleted action, also of the ones a foreign key deletes by cascade (a multi action’s children, the actions of a deleted model or field). Writing ir.actions.actions directly is refused with Programming “ir.actions.actions rows follow their typed action; write the typed action instead”, and so is upsert on any action model (it does not run create).

    A new action type of your addon inherits ir.actions.base, names the same sequence and declares the trigger; create refuses an action model without both, and so does the final registry (erp_addon_base::ir_actions::check_action_model):

    # erp_sdk::addon!(name = "actions_guide", depends = ["base"]);
    use erp_sdk::prelude::*;
    use erp_addon_base::ir_actions::{ACTIONS_CACHE, ACTIONS_ID_SEQUENCE, IrActionsBase};
    /// An action that opens a dashboard.
    #[model(
    name = "actions_guide.dashboard_action",
    description = "Dashboard Action",
    table = "actions_guide_dashboard_action",
    inherit = [IrActionsBase],
    id_sequence = ACTIONS_ID_SEQUENCE,
    follow_deletes = [("_keys_follow", cache = ACTIONS_CACHE, key_table = "ir_actions")]
    )]
    pub struct DashboardAction {
    /// The dashboard to open.
    #[field(char, required = true)]
    pub dashboard: Option<Arc<str>>,
    }
    # fn main() {}

    type is set from the model on create; a different value is a Validation error. To find which type an id belongs to, erp_addon_base::ir_actions::action_by_id(tx, id) reads the key table (one statement) and returns an ActionRef whose model is checked against the registry.

    Inserts and updates that go around the ORM (migration SQL on an action table) must keep ir_actions in step and invalidate the actions named cache themselves; deletes are followed by the trigger, but the deleting transaction itself sees the change only when the ORM made it. get_bindings refuses a key row whose typed row is missing, naming both tables. run_as_superuser is set only by an administrator on an action with groups (see “Running server actions”).

    path is the URL segment the web client shows for an action. It must match [a-z][a-z0-9_-]*, must not start with m- or action-, must not be new, and is at most 128 bytes; each rule has Odoo’s message, checked before anything is written (erp_addon_base::ir_actions::check_path, typed error ActionPathError):

    use erp_addon_base::ir_actions::{ActionPathError, check_path};
    fn main() {
    assert_eq!(check_path("contacts"), Ok(()));
    assert_eq!(check_path("Contacts"), Err(ActionPathError::Format));
    assert_eq!(check_path("action-7"), Err(ActionPathError::ReservedAction));
    }

    An empty path is a format error (leave the field unset instead; Odoo would store ''). A path is unique across all action types: the unique index _path_unique of ir_actions decides, so two transactions saving the same path on two types cannot both commit. The second waits for the first and then fails with Validation “Path to show in the URL must be unique! Please choose another one.” (Odoo checks with a count query, which two transactions can pass together.)

    views is computed: first one (view, type) per view_ids row, then each type of view_mode that no row gives, the action’s view_id first when its type is one of them, the others with false. With view_mode = "list,form,kanban", view_id a form view F and a view_ids row for a kanban view K, views is [[K, "kanban"], [F, "form"], [false, "list"]].

    view_mode must not repeat a type (“The modes in view_mode must not be duplicated: […]”) and must not contain whitespace or an empty type (“No spaces allowed in view_mode: “[…]””). Odoo lets "list, form" and "list,,form" through (BUG-072); we do not. At most 32 types and 256 bytes. Unknown types are accepted, as in Odoo. res_model and the binding model must be models of the registry (“Invalid model name “x” in action definition.”); without a name, the action takes its model’s description.

    A window action opened in the web client may carry default values for the records created from it:

    <record id="action_move_out_invoice_type" model="ir.actions.act_window">
    <field name="name">Invoices</field>
    <field name="res_model">account.move</field>
    <field name="view_mode">list,form</field>
    <field name="context">{'default_move_type': 'out_invoice'}</field>
    </record>

    The web server (erp_load_web_action, erp_load_web_action_views, erp_load_web_action_ref) admits the context only as a literal dictionary of at most 16 keys, each default_<field> naming a field of res_model, each value a text, a boolean or an integer within the browser’s safe range. The client adds it to the session context, so the list’s New button and a form opened from the menu start with those values; a dashboard card’s own context comes after it, and a session key always keeps the session’s value. Everything else is refused by name when the action is loaded: an expression (uid, context.get(...)), a list or a negative number as a value, a key that names no field, a repeated key, session keys such as allowed_company_ids, and search_default_<name> (default search filters of an action are not delivered yet).

    A default must also be one the field can take. A key that names a readonly, computed or related field, a one2many or many2many field, or a field of a type without a literal form here (binary, json, reference and the like) is refused. The value must fit the field’s type:

    Field typeValue
    booleanTrue or False
    integeran integer
    many2onea record id: an integer above zero
    float, monetaryan integer (the context admits no decimal literal)
    char, text, htmla text
    selectiona text; one of the declared values when the selection is a static list
    datea text of the form YYYY-MM-DD
    datetimea text of the form YYYY-MM-DD HH:MM:SS

    For dates only the form is checked when the action is loaded. An empty {} is the same as no context.

    An action with binding_model_id shows in that model’s action menu (binding_type = "action") or print menu ("report"), in the view types of binding_view_types:

    # #![recursion_limit = "256"]
    # erp_sdk::addon!(name = "bindings_guide", depends = ["base"]);
    use erp_sdk::prelude::*;
    async fn menu_entries(tx: &mut Transaction) -> Result<Vec<String>> {
    let env = tx.env();
    let bindings = erp_addon_base::ir_actions::get_bindings(tx, &env, "res.groups").await?;
    Ok(bindings
    .action()
    .iter()
    .map(|b| format!("{}: {:?}", b.id(), b.values().get("name")))
    .collect())
    }
    # fn main() {}

    Each binding’s values are id, name, binding_view_types, and sequence and domain where the action type has them (an empty domain is left out). action bindings are sorted by sequence (absent: 0), then id. A binding with group_ids shows only to members of one of them (base.group_no_one only in debug mode); a binding with a res_model shows only when the user may read that model. The part that is the same for everyone is cached per model in the named cache actions, which every action write invalidates, in every process (the signal generations); a cold call costs one statement on ir_actions plus one per action type present, a warm call none. Group membership is checked per call, so joining a group needs no invalidation. A model name the registry does not have is a Validation error.

    ir.ui.menu has Odoo’s fields: name, active, sequence (default 10), parent_id (ondelete = restrict: a menu with children cannot be deleted), child_id, group_ids (ir_ui_menu_group_rel), web_icon and action, a reference "<action model>,<id>" over the four action models. The tree is a parent store: a cycle is refused with “This parent would make a loop in the ‘Menu’ records: …”. The <menuitem> shorthand of data files writes these records (data-files.md). Which menus a user sees is decided by the web client’s menu loading, which is not available yet.

    A report is an ir.actions.report record plus a QWeb view whose key is the report’s report_name. Both load from your data files; the action shares the id space of the other action types and shows under Settings > Technical > Reporting > Reports. Paper formats (report.paperformat) are under Paper Format next to it.

    <record id="report_order_view" model="ir.ui.view">
    <field name="name">my_addon.report_order</field>
    <field name="type">qweb</field>
    <field name="key">my_addon.report_order</field>
    <field name="arch" type="xml">
    <t t-name="my_addon.report_order">
    <t t-foreach="docs" t-as="doc"><p t-field="doc.name"/></t>
    </t>
    </field>
    </record>
    <record id="report_order" model="ir.actions.report">
    <field name="name">Order</field>
    <field name="model">my_addon.order</field>
    <field name="report_type">qweb-pdf</field>
    <field name="report_name">my_addon.report_order</field>
    <field name="print_report_name">'Order ' + object.name</field>
    <field name="paperformat_id" ref="base.paperformat_euro"/>
    <field name="binding_model_id" ref="model_my_addon_order"/>
    <field name="binding_type">report</field>
    </record>
    FieldMeaning
    model (required)the model printed; must be in the registry
    report_typeqweb-pdf (default), qweb-html or qweb-text
    report_name (required)the key of the QWeb template
    paperformat_ida report.paperformat; empty: the company’s, then base.paperformat_euro
    print_report_nameexpression over object and time giving the download name; empty: name
    binding_model_id, binding_type=reportlists the report when printing records of that model; create_action and unlink_action (the form’s “Offer when printing” and “Stop offering when printing”) set and clear it
    binding_view_types, multiwhere the Print menu offers it; multi hides it on a form
    group_ids, domainwho and which records see it in the Print menu
    save_as_attachment, attachment, attachment_usekeep the printed file as an attachment named by the attachment expression, and print it again instead of rendering
    allow_attachment_group_fieldsacknowledges that a kept attachment shows group-restricted fields as the first printer saw them

    Base ships three paper formats: base.paperformat_euro (A4), base.paperformat_us (US Letter) and base.paperformat_batch_deposit.

    Checked when the action or its template loads, each refusal naming the report:

    • print_report_name and attachment must parse as expressions; save_as_attachment needs an attachment expression.
    • For qweb-pdf and qweb-html, the template and every template it calls by a literal t-call must stay inside the print profile (crates/erp-report/src/profile.rs).
    • With an attachment expression, a template that prints a field limited to groups is refused unless allow_attachment_group_fields is set.
    • At the end of the install or upgrade, a template (or called template) that is not an active QWeb view of the database is refused: Report 'Order' (my_addon.report_order): template '...' is not an active QWeb view of this database.

    Printing: a list with selected records and a record form each show a Print button before the Actions menu. It lists the reports of the model (erp_print_reports) by name, a model without a report shows “No report available”, and the Actions menu never holds reports. On a form, picking a report saves unsaved changes first and then prints that one record. report_action returns the client action (type, name, report_name, report_type, context.active_ids, data).

    Actions and menus live in PostgreSQL only. The bindings cache is per process and rebuilt on demand; another process’s action write reaches it through the cache:actions generation, read by the opening flight of each transaction before any cached value is used.

    erp_addon_base::server_action::run_server_action(tx, env, &RunRequest::new(action_id, active_model, &active_ids)) runs one ir.actions.server action and returns the action it asks the client to open, if any (ActionResult). It runs as the caller: the access check, every child of a multi action and every write use the caller’s environment, never superuser, unless the action carries the administrator-only run_as_superuser flag (ADR 0009 §10; Odoo checks the caller and then runs as superuser). An action with groups needs the caller in one of them; one without needs write access on its model and the active records. A flagged action’s run is audited: see the audit trail.

    Before the first runner starts, the action and its whole tree of children are read in one statement and checked: at most 8 levels (MAX_DEPTH) and 256 actions (MAX_ACTIONS), no warnings (a child on another model, children with other groups, a sequence on a non-text field, …), a runner for every type, and every stored selection set (evaluation_type on object_write, update_m2m_operation on an x2many target). An error after that point (a child’s access check, a write) can come after an earlier child wrote: roll back the transaction on every error.

    Stored action data is bounded before it reaches the client driver: each selected text field may contain at most 65,536 UTF-8 bytes, each action at most 256 group IDs, and the tree at most 1,048,576 logical payload bytes (text plus eight bytes per group ID). Exceeding a bound returns a typed Limit error; group lists are never truncated. An update path may contain at most 16 dot-separated steps.

    The runner’s active_model, active_ids and active_id describe the current request. An empty request removes active_id, including a value inherited from the caller’s context, while preserving unrelated context keys. The caller’s original environment is unchanged.

    Outside superuser mode, the guard for mutations of a flagged action tree permits at most 256 distinct actions across the affected ancestor/descendant set. Larger sets are refused before locking; unlink checks the caller’s model and record permissions first. Stored parent chains are checked after create, including links supplied by default_parent_id in loader or sudo contexts.

    Built in: object_write, object_create, multi, and sandboxed Luau code/equations (script API). object_copy and webhook (both planned) return ServerActionError::Unsupported. run_as_superuser = true is written only by an administrator, on an action with groups; changing the tree of a flagged action also needs base.group_system. Running a flagged action records the elevation in the audit trail before the elevated body runs: the caller’s right to run it is checked first, then the node and its subtree run with superuser mode, and a run whose audit row cannot be written does not start.

    An addon adds a value to ir.actions.server.state with selection_add and declares its runner (Odoo’s _run_action_<state>[_multi]):

    use erp_addon_base::server_action::{ActionResult, RunnerCtx};
    use erp_sdk::{BoxFuture, Result, serde_json::json};
    erp_sdk::addon!(name = "action_demo", depends = ["base"]);
    fn open_record(ctx: RunnerCtx<'_>) -> BoxFuture<'_, Result<Option<ActionResult>>> {
    Box::pin(async move {
    let id = ctx.records().ids()[0];
    Ok(Some(ActionResult::new(json!({
    "type": "ir.actions.act_url",
    "url": format!("/record/{id}"),
    }))?))
    })
    }
    erp_addon_base::server_action_runner!(
    OPEN_RECORD = { state: "x_open_record", multi: false, run: open_record }
    );
    # fn main() {}

    multi: false runs once per active record (its id in the context as active_id), multi: true once for all. The declaration belongs to the declaring crate’s ADDON (or addon: OTHER_ADDON) and counts only when that addon is installed. Registry setup (check_runners, from _register_hook of ir.actions.server) refuses two runners for one state and a runner whose state is not in the selection, naming each declaration’s file:line, and a state without a runner, naming the state. A runner writes only through ctx.env() and ctx.tx(), never sudo.

    Section titled “Method results opening a related list (ADR 0107)”

    Implementation acceptance for this new contract is pending. An exposed main-form object method can return a literal action such as:

    {
    "type": "ir.actions.act_window",
    "name": "Related records",
    "res_model": "my_addon.line",
    "target": "current",
    "views": [[false, "list"], [false, "form"]],
    "domain": [["parent_id", "=", 42]],
    "context": {"default_parent_id": 42}
    }

    In real code derive the parent id from the authorized singleton. The numbers above illustrate syntax; they are not a shipped provider or real count. Check the source record’s read permission in your method. The normalizer admits the target model and domain fields under the caller, and every later ORM read enforces current record rules and company selection. A domain filters the action; it is not a grant and does not replace model security. Admission uses ordinary read-only search planning, including registered search-domain hooks. Those hooks can run during normalization and again during later searches; keep them read-only and do not treat normalization as a single execution of a business action.

    Only literal domains, list optionally followed by form, and default_<field> values naming real target fields are supported. A current-window result may also carry the booleans active_test and create; create: False hides New in the opened list, as Odoo does. The opened list’s breadcrumb leads back to the record whose button opened it. Company/user/locale/server context, expressions, services, res_id, view_mode aliases and current-list results from a dialog are refused. Integral numeric literals must fit the browser’s safe integer range; use the field’s supported string representation for exact decimal values. Existing target: "new" form dialogs keep their existing syntax.

    The source is saved and validated before its object method runs. A destination failure is reported without repeating that method; the source is refreshed. The base domain survives list search clearing, paging and form/list navigation. Field defaults and caller context travel with that action, including new-record creation.

    The URL contains only a page-lifetime action identity. Back/forward in the same page can reuse it. Reload, copying the URL into another tab, state eviction or authority/metadata lifetime changes can expire it; an explicit error asks the user to reopen the originating menu, with a recovery link on an initially expired route. No raw action JSON or domain is placed in the URL, and expired state never opens an unfiltered list. The page keeps at most 64 entries, each bounded to 32 KiB serialized state.

    This framework change does not add a sample Library loan counter. A correct related count must use a separately admitted aggregate under the caller’s rules, including target-model Read when zero rows match. Historical event counters and relation-id materialization are not substitutes for that provider.

    The web client loads the menu tree via ir.ui.menu.erp_load_web_menus (JSON-2 endpoint, Read access).

    Every returned menu node includes module: string | null, including application roots. This is the nonempty namespace of the oldest ir.model.data row (lowest row ID) whose model is ir.ui.menu and whose res_id is that menu. No provenance, or an empty namespace on that selected row, returns explicit null. A child uses its own provenance; it does not inherit the root’s module. Later external-ID aliases do not replace the selected namespace. Names, icons and action targets do not determine the module.

    This read never generates an external ID. An ordinary user can receive module metadata for an authorized menu without direct access to ir.model.data. The value grants no permission and does not prove that an addon is installed. Existing menu, action and target-model access still determines the returned forest. Module text shares the request budget and is limited to 4096 bytes. Settings-rail rendering is delivered separately.

    Key capabilities on ir.ui.menu:

    • complete_name: Computed breadcrumb path of the menu (e.g. "Sales / Configuration / Settings"), computed hierarchical path joined with " / ".
    • _visible_menu_ids(debug): ORM method returning the set of menu IDs visible to the calling user based on:
      • Active flag (active = true)
      • ACL read permissions on ir.ui.menu
      • Group membership in group_ids
      • Deep visibility: a menu with an action is visible if the user has access; a parent folder menu is visible only if at least one of its children or descendants is visible.

    Menu trees (wire::MenuTree) are evaluated directly per request within the caller’s authenticated transaction and REPEATABLE READ snapshot. Ad-hoc in-memory caching was removed (ADR 0060 D3/D5, review WM-01/02) to eliminate authority collisions across principals, group revocations, company context, and database snapshot boundaries.

    Evaluation invariants:

    • Bounded capacity: Enforces MAX_MENU_ROWS = 4096 and MAX_TREE_DEPTH = 32.
    • Cycle detection: Fails loudly on menu hierarchy cycles.
    • Action access reachability: Replaces raw SQL with authenticated ORM record checks (ir.actions.act_window record rules and target model Read permissions).
    • Descendant pruning: Menus without an accessible action and folder menus with no authorized action descendant are pruned from the returned tree.
    • Budget enforcement: Response payload serialization is metered through ResponseAdmission and DescriptionEncoder, sharing the request’s DescriptionBudget under the 8 MiB ceiling.