Skip to content
ERPForAll DocsDevelopment

    Tracked fields

    A field declared tracking has its changes captured by the ORM, so the mail addon can write a chatter message at commit. The ORM side produces raw old and new values; display names, formatting, the user’s time zone and the messages are the mail addon’s. Design: docs/design/m3-tracking-capture.md. Behavior: SPEC-MAIL-049..062 (every case keeps a mail-side half).

    #[field(char, tracking = true)] // sequence 100
    pub name: Option<Arc<str>>,
    #[field(selection, selection = [("draft", "Draft"), ("done", "Done")], tracking = 20)]
    pub state: Option<Arc<str>>,

    tracking = <sequence> orders a record’s changes (sequence, then field name). tracking = false switches tracking off when an extension re-declares a field. fields_get carries tracking and tracking_sequence for tracked fields only.

    The registry refuses, with the field named: tracking = 0; a field that is not stored; a one2many; a translated or company-dependent field (not supported yet); a database-generated field; a stored computed or related field (see below); a secret field (its value would land in the history and the chatter); a field of a type the history cannot store and show (json, binary and images, uuid, xid8, timestamptz, date_range, datetime_range); and more than 800 tracked fields on a model (PostgreSQL limits the RETURNING list of the flush UPDATE, which carries the old and new value of each tracked column). A WebAssembly addon cannot declare tracking yet (its loader refuses the attribute).

    • Scalar columns: the flush UPDATE returns old and new values of the tracked columns it writes (RETURNING WITH (OLD AS ..., NEW AS ...)), so capture costs no extra statement. A write that touches no tracked column keeps its statement.
    • Many2many: the id sets before and after, taken from the relation write in memory.
    • Only prepared records count. A write() of a model with tracked fields prepares its records. Records created in the transaction (including upsert inserts) or deleted in it never report changes. A write under the context key tracking_disable or mail_notrack prepares nothing; if such a write is still waiting for the flush when a tracked write of the same record follows, it is flushed first (one extra statement). Both keys are set by server-side code only (the data loader, an addon method): an RPC client cannot send them, the call is refused with context key '<key>' cannot be set by the caller (they are in the RPC’s server-only context keys).
    • An upsert that updates a row is a tracked write.
    • Changes are compared when taken: first old value, last new value; A -> B -> A is no change, and falsy values (NULL, false, 0, empty text, empty set) are equal.
    • Computed and related fields: tracking on a stored computed (or related) field is refused when the registry is built, because only write, create and upsert prepare records; a recompute prepares nothing, so the change would be silently lost. Tracking recomputed fields (Odoo prepares them on recompute) belongs to a later slice; its follow-up task must be created.
    • _inherits: a child model’s delegated copy of a tracked parent field is not itself tracked (describe shows it untracked); the change is captured and reported under the parent model.
    • The log is savepoint-scoped: a rolled back savepoint reports nothing.
    for record in tx.take_tracked_changes().await? {
    for c in record.changes() { /* c.field(), c.old(), c.new_value(), c.sequence() */ }
    }

    take_tracked_changes flushes, drains and clears the log; it is a Programming error while a savepoint is open. The ORM runs registered precommit hooks at commit, after the flush and before COMMIT (OrmBuilder::precommit_hook, PrecommitHook::new(name, fn)); they run again while tracked changes are still pending, at most max_flush_rounds rounds, then the commit fails with a Programming error. Hooks run again only when one of them drained in that round; when none does, the loop ends and the pending changes stay unreported (as with no hook registered). A hook error is returned as precommit hook '<name>': <message> with the hook’s kind.

    The history messages, display names and field-level filtering are written by the mail addon (docs/addon-guide/mail.md, Record history); a status written by an addon’s own statement is reported with Transaction::track_external. Still open: monetary display with its currency, _track_add and cross-model tracking (064, 065), tracking of translated or company-dependent fields, tracking of stored computed fields, a monetary-field fixture, properties fields (the registry has no properties type, so there is no properties refusal and no properties ordering), and _track_discard (SPEC-MAIL-054: not implemented in this slice; a record deleted in the transaction reports nothing, which is tested under SPEC-MAIL-052). Known follow-ups: the log is kept in memory until a drain or the end of the transaction, so a transaction that writes very many tracked records with no consuming hook holds one entry per written tracked field.