diff --git a/src/investir/parser/trading212.py b/src/investir/parser/trading212.py index 31a3195..c023620 100644 --- a/src/investir/parser/trading212.py +++ b/src/investir/parser/trading212.py @@ -112,12 +112,17 @@ def parse(self) -> ParsingResult: "Deposit": self._parse_transfer, "Withdrawal": self._parse_transfer, "Interest on cash": self._parse_interest, - "Currency conversion": lambda _: None, + "Currency conversion": None, } with self._csv_file.open(encoding="utf-8") as file: for row in csv.DictReader(file): tr_type = row["Action"] + + 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): currency_total = row["Currency (Total)"] if currency_total != "GBP": @@ -125,8 +130,6 @@ def parse(self) -> ParsingResult: CurrencyError(self._csv_file, row, currency_total) ) 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_trading212.py b/tests/parsers/test_trading212.py index 13914d5..910fc52 100644 --- a/tests/parsers/test_trading212.py +++ b/tests/parsers/test_trading212.py @@ -74,6 +74,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]]) -> Trading212Parser: @@ -301,6 +302,9 @@ def test_parser_invalid_transaction_type(create_parser): with pytest.raises(TransactionTypeError): parser.parse() + config.strict = False + parser.parse() + def test_parser_invalid_account_currency(create_parser): order = dict(ACQUISITION)