From 001116fa2cf70e6f8053a764b6e01fdb163136d3 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Sat, 12 Sep 2020 08:08:44 +0200 Subject: [PATCH] Add support for LCL checks --- ofx_processor/processors/lcl.py | 13 ++++++++++++- tests/samples/lcl.ofx | 7 +++++++ tests/samples/lcl_as_downloaded.ofx | 7 +++++++ tests/samples/lcl_expected.json | 7 +++++++ tests/samples/lcl_transactions.json | 8 ++++++++ tests/utils.py | 18 +++++++----------- 6 files changed, 48 insertions(+), 12 deletions(-) diff --git a/ofx_processor/processors/lcl.py b/ofx_processor/processors/lcl.py index daaad56..df7ffc8 100644 --- a/ofx_processor/processors/lcl.py +++ b/ofx_processor/processors/lcl.py @@ -9,11 +9,17 @@ from ofx_processor.utils.base_ofx import OfxBaseLine, OfxBaseProcessor class LclLine(OfxBaseLine): def _extract_payee_and_date(self): - split = self.data.name.split() default_date = ( self.data.dtposted.isoformat().split("T")[0] if self.data.dtposted else None ) + if self.data.trntype.lower() == "check": + return "CHQ", default_date + + if not self.data.name: + return "", default_date + + split = self.data.name.split() if not split: return "", default_date @@ -39,6 +45,11 @@ class LclLine(OfxBaseLine): def get_date(self): return self._extract_payee_and_date()[1] + def get_memo(self): + if self.data.trntype.lower() == "check": + return f"CHQ {self.data.checknum}" + return super().get_memo() + class LclProcessor(OfxBaseProcessor): line_class = LclLine diff --git a/tests/samples/lcl.ofx b/tests/samples/lcl.ofx index 918ca5b..bcbca0a 100644 --- a/tests/samples/lcl.ofx +++ b/tests/samples/lcl.ofx @@ -52,6 +52,13 @@ NEWFILEUID:NONE 348 200720 -40045 CB IKEA 17/07/20 + +CHECK +20200721 +-42.00 +003 1234567 +1234567 + +1000.00 diff --git a/tests/samples/lcl_as_downloaded.ofx b/tests/samples/lcl_as_downloaded.ofx index 891104c..5d501e9 100644 --- a/tests/samples/lcl_as_downloaded.ofx +++ b/tests/samples/lcl_as_downloaded.ofx @@ -53,6 +53,13 @@ NEWFILEUID:NONE 348 200720 -40045 CB IKEA 17/07/20 + +CHECK +20200721 +-42.00 +003 1234567 +1234567 + +1000.00 diff --git a/tests/samples/lcl_expected.json b/tests/samples/lcl_expected.json index bec5da4..54c68f6 100644 --- a/tests/samples/lcl_expected.json +++ b/tests/samples/lcl_expected.json @@ -12,5 +12,12 @@ "payee_name": "CB IKEA", "memo": null, "import_id": "YNAB:-400450:2020-07-17:1" + }, + { + "date": "2020-07-21", + "amount": -42000, + "payee_name": "CHQ", + "memo": "CHQ 1234567", + "import_id": "YNAB:-42000:2020-07-21:1" } ] \ No newline at end of file diff --git a/tests/samples/lcl_transactions.json b/tests/samples/lcl_transactions.json index 4b0edbd..8a151d7 100644 --- a/tests/samples/lcl_transactions.json +++ b/tests/samples/lcl_transactions.json @@ -15,6 +15,14 @@ "memo": null, "import_id": "YNAB:-400450:2020-07-17:1", "account_id": "" + }, + { + "date": "2020-07-21", + "amount": -42000, + "payee_name": "CHQ", + "memo": "CHQ 1234567", + "import_id": "YNAB:-42000:2020-07-21:1", + "account_id": "" } ] } \ No newline at end of file diff --git a/tests/utils.py b/tests/utils.py index 52ff112..4d2ca14 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,19 +1,15 @@ import datetime +from dataclasses import dataclass +@dataclass class OfxTransaction: """ Mimick what is retrieved via ofxtools when parsing the file """ - def __init__( - self, - name: str = "", - memo: str = "", - dtposted: datetime.datetime = None, - trnamt: float = 0, - ): - self.dtposted = dtposted - self.memo = memo - self.trnamt = trnamt - self.name = name + name: str = "" + memo: str = "" + dtposted: datetime.datetime = None + trnamt: float = 0 + trntype: str = ""