From e09c9051510d31e59c28d9aa3f6a26468fd203e7 Mon Sep 17 00:00:00 2001 From: 5Ub-Z3r0 <1673590+5Ub-Z3r0@users.noreply.github.com> Date: Sun, 27 Aug 2023 22:17:35 +0200 Subject: [PATCH] Add an importer for BCGE MT940 exports. This importer tries to parse the data that BCGE exports in the transaction detail field, namely ORDP, BENM and REMI. This should probably be added to the mt940 library, as it's MT940 specific encoding. --- docs/importers.rst | 11 +++++++ src/tariochbctools/importers/bcge/__init__.py | 0 src/tariochbctools/importers/bcge/importer.py | 31 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/tariochbctools/importers/bcge/__init__.py create mode 100644 src/tariochbctools/importers/bcge/importer.py diff --git a/docs/importers.rst b/docs/importers.rst index 90bbaba..f76f405 100644 --- a/docs/importers.rst +++ b/docs/importers.rst @@ -373,3 +373,14 @@ Import PDF from `Viseca One `__ from tariochbctools.importers.viseca import importer as visecaimp CONFIG = [visecaimp.Importer(r"Kontoauszug.*\.pdf", "Assets:Viseca:CHF")] + +BCGE +---- + +Import mt940 from `BCGE `__ + +.. code-block:: python + + from tariochbctools.importers.bcge import importer as bcge + + CONFIG = [bcge.BCGEImporter("/\d+\.mt940", "Assets:BCGE")] diff --git a/src/tariochbctools/importers/bcge/__init__.py b/src/tariochbctools/importers/bcge/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/tariochbctools/importers/bcge/importer.py b/src/tariochbctools/importers/bcge/importer.py new file mode 100644 index 0000000..2cbbb6e --- /dev/null +++ b/src/tariochbctools/importers/bcge/importer.py @@ -0,0 +1,31 @@ +import re + +from tariochbctools.importers.general import mt940importer + + +def strip_newline(string): + return string.replace("\n", "").replace("\r", "") + + +class BCGEImporter(mt940importer.Importer): + def prepare_payee(self, trxdata): + transaction_details = strip_newline(trxdata["transaction_details"]) + payee = re.search(r'ORDP/([^/]+)', transaction_details) + if payee is None: + return "" + else: + return payee.group(1) + + def prepare_narration(self, trxdata): + transaction_details = strip_newline(trxdata["transaction_details"]) + extra_details = strip_newline(trxdata["extra_details"]) + beneficiary = re.search( + r'/BENM/([^/]+)', transaction_details) + remittance = re.search( + r'/REMI/([^/]+)', transaction_details) + narration = [] + if beneficiary is not None: + narration.append("Beneficiary: %s" % beneficiary.group(1)) + if remittance is not None: + narration.append("Remittance: %s" % remittance.group(1)) + return ("%s - %s" % (extra_details, ",".join(narration)))