Skip to content
ERPForAll DocsDevelopment

    Data files (XML and CSV)

    Status: data parsing and loading are complete (crates/erp-data, crates/erp-modules). The loader turns your XML and CSV data files into transactional operations, assigns external IDs (ir.model.data), enforces noupdate and forcecreate semantics, executes <function> calls and <delete> statements, registers views and templates, and automatically cleans up obsolete records on module upgrade and uninstallation.

    ERP data files retain Odoo input compatibility: an addon written for Odoo reads the same way, with the stricter checks below (ADR 0019). Every rule here is enforced when the file is read, before anything reaches the database.

    Per project rules (AGENTS.md “Default data for every model”), every model defined by a base addon (including uom) ships default records like Odoo in its data files (data/*.xml or data/*.csv), with an install test confirming the records exist after erp module install. Default data files are marked with noupdate="1" in XML files (<erp noupdate="1">) or # noupdate: 1 as the first line of CSV files so that tenant modifications are preserved across module upgrades without creating duplicate rows or resetting operator changes.

    The canonical root is <erp>; legacy <odoo>, <openerp> and <data> roots remain accepted input aliases. Containers nest and take noupdate, auto_sequence, uid and context. Inside: record, template, asset, menuitem, delete, function.

    <erp noupdate="1" context="{'tracking_disable': True}">
    <record id="tag_vip" model="res.partner.category">
    <field name="name">VIP</field>
    <field name="parent_id" ref="base.res_partner_category_0"/>
    <field name="color" type="int">3</field>
    <field name="image_1920" type="bytes" file="my_addon/static/img/vip.png"/>
    </record>
    <menuitem id="menu_root" name="My Addon" web_icon="my_addon,static/description/icon.png">
    <menuitem id="menu_tags" action="action_tags"/>
    </menuitem>
    <template id="badge" name="Badge"><span class="badge" t-out="name"/></template>
    </erp>

    What the reader checks, beyond well-formed XML:

    • Allowed elements and attributes only, per element, as in Odoo’s import_xml.rng. A typo (<feild>, modle=) stops the file with “does not fit the required schema” and the line.
    • One value source per field: ref, eval or search, or a type with text or file. model goes with eval/search, use with search. Text next to eval is refused.
    • File values: type="bytes" file="path" (binary, preferred; type="base64" still read), type="file" with the path as text (stored as module,path), file="path" without type (the file’s text).
    • Markup: put view architectures in type="xml" and HTML in type="html"; markup in a field without a type is refused (it would lose its structure). HTML void elements (<br/>, <img/>) must be empty.
    • Booleans (noupdate, forcecreate, menu active, …): 1/0, true/false, yes/no, on/off in any case. On <template>/<asset>, active and customize_show must be exactly True or False.
    • Integers (sequence, priority, type="int", type="float") must parse.
    • External IDs: name or module.name, one dot at most, no spaces; the module part is a module name. An empty optional attribute (ref="", id="") counts as not written, as in Odoo.
    • Menus: a nested menu takes the enclosing menu as parent (no parent, no web_icon); web_icon is for root menus only; a submenu has either an action or child menus. groups="a,-b" links a, unlinks b. web_icon="lucide:<name>" picks one of the icons the web client ships (web/vendor/lucide/icons/, the same list the Technical › Menus form offers in its icon picker); a name it does not ship shows the default layout-grid icon and a console warning, and a test fails for any shipped addon that names one. Give a child menu its own icon by updating the same external ID after the menu declaration: <record id="menu_orders" model="ir.ui.menu"><field name="web_icon">lucide:clipboard-list</field></record>. Both the top navigation and the Office Blue sidebar use this value. Pick an icon for the destination, including intermediate groups. A missing icon falls back to the generic menu icon.
    • Templates: groups can only add groups (no -group); primary="True" needs inherit_id.
    • Functions: method names with __ or Odoo’s unsafe names are refused; a nested <function> runs with its parent’s user and context, so it cannot set its own.
    • Comments inside text values (<field name="n">Hello<!-- c --> World</field>) are refused: Odoo keeps only the text before the comment. Comments inside type="xml"/type="html" markup are kept.
    • Entities: only &amp; &lt; &gt; &quot; &apos; and character references; no DOCTYPE.
    • Size: nesting up to 256 levels, one operation up to 32 MiB of source.

    uid and context stack: the innermost uid wins and contexts are merged from the outer container inwards. auto_sequence="1" applies to the records directly in that container, not to nested containers.

    The file name gives the model (ir.model.access.csv, res.partner-extra.csv → res.partner). The first line holds the field paths for load() (id, name, group_id:id, model_id/id, …), kept exactly as written. Columns with @ (translations) are skipped, as are rows whose cells are all empty. An empty or repeated header, a row with a different number of cells, or an invalid external ID in the id column stops the file with its line. On upgrade, a file without an id column is skipped with a reason.

    Errors name the file, the line and what is wrong, for example:

    The XML file 'my_addon/data/tags.xml' does not fit the required schema!
    my_addon/data/tags.xml:12: unknown attribute 'modle' on <record>; allowed: id, model, forcecreate, uid, context

    Value errors also show the operation they occurred in (up to 2 KiB of it):

    while parsing my_addon/data/tags.xml:14, somewhere inside
    <record id="tag_vip" model="res.partner.category">…</record>
    invalid integer 'three' in <field>: invalid digit found in string

    The module system loads the files of data (and, for modules with demo data, demo) in the operation’s transaction, through the default ErpDataLoader. An error anywhere rolls the whole operation back.

    File kinds (by extension, case-insensitive): .xml and .csv are loaded; .sql is run as written (one round trip, development-folder addons only; a COMMIT in it fails the operation); .js is listed and ignored (not even read); anything else fails with can't load unknown file type … (expected .xml, .csv, .sql or .js). A file listed twice in one list loads twice.

    Modes. Install and reinit load in init mode (every record is written); an upgrade loads in update mode, which leaves records under noupdate alone:

    • A record under noupdate (its <data noupdate="1"> or <erp noupdate="1">) that already exists is not written, and neither are the <record id=…> sub-records inside it; their external ids still count as loaded. A noupdate record without an id is skipped. A noupdate record the user deleted is created again (its external id is re-pointed), unless it says forcecreate="0".
    • The noupdate flag of an external id is fixed when the id is created; loading never changes it.
    • An external id of another module (<record id="other.x">) updates that module’s record; the module must be part of the install step (The ID "other.x" refers to an uninstalled module), and the record must exist (Cannot update missing record 'other.x') unless the record says forcecreate="1".
    • A ref="x" that does not resolve fails the load (External ID not found in the system: m.x); on a record with forcecreate="0" the record is skipped instead and the skip is returned as a notice.
    • <field name="lines"><record …/></field> on a one2many field creates the parent first, then each sub-record with the inverse field set, depth first.
    • auto_sequence="1" on <erp> or <data> numbers the records of a model with a sequence field that give none: 10, 20, 30, … within one top-level record and the sub-records nested in it, restarting for the next top-level record (as Odoo does); a skipped record does not take a number.
    • At the end of an operation the records of the updated modules whose external ids the data no longer names are deleted (a record that another external id still names only loses this one; noupdate ids and the schema records of the module system are never touched).

    Consecutive records of one model are written together: a file of 1,000 records costs a handful of statements, not thousands. A failure of such a write is reported at the first record of the batch and says how many records were written together.

    <record>. Fields convert by the field’s type: text to integer, float, boolean (0, false, off are false) and many2one ids; ref="x" gives the id of an external id (the model and id, model,id, for a reference field); eval runs the expression language (ref(), Command, dates, version). The record gets an ir.model.data row module.id (flag noupdate from the enclosing <data noupdate>), and a field named xmlid is filled with it unless the file sets it. uid="ref" runs the record as that user; the context of enclosing elements and of the record are evaluated outer to inner and merged key by key, and data files never carry lang.

    Value forms. Besides text, ref= and eval, a <field> takes: search="[domain]" (with model="…", or the comodel of a relational field; use="field" picks the value read from the match): the first match for a many2one or plain field, every match for a many2many (as Command.set), False when nothing matches; type="file" (stores module,path after checking the file exists in the addon); file="module/path" (text), type="bytes" file="…" and the deprecated type="base64" file="…" (base64 text, plus a DeprecatedBase64 notice); type="list" / "tuple" of <value> elements (a None inside stays null); and type="xml" / "html", where %(xid)d and %(xid)s are replaced by the record id and %% is a literal %. A search= on a plain field without model fails with Odoo’s text Define an attribute model="..." in your .XML file!. A context that sets lang fails until translations exist.

    Menus and templates. <menuitem> writes ir.ui.menu records (parent from the enclosing menu or the parent attribute, sequence, web_icon on top-level menus, action as model,id, the name from the action when the menu has none, groups="a,-b" as link and unlink); a menu tree costs a fixed number of statements per tree level. <template> writes an ir.ui.view record (a theme.ir.ui.view record in a module named theme_*); a root active= is applied on install or for a view that does not exist yet and never on an upgrade of an existing view. Both need the real models (ir.ui.menu, ir.ui.view), which the base addon provides: a module that does not depend on base fails loading with an error that names the missing model and says to add base to depends.

    Demo data. A module gets demo data only when every module it depends on has it. All demo files of a module load inside one savepoint; if one fails on its data (a parse error, a refused value, a missing reference), the savepoint rolls back, the module installs with demo = false, and the failure is returned in OperationOutcome::data_notices as DemoFailed (and written to ir.demo_failure when that model exists). Failures of the database itself still fail the install. An administrator can load demo data into a database created without it: see Load demo data.

    Notices. Things Odoo only logs are returned in OperationOutcome::data_notices: a file listed twice (RepeatedFile), a .js file (IgnoredFile), a CSV file skipped because an upgrade found no id column (SkippedFile), a record skipped for an unresolved ref with forcecreate="0" (SkippedUnresolvedRef), a failed demo (DemoFailed).

    let outcome = system.button_immediate_install(&caller, &[module]).await?;
    for notice in &outcome.data_notices {
    eprintln!("{notice}");
    }

    <function>, <delete> and CSV files, and #[data_callable]: Calling methods and deleting from data files.

    ModuleSystem::reinit(&caller, &[module]) reloads the data of installed modules (and their installed dependents) in init mode without running migrations.