Add support for LCL checks

This commit is contained in:
Gabriel Augendre 2020-09-12 08:08:44 +02:00
parent 43f1172ea6
commit 001116fa2c
No known key found for this signature in database
GPG key ID: 1E693F4CE4AEE7B4
6 changed files with 48 additions and 12 deletions

View file

@ -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

View file

@ -52,6 +52,13 @@ NEWFILEUID:NONE
<FITID>348 200720 -40045
<NAME> CB IKEA 17/07/20
</STMTTRN>
<STMTTRN>
<TRNTYPE>CHECK
<DTPOSTED>20200721
<TRNAMT>-42.00
<FITID>003 1234567
<CHECKNUM>1234567
</STMTTRN>
</BANKTRANLIST>
<LEDGERBAL>
<BALAMT>+1000.00

View file

@ -53,6 +53,13 @@ NEWFILEUID:NONE
<FITID>348 200720 -40045
<NAME> CB IKEA 17/07/20
</STMTTRN>
<STMTTRN>
<TRNTYPE>CHECK
<DTPOSTED>20200721
<TRNAMT>-42.00
<FITID>003 1234567
<CHECKNUM>1234567
</STMTTRN>
</BANKTRANLIST>
<LEDGERBAL>
<BALAMT>+1000.00

View file

@ -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"
}
]

View file

@ -15,6 +15,14 @@
"memo": null,
"import_id": "YNAB:-400450:2020-07-17:1",
"account_id": "<YOUR CE ACCOUNT ID>"
},
{
"date": "2020-07-21",
"amount": -42000,
"payee_name": "CHQ",
"memo": "CHQ 1234567",
"import_id": "YNAB:-42000:2020-07-21:1",
"account_id": "<YOUR CE ACCOUNT ID>"
}
]
}

View file

@ -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 = ""