Skip to content

Export XMLID in hybrid mode #22

Description

@bosd

Objective:
Enhance the odoo-data-flow tool to allow exporting the external XML ID of the main record while using the tool's fast read mode.

Background:
The tool defaults to a high-speed read mode, which returns the numeric database ID for the id field, not the external XML ID. This prevents users from preserving external IDs when their export includes binary or selection fields, as those fields force read mode. The goal is to enrich the data with the correct external IDs without forcing the entire export into the slower legacy export mode.

Proposed Implementation:

  1. Implicit Trigger:

    • The new enrichment logic should be automatically triggered when the --fields list contains both .id and id, and the tool determines it will be using the read method.
  2. Primary Data Fetch (Polars DataFrame):

    • The tool should execute its main read() operation as normal, fetching records in batches into a Polars DataFrame (df_main). This DataFrame will contain the numeric ID in the .id column.
  3. Secondary Enrichment Step (Polars Join):

    • After a batch is fetched, check if the trigger conditions are met.
    • If so, collect the unique numeric IDs from the df_main['.id'] column.
    • Perform a second Odoo RPC call to ir.model.data with the domain [('model', '=', <model_name>), ('res_id', 'in', <list_of_ids>)] and fetch ['res_id', 'module', 'name'].
    • Convert the result of this RPC call into a separate Polars DataFrame (df_xml_ids) with two columns: res_id (numeric) and xml_id (e.g., "module.name").
    • Perform a left join in Polars, merging df_xml_ids into df_main on df_main['.id'] == df_xml_ids['res_id'].
  4. Merge and Finalize Results:

    • After the join, the df_main DataFrame will contain the original data plus the new xml_id column.
    • The script should then rename the xml_id column to id, overwriting the original (now redundant) id column that was requested.
    • The final output CSV should not include the .id column.

Acceptance Criteria:

  1. When an export is run with both .id and id in the field list (and in read mode), the resulting CSV's id column must contain the full external XML IDs.
  2. If a record does not have an external XML ID, its id value in the output should be empty.
  3. All existing tests (nox -s test) must pass.
  4. The linter session (nox -s pre-commit) must pass. )same for mypy, typeguard)

Metadata

Metadata

Assignees

No one assigned

    Labels

    JulesGoogle Jules

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions