Update CE processing

This commit is contained in:
Gabriel Augendre 2020-02-26 17:22:13 +01:00
parent 0354b25bce
commit 40331a39bc
No known key found for this signature in database
GPG key ID: 1E693F4CE4AEE7B4
2 changed files with 37 additions and 19 deletions

View file

@ -7,22 +7,6 @@ from ofxtools import OFXTree
from ofx_processor.utils.processor import Processor, Line from ofx_processor.utils.processor import Processor, Line
def _process_name_and_memo(name, memo):
if "CB****" in name:
conversion = re.compile(r"\d+,\d{2}[a-zA-Z]{3}")
match = conversion.search(memo)
if match:
res_name = memo[: match.start() - 1]
res_memo = name + memo[match.start() - 1 :]
else:
res_name = memo
res_memo = name
return res_name, res_memo
return name, memo
class BpvfLine(Line): class BpvfLine(Line):
def __init__(self, data=None): def __init__(self, data=None):
super(BpvfLine, self).__init__(data) super(BpvfLine, self).__init__(data)
@ -34,10 +18,26 @@ class BpvfLine(Line):
return int(self.data.trnamt * 1000) return int(self.data.trnamt * 1000)
def get_memo(self): def get_memo(self):
return _process_name_and_memo(self.data.name, self.data.memo)[1] return self._process_name_and_memo(self.data.name, self.data.memo)[1]
def get_payee(self): def get_payee(self):
return _process_name_and_memo(self.data.name, self.data.memo)[0] return self._process_name_and_memo(self.data.name, self.data.memo)[0]
@staticmethod
def _process_name_and_memo(name: str, memo: str):
if "CB****" in name:
conversion = re.compile(r"\d+,\d{2}[a-zA-Z]{3}")
match = conversion.search(memo)
if match:
res_name = memo[: match.start() - 1]
res_memo = name + memo[match.start() - 1 :]
else:
res_name = memo
res_memo = name
return res_name, res_memo
return name, memo
class BpvfProcessor(Processor): class BpvfProcessor(Processor):

View file

@ -1,10 +1,28 @@
import re
import click import click
from ofx_processor.processors.bpvf import BpvfProcessor from ofx_processor.processors.bpvf import BpvfProcessor, BpvfLine
class CeLine(BpvfLine):
@staticmethod
def _process_name_and_memo(name: str, memo: str):
name = name.strip()
cb_format = re.compile(r"FACT \d{6}$")
match = cb_format.search(name)
if match:
res_name = name[: match.start() - 1].strip()
res_memo = name[match.start() - 1 :].strip()
else:
res_name = name
res_memo = memo
return res_name, res_memo
class CeProcessor(BpvfProcessor): class CeProcessor(BpvfProcessor):
account_name = "ce" account_name = "ce"
line_class = CeLine
@staticmethod @staticmethod
@click.command("ce", help="Process CE bank statement (OFX)") @click.command("ce", help="Process CE bank statement (OFX)")