Skip to content

[16.0][ADD] account_invoice_import_invoice2data_db_templates - #1365

Draft
bosd wants to merge 104 commits into
OCA:16.0from
bosd:16.0-store_invoice2data_templates
Draft

[16.0][ADD] account_invoice_import_invoice2data_db_templates#1365
bosd wants to merge 104 commits into
OCA:16.0from
bosd:16.0-store_invoice2data_templates

Conversation

@bosd

@bosd bosd commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Depends on #1220 (the 16.0 migration of account_invoice_import_invoice2data). Until that lands the diff includes its commits; once it merges this rebases cleanly onto OCA/edi 16.0.

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.

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, no parallel list to maintain.

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; surfaces the parsed dict and required-fields warnings.
  • Suggest fields — wires invoice2data.extract.template_builder.suggested_template + the label-detection helpers to pre-fill the field grid from the latest attached PDF (the "guessing framework" the 2017 TODO list asked for).

Wizard merge

Extends account.invoice.import to reimplement invoice2data_parse_invoice cleanly:

First-class support for the 1.0 lib options

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

Security

  • New Manage invoice2data templates group on top of account.group_account_invoice.
  • ir.model.access.csv for both the parent model and the o2m.

Tests

Cover JSON round-trip, structured composition, the replace pair, extract_number opt-in semantics, type/active filtering, and the wizard's merged template list.

External dependency

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

Roadmap (in readme/ROADMAP.rst)

  • Visual PDF region picker for area:-style templates (ties into the camelot/Excalibur path).
  • AI authoring (--new-template --ai) wired as an action.
  • Per-record audit of which DB template matched on a given import.

Reviewers

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

alexis-via and others added 30 commits February 19, 2026 10:02
…edicated module account_invoice_import_invoice2data

Update README.rst and headers to latest OCA conventions.
Better key names in the parsed_inv dict
parsed_inv doesn't need to be JSON serializable anymore (small drawback: the invoice is parsed a second time on the second step... but the second step is rarely used)
Move code from account_invoice_import_invoice2data to account_invoice_import
Update REAME and some interface strings about UBL being an ISO standard
Small code changes
…voice dict, cleaner organisation)

Code refactoring: move code in base_business_document_import, factorise code for tax matching (it was duplicated in UBL and ZUGFeRD)
Now support PDF with embedded UBL XML file
Enable unittests on account_invoice_import_ubl
More absolute xpath in account_invoice_import_ubl instead of relative xpath

WARNING: these are big changes, I may have broken a few details
…te dir and the built-in templates

Also allow to use only a local template dir
README updated to explain how to configure all this
Special thanks to Sébastien Beau for his help to achieve this
Add support for partner bank matching on invoice update (before, it was only supported on invoice creation)
[FIX] LINT

Use try/except when importing external libs
Remove self.ensure_one() that has nothing to do in an api.model method
…a recent version of pdftotext on travis's ubuntu 12.04 images
Rename __openerp__.py to __manifest__.py and set installable to False
Also port all the modules that generate the XML documents: account_invoice_ubl, account_invoice_zugferd, purchase_order_ubl and sale_order_ubl
… module

Fix spelling mistake and other remarks on README by Tarteo
* Update to work with latest version of invoice2data

* Add requirements.txt file
Update the account_invoice_download_weboob following the changes in account_invoice_download
Add README.rst for the 2 modules
Update text displayed in the invoice import wizard and make list of
supported formats modular (like in bank statement import)
Updated by Actualizar ficheiros PO com o novo POT (msgmerge) hook in Weblate.
weblate and others added 16 commits February 19, 2026 10:02
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: edi-14.0/edi-14.0-account_invoice_import_invoice2data
Translate-URL: https://translation.odoo-community.org/projects/edi-14-0/edi-14-0-account_invoice_import_invoice2data/
Currently translated at 100.0% (16 of 16 strings)

Translation: edi-14.0/edi-14.0-account_invoice_import_invoice2data
Translate-URL: https://translation.odoo-community.org/projects/edi-14-0/edi-14-0-account_invoice_import_invoice2data/nl/
Currently translated at 100.0% (16 of 16 strings)

Translation: edi-14.0/edi-14.0-account_invoice_import_invoice2data
Translate-URL: https://translation.odoo-community.org/projects/edi-14-0/edi-14-0-account_invoice_import_invoice2data/es/
… PDF invoices

Restore implementation in OCA#630:
- when importing an invoice for an unknown partner, it creates an empty invoice with PDF a
s attachment
DISABLED_MAIL_CONTEXT is not available yet in v14 and v15.
Updated by "Update PO files to match POT (msgmerge)" hook in Weblate.

Translation: edi-14.0/edi-14.0-account_invoice_import_invoice2data
Translate-URL: https://translation.odoo-community.org/projects/edi-14-0/edi-14-0-account_invoice_import_invoice2data/
Add support for discount on lines in the multi-line create scenario
@OCA-git-bot OCA-git-bot added series:16.0 mod:account_invoice_import_invoice2data Module account_invoice_import_invoice2data labels Jun 23, 2026
mymage and others added 3 commits July 16, 2026 22:31
Translated using Weblate (Italian)

Currently translated at 6.6% (1 of 15 strings)

Translation: edi-14.0/edi-14.0-account_invoice_import_invoice2data
Translate-URL: https://translation.odoo-community.org/projects/edi-14-0/edi-14-0-account_invoice_import_invoice2data/it/

Translated using Weblate (Italian)

Currently translated at 13.3% (2 of 15 strings)

Translation: edi-14.0/edi-14.0-account_invoice_import_invoice2data
Translate-URL: https://translation.odoo-community.org/projects/edi-14-0/edi-14-0-account_invoice_import_invoice2data/it/
@bosd
bosd force-pushed the 16.0-store_invoice2data_templates branch from 007b588 to 446ff7c Compare July 18, 2026 17:36
DB-stored invoice2data templates + GUI builder as a new addon that
depends on account_invoice_import_invoice2data (this PR is stacked on
top of OCA#1220).

- `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 (issue invoice2data#497) and `extract_number`
  flag (issue invoice2data#652) exposed as first-class columns.
- Form actions: Preview text, Test (full extract_data() vs chatter PDF),
  and 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. Uses `with NamedTemporaryFile(...)` + flush()
  (matches the review on OCA#1220).
- 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.
@OCA-git-bot OCA-git-bot added the mod:account_invoice_import_invoice2data_db_t 3d05b Module account_invoice_import_invoice2data_db_templates label Jul 18, 2026
bosd added 2 commits July 19, 2026 21:48
Two red-CI fixes:

- `_field_selection` was defined as a zero-arg function but Odoo passes
  `self` to selection callables; test errors were:
  `TypeError: _field_selection() takes 0 positional arguments but 1 was given`
- black + isort reformats to satisfy OCA/edi's pre-commit config.
Pre-commit's 'unchecked-in-files' guard was failing because the OCA
setup/<addon>/{setup.py, odoo/addons/<addon>} scaffolding wasn't
committed alongside the module. Add it (matches what
setuptools-odoo-make-default generates).
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 mod:account_invoice_import_invoice2data Module account_invoice_import_invoice2data series:16.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.