Compare commits

...

3 Commits

2 changed files with 33 additions and 9 deletions

View File

@ -11,7 +11,7 @@ from rich.table import Table
from rich import print as rich_print
from rich.panel import Panel
__version__ = "0.3"
__version__ = "0.4"
DATE_RE = r"([0-9]{1,2}/[0-9]{2}/[0-9]{2,4})"
@ -63,11 +63,6 @@ class Line:
"""Line short description."""
return re.sub(r"\s+", " ", self.match["label"]).strip()
@property
def safe_label(self):
"""Line short description without double quotes."""
return self.label.replace('"', "")
def add_description(self, description_line):
"""Add a line to a long description."""
description_line = re.sub("\s+", " ", description_line).strip()
@ -106,7 +101,7 @@ class Line:
return self.abs_amount if self.direction == "+" else -self.abs_amount
def __str__(self):
return f"{self.safe_label} {self.amount}"
return f"{self.label} {self.amount}"
class AccountLine(Line):
@ -150,6 +145,8 @@ class CardLineDebit(CardLine):
class CardLineDebitWithFrancs(CardLineDebit):
"""Around 2019-03-08 the date format changed from 08032019 to 08/03/19."""
PATTERN = re.compile(
rf"\s+A\s+VOTRE\s+DEBIT\s+LE\s+{DATE_RE}\s+"
rf"(?P<amount>[0-9.,]+)\s+(?P<debit_francs>[0-9.,]+)$"
@ -160,8 +157,8 @@ class CardLineWithFrancs(CardLine):
"""Represents one line (debit or credit) in a card statement."""
PATTERN = re.compile(
rf"\s*(?P<date>{DATE_RE})\s+CARTE\s+(?P<label>.*)\s+"
rf"(?P<amount>[0-9.,]+)\s+(?P<amount_francs>[0-9.,]+)$"
rf"\s*(?P<date>{DATE_RE})\s+CARTE\s+(?P<valeur>{DATE_RE}|[0-9]{{8}})"
rf"\s+(?P<label>.*)\s+(?P<amount>[0-9.,]+)\s+(?P<amount_francs>[0-9.,]+)$"
)

View File

@ -6,6 +6,7 @@ tests against them too.
import datetime as dt
from pathlib import Path
from decimal import Decimal
import pytest
from boursobank import Statement, CardStatement, AccountStatement
@ -86,3 +87,29 @@ pour une Carte VISA Premier.
"""
)
assert statement.headers["card_owner"] == "THE OWNER IS HERE"
def test_old_date_format():
"""Around 2019-03-08 the date format on debit card statements
changed from 08032019 to 08/03/19.
The last column is in Francs, the previous one in .
"""
statement = Statement.from_string(
"""
28/03/2019 11111 22222 00000000000 99 1234********7890 27/02/2019 27/03/2019 1
...
11/03/2019 CARTE 08032019 99 FOOD 27,60 181,04
11/03/2019 CARTE 07032019 77 DRINKS 184,38 1.209,45
...
A VOTRE DEBIT LE 01/04/2019 1.234,56 12.345,67
"""
)
assert statement.lines
assert statement.lines[0].amount == Decimal("-27.60")
assert statement.lines[1].amount == Decimal("-184.38")