Skip to content

[14.0][ADD] account_invoice_import_invoice2data_db_templates - #1372

Open
bosd wants to merge 2 commits into
OCA:14.0from
bosd:14.0-add-invoice2data-db-templates
Open

[14.0][ADD] account_invoice_import_invoice2data_db_templates#1372
bosd wants to merge 2 commits into
OCA:14.0from
bosd:14.0-add-invoice2data-db-templates

Conversation

@bosd

@bosd bosd commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

What this adds

A new addon, account_invoice_import_invoice2data_db_templates, that stores invoice2data templates in the Odoo database and merges them into the import wizard alongside the existing disk-loaded ones. Implements the GUI template builder the parent module's 2017 TODO list asked for.

14.0 back-port of #1365 (16.0). The parent module account_invoice_import_invoice2data already exists on 14.0, so this can land without depending on the 16.0 migration.

Authoring modes

  • Guided: name + keywords + per-field rules via a field_ids o2m; JSON is composed at save time.
  • Power user: paste a full invoice2data JSON template into a dedicated tab; the Fields tab is then ignored.

The canonical field-name selection list is driven from invoice2data.extract.schema — adding a new canonical field upstream automatically becomes selectable here.

Buttons on the form

  • Preview text — runs the lib's to_text on the latest chatter attachment.
  • Test — runs a full extract_data() against the attached PDF using this template + the disk-loaded ones.
  • Suggest fields — wires invoice2data.extract.template_builder.suggested_template + the label-detection helpers to pre-fill the field grid from the latest attached PDF.

First-class support for the 1.0 lib options

Per-field replace (invoice2data#497) and extract_number flag (invoice2data#652) are exposed as columns on the o2m, not buried in JSON.

Differences from the 16.0 module

  • Dropped the web_ribbon widget (14.0 has no built-in web_ribbon).
  • Same models / wizard / tests otherwise.

External dependency

invoice2data >= 1.0 (now on PyPI). The 1.0 cut includes ordered_load, suggested_template, per-field replace, and the extract_number field option this module surfaces.

Reviewers

cc @alexis-via — happy to rebase / split / squash per your preferences.

Back-port of the 16.0 module (in review at OCA#1365) to 14.0. The parent
addon account_invoice_import_invoice2data already exists on 14.0, so
this can land without depending on the 16.0 migration PR (OCA#1220).

Same shape as the 16.0 version:

- `invoice2data.template` model with two authoring modes: guided
  (name + keywords + `field_ids` o2m composing the JSON at read time)
  and power-user (paste a full invoice2data JSON template into a
  dedicated tab).
- Per-field `replace` pair (invoice2data#497) and `extract_number`
  flag (invoice2data#652) exposed as first-class columns.
- Form actions: Preview text, Test (full extract_data() vs chatter PDF),
  Suggest fields (wires the lib's suggested_template + label detection
  to pre-fill the field grid).
- Wizard extension reimplements invoice2data_parse_invoice: builds the
  templates list via a `_invoice2data_collect_templates` hook that
  concatenates disk + DB.
- Security: dedicated 'Manage invoice2data templates' group.
- Tests: JSON round-trip, structured composition, replace pair,
  extract_number opt-in semantics, type/active filtering, wizard merge.

Selection lists are driven from invoice2data.extract.schema so adding
a new canonical field upstream automatically becomes selectable here.

Differences from the 16.0 version:
- `_inherit = ["mail.thread", "mail.activity.mixin"]` -- both mixins
  exist on 14.0.
- Dropped the `web_ribbon` widget from the form view (14.0 has no
  built-in web_ribbon widget yet).

Requires invoice2data >= 1.0 for `ordered_load`, `suggested_template`,
per-field `replace` / `extract_number`.
@OCA-git-bot OCA-git-bot added series:14.0 mod:account_invoice_import_invoice2data_db_t 3d05b Module account_invoice_import_invoice2data_db_templates labels Jul 20, 2026
Three CI-red fixes:

- Test: `TransactionCase.setUpClass` doesn't set `cls.env` on 14.0 (only
  `SavepointCase` does), so `cls.Template = cls.env[...]` blew up with
  `AttributeError: type object 'TestInvoice2dataDBTemplates' has no
  attribute 'env'`. Move the fixture binding to `setUp` (instance).
- Black reformat on the models / wizard / tests to satisfy the OCA
  pre-commit hook.
- Add the OCA-required setup/account_invoice_import_invoice2data_db_templates
  scaffolding (auto-generated by `setuptools-odoo-make-default`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:account_invoice_import_invoice2data_db_t 3d05b Module account_invoice_import_invoice2data_db_templates series:14.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants