Skip to content

Commit

Permalink
parsers: Freetrade: Ignore TAX_CERTIFICATE rows
Browse files Browse the repository at this point in the history
  • Loading branch information
tacgomes committed Nov 21, 2024
1 parent a55d297 commit 4256a76
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
15 changes: 8 additions & 7 deletions src/investir/parser/freetrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ def parse(self) -> ParsingResult:
"TOP_UP": self._parse_transfer,
"WITHDRAWAL": self._parse_transfer,
"INTEREST_FROM_CASH": self._parse_interest,
"MONTHLY_STATEMENT": lambda _: None,
"MONTHLY_STATEMENT": None,
"TAX_CERTIFICATE": None,
}

with self._csv_file.open(encoding="utf-8") as file:
Expand All @@ -98,19 +99,19 @@ def parse(self) -> ParsingResult:

for row in rows:
tr_type = row["Type"]

if tr_type not in parse_fn:
raise_or_warn(TransactionTypeError(self._csv_file, row, tr_type))
continue

if fn := parse_fn.get(tr_type):
if (
row["Type"] != "MONTHLY_STATEMENT"
and row["Account Currency"] != "GBP"
):
if row["Account Currency"] != "GBP":
raise CurrencyError(
self._csv_file,
row,
row["Account Currency"],
)
fn(row)
else:
raise_or_warn(TransactionTypeError(self._csv_file, row, tr_type))

return ParsingResult(
self._orders, self._dividends, self._transfers, self._interest
Expand Down
10 changes: 8 additions & 2 deletions tests/parsers/test_freetradeparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

@pytest.fixture(name="create_parser")
def fixture_create_parser(tmp_path) -> Callable:
config.reset()
config.include_fx_fees = True

def _create_parser(rows: Sequence[Mapping[str, str]]) -> FreetradeParser:
Expand Down Expand Up @@ -120,7 +121,8 @@ def test_parser_happy_path(create_parser):
"Total Amount": "4.65",
}

statement = {"Type": "MONTHLY_STATEMENT"}
monthly_statement = {"Type": "MONTHLY_STATEMENT"}
tax_certificate = {"Type": "TAX_CERTIFICATE"}

parser = create_parser(
[
Expand All @@ -130,7 +132,8 @@ def test_parser_happy_path(create_parser):
deposit,
withdrawal,
interest,
statement,
monthly_statement,
tax_certificate,
]
)

Expand Down Expand Up @@ -260,6 +263,9 @@ def test_parser_invalid_transaction_type(create_parser):
with pytest.raises(TransactionTypeError):
parser.parse()

config.strict = False
parser.parse()


def test_parser_invalid_buy_sell(create_parser):
order = dict(ACQUISITION)
Expand Down

0 comments on commit 4256a76

Please sign in to comment.