Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Template matching use in function. #590

Merged
merged 2 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/invoice2data/extract/invoice_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,24 +128,24 @@ def matches_input(self, extracted_str: str) -> bool:

Returns:
bool: True if the extracted string matches the template keywords,
False otherwise.
False otherwise.
"""
if all([re.search(keyword, extracted_str) for keyword in self["keywords"]]):
# All keyword patterns matched
if all([keyword in extracted_str for keyword in self["keywords"]]):
# All keywords found
if self["exclude_keywords"]:
if any(
[
re.search(exclude_keyword, extracted_str)
exclude_keyword in extracted_str
for exclude_keyword in self["exclude_keywords"]
]
):
# At least one exclude_keyword matches
# At least one exclude_keyword found
logger.debug(
"Template: %s | Keywords matched. Exclude keyword found!",
self["template_name"],
)
return False
# No exclude_keywords or none match, template is good
# No exclude_keywords or none found, template is good
logger.debug(
"Template: %s | Keywords matched. No exclude keywords found.",
self["template_name"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"invoice_number": "InvoiceNo:(\\S+)",
"order_id": "OrderID:(\\w{2}\\d{16,18})"
},
"keywords": ["flipkart", "WS\\s?Retail", "OD"],
"keywords": ["flipkart", "WS Retail", "OD"],
"options": {
"currency": "INR",
"remove_whitespace": true
Expand Down
2 changes: 1 addition & 1 deletion src/invoice2data/extract/templates/nl/nl.be.coolblue.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fields:
price_subtotal: float
keywords:
- Coolblue
- (NL810433941B01|BE0867686774)
- Klantnummer
- factuur
- €
options:
Expand Down
Loading