Skip to content

Commit

Permalink
Merge pull request #102 from 5Ub-Z3r0/master
Browse files Browse the repository at this point in the history
Add an importer for BCGE MT940 exports.
  • Loading branch information
tarioch committed Aug 28, 2023
2 parents 59ac627 + 697701e commit 0db7f11
Show file tree
Hide file tree
Showing 3 changed files with 40 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.
29 changes: 29 additions & 0 deletions src/tariochbctools/importers/bcge/importer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
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 0db7f11

Please sign in to comment.