mirror of
https://github.com/pretix/pretix.git
synced 2026-05-05 15:14:04 +00:00
Improve date format heuristic for bank statement import (#4814)
When dates are ambiguous, use the event's locale to infer whether the day or month comes first. Since regions follow certain date format conventions, this helps make more accurate guesses.
This commit is contained in:
@@ -292,11 +292,11 @@ def _handle_transaction(trans: BankTransaction, matches: tuple, event: Event = N
|
||||
trans.save()
|
||||
|
||||
|
||||
def parse_date(date_str):
|
||||
def parse_date(date_str, region=None):
|
||||
try:
|
||||
return dateutil.parser.parse(
|
||||
date_str,
|
||||
dayfirst="." in date_str,
|
||||
dayfirst="." in date_str or region in ["GB"],
|
||||
).date()
|
||||
except (ValueError, OverflowError):
|
||||
pass
|
||||
@@ -339,7 +339,7 @@ def _get_unknown_transactions(job: BankImportJob, data: list, event: Event = Non
|
||||
external_id=row.get('external_id'),
|
||||
currency=event.currency if event else job.currency)
|
||||
|
||||
trans.date_parsed = parse_date(trans.date)
|
||||
trans.date_parsed = parse_date(trans.date, (event and event.settings.region) or (organizer and organizer.settings.region) or None)
|
||||
|
||||
trans.checksum = trans.calculate_checksum()
|
||||
if trans.checksum not in known_checksums and (not trans.external_id or (trans.external_id, trans.date, trans.amount) not in known_by_external_id):
|
||||
|
||||
Reference in New Issue
Block a user