Conversation
The value patterns in _VALUE_PATTERNS get embedded into every regex the
CLI builder / db_templates Suggest Fields wizard generates for a
matched identifier candidate. They were loose:
'iban': r'[A-Z0-9 ]+',
'vat': r'[A-Z0-9]+',
'bic': r'[A-Z0-9]+',
A suggestion built on a valid candidate is therefore fine on the
sample document (the candidate detector's own regex is strict, and the
label anchor picks the right value there), but when the same suggested
template is later applied to a fresh PDF the loose pattern grabs any
adjacent uppercase-alphanumeric blob near the label -- an order code
'ORDER12345' can match 'bic' shaped just fine, so downstream consumers
(Odoo's base_business_document_import) reject the field and the import
fails.
Tighten each pattern to mirror the strict validators in validators.py:
- BIC: ISO 9362 shape [A-Z]{6}[A-Z0-9]{2}(?:[A-Z0-9]{3})? (8 or 11
chars, first 6 letters).
- VAT: 2 alpha country + 8-14 alphanumerics.
- IBAN: country + 2 digits + 11-30 alphanumeric body, tolerating
embedded single-spaces/hyphens.
Regression test in tests/test_template_builder.py covers the BIC case
end-to-end (suggested template on a doc containing both an order code
and a valid BIC -> regex captures ONLY the BIC).
Reported downstream while iterating on the account_invoice_import_
invoice2data_db_templates Suggest Fields wizard (OCA/edi#1365).
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
`_VALUE_PATTERNS` in `src/invoice2data/extract/template_builder.py` used loose regexes:
```
'iban': r'[A-Z0-9 ]+',
'vat': r'[A-Z0-9]+',
'bic': r'[A-Z0-9]+',
```
These patterns are embedded into every field regex the CLI builder / db_templates "Suggest fields" wizard produces. On the sample document a suggestion is built from, the candidate detector's own strict pattern anchors things correctly — but when the same suggested template is later applied to a fresh PDF, the loose pattern happily grabs any adjacent uppercase-alnum blob near the label. An order code like `ORDER12345` matches the `bic` slot; downstream (Odoo's `base_business_document_import`) then rejects the field and the import fails.
Tighten each pattern to mirror the strict validators in `validators.py`:
Test
`tests/test_template_builder.py::test_bic_value_pattern_only_captures_bic_shape` — a doc containing both an order code and a valid BIC. Old pattern captured both; the tight one captures only the BIC.
All six template-builder tests green locally.
Test plan
Reported downstream while iterating on the account_invoice_import_invoice2data_db_templates "Suggest Fields" wizard (OCA/edi#1365) — Suggest was producing a BIC regex that captured an unrelated order code, so re-applying the template on a fresh PDF grabbed the wrong value.