Conversation
…is not one 'date'
Reported by the downstream Odoo template builder: Guided Suggest for
DATE captured '18503 04/04' (a ZIP-code + first half of a real date) on
an invoice where the Date label sat one line below the address
block.
Root cause: two date regexes were loose.
- labels._DATE = r'\d[\d /.\-]{6,12}\d' — any 8-14 char run of
digits + space/dot/slash/dash bounded by digits. Matched 'ZIP + rest
of the day+month' as one 'date' value; Date label then anchored
onto that span. Replace with a set of alternatives that each require
a real numeric / month-name separator between parts.
- candidates._DATE_RE third alt \b[A-Za-z]{3,9}\.?\s+\d{1,2},?
\s+\d{2,4}\b (and my in-progress expansion) matched 'Date 12.05' as
a 'date' because [A-Za-z]{3,9} accepts any 3-9 letter word. That
swallowed adjacent digits and prevented the real '12.05.2024' from
becoming a date candidate. Replace the letter class with a proper
month-name alternation (case-insensitive, English + common
Dutch/German/French/Spanish/Italian short forms).
Also broadens the accepted date shapes so real-world dash-separated
month-name variants ('6-sept-2026', '6-Sep-26', '6.sep.2026') go
through, alongside the existing '2024-05-12' / '12/05/2024' / '06/09/26'
and 'May 12, 2024' forms.
Tests:
- test_date_label_does_not_grab_zip_and_partial_date — regression.
- test_date_label_accepts_month_name_with_dashes — four format
variants each go through find_labeled_fields.
- test_find_dates_recognises_month_name_with_dash and
test_find_dates_recognises_short_year_slash — candidate-side
coverage.
All 22 candidate/label/template_builder tests pass locally.
bosd
force-pushed
the
fix/date-candidate-and-label-precision
branch
from
September 6, 2026 17:35
c6fb101 to
66f524f
Compare
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
Reported downstream (OCA/edi template builder): Guided Suggest for the DATE field captured a ZIP + partial date as a single "date" value, e.g.
18503 04/04on an invoice where theDatelabel sat one line below the address block.Two date regexes were too loose:
1.
labels._DATE = r'\d[\d /.\-]{6,12}\d'Any 8-14 char run of digits + space/dot/slash/dash bounded by digits. That's happy to span from inside a ZIP into the first half of an actual date, so a nearby
Datelabel anchor picks up the wrong span. Replace with alternatives that each require a real numeric or month-name separator between parts:2.
candidates._DATE_REthird alt:\b[A-Za-z]{3,9}\.?\s+\d{1,2},?\s+\d{2,4}\bThe letter class accepts any 3-9 letter word, so on a line like
Date 12.05.2024, "Date 12.05" matched as a "date" and swallowed the digits — preventing the real12.05.2024from being detected. Replace[A-Za-z]{3,9}with an actual month-name alternation (case-insensitive, English full names + English/Dutch/German/French/Spanish/Italian common short forms):The same alternation is used in the
dd mon yyyy(dash/dot separator ok) andmon dd, yyyyalts, so real-world formats like6-sept-2026,6.sep.2026,06/09/26,May 12, 2024all detect cleanly, while a label likeDatecannot masquerade as a month.Tests
test_date_label_does_not_grab_zip_and_partial_date— the reproduction from the downstream report.test_date_label_accepts_month_name_with_dashes— four format variants each go throughfind_labeled_fields.test_find_dates_recognises_month_name_with_dashandtest_find_dates_recognises_short_year_slash— candidate-side coverage.All 22 candidate/label/template_builder tests pass locally.
Test plan
pytest tests/test_candidates.py tests/test_labels.py tests/test_template_builder.py— 22/22ruff check/ruff format --checkclean