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

[16.0][IMP] account_statement_import_online_gocardless: use a hashing strategy to produce the unique_transaction_id #758

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2022 ForgeFlow S.L.
# Copyright 2023-2024 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import hashlib
import json
from datetime import datetime
from uuid import uuid4
Expand Down Expand Up @@ -367,11 +368,7 @@
"date": current_date,
"ref": partner_name or "/",
"payment_ref": payment_ref,
"unique_import_id": (
tr.get("entryReference")
or tr.get("transactionId")
or tr.get("internalTransactionId")
),
"unique_import_id": self._gocardless_get_unique_import_id(tr),
"amount": amount_currency,
"account_number": account_number,
"partner_name": partner_name,
Expand All @@ -381,6 +378,25 @@
)
return res, {}

def _gocardless_prepare_unique_import_id_hasher(self, hasher, tr):
"""Inherit this method if you need to add more fields
to produce a unique identifier for this transaction"""
transactionId = tr.get("transactionId", False)
entryReference = tr.get("entryReference", False)
internalTransactionId = tr.get("internalTransactionId", False)
if transactionId:
hasher.update(transactionId.encode("utf-8"))
if entryReference:
hasher.update(entryReference.encode("utf-8"))

Check warning on line 390 in account_statement_import_online_gocardless/models/online_bank_statement_provider.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_online_gocardless/models/online_bank_statement_provider.py#L390

Added line #L390 was not covered by tests
if internalTransactionId:
hasher.update(internalTransactionId.encode("utf-8"))

Check warning on line 392 in account_statement_import_online_gocardless/models/online_bank_statement_provider.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_online_gocardless/models/online_bank_statement_provider.py#L392

Added line #L392 was not covered by tests
return hasher

def _gocardless_get_unique_import_id(self, tr):
hasher = hashlib.sha1()
hasher = self._gocardless_prepare_unique_import_id_hasher(hasher, tr)
return hasher.hexdigest()

def _gocardless_get_note(self, tr):
"""Override to get different notes."""
note_elements = [
Expand Down
Loading