Skip to content

Commit

Permalink
Add an importer for BCGE MT940 exports.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
5Ub-Z3r0 committed Aug 27, 2023
1 parent 59ac627 commit e09c905
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/importers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,14 @@ Import PDF from `Viseca One <https://one-digitalservice.ch/>`__
from tariochbctools.importers.viseca import importer as visecaimp
CONFIG = [visecaimp.Importer(r"Kontoauszug.*\.pdf", "Assets:Viseca:CHF")]
BCGE
----

Import mt940 from `BCGE <https://www.bcge.ch/>`__

.. code-block:: python
from tariochbctools.importers.bcge import importer as bcge
CONFIG = [bcge.BCGEImporter("/\d+\.mt940", "Assets:BCGE")]
Empty file.
31 changes: 31 additions & 0 deletions src/tariochbctools/importers/bcge/importer.py
Original file line number Diff line number Diff line change
@@ -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)))

0 comments on commit e09c905

Please sign in to comment.