diff --git a/src/investir/parser/freetrade.py b/src/investir/parser/freetrade.py index 0189847..148a0e8 100644 --- a/src/investir/parser/freetrade.py +++ b/src/investir/parser/freetrade.py @@ -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: @@ -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 diff --git a/tests/parsers/test_freetradeparser.py b/tests/parsers/test_freetradeparser.py index eb3fabb..3f8098f 100644 --- a/tests/parsers/test_freetradeparser.py +++ b/tests/parsers/test_freetradeparser.py @@ -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: @@ -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( [ @@ -130,7 +132,8 @@ def test_parser_happy_path(create_parser): deposit, withdrawal, interest, - statement, + monthly_statement, + tax_certificate, ] ) @@ -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)