From 5f51ef0d9c2b448558c468987100b347b002fcbe Mon Sep 17 00:00:00 2001 From: Nirus2000 Date: Wed, 1 Nov 2023 16:31:32 +0100 Subject: [PATCH] Modify Trade Republic PDF-Importer to support new transaction https://forum.portfolio-performance.info/t/pdf-import-von-trade-republic/5107/453 --- .../TradeRepublicPDFExtractorTest.java | 90 ++++++++++++------- .../pdf/traderepublic/Zinsabrechnung03.txt | 25 ++++++ .../pdf/TradeRepublicPDFExtractor.java | 26 ++++++ 3 files changed, 111 insertions(+), 30 deletions(-) create mode 100644 name.abuchen.portfolio.tests/src/name/abuchen/portfolio/datatransfer/pdf/traderepublic/Zinsabrechnung03.txt diff --git a/name.abuchen.portfolio.tests/src/name/abuchen/portfolio/datatransfer/pdf/traderepublic/TradeRepublicPDFExtractorTest.java b/name.abuchen.portfolio.tests/src/name/abuchen/portfolio/datatransfer/pdf/traderepublic/TradeRepublicPDFExtractorTest.java index 137345d572..a6320f1fe8 100644 --- a/name.abuchen.portfolio.tests/src/name/abuchen/portfolio/datatransfer/pdf/traderepublic/TradeRepublicPDFExtractorTest.java +++ b/name.abuchen.portfolio.tests/src/name/abuchen/portfolio/datatransfer/pdf/traderepublic/TradeRepublicPDFExtractorTest.java @@ -3684,22 +3684,19 @@ public void testZinsabrechnung01() errors); assertThat(errors, empty()); + assertThat(countSecurities(results), is(0L)); + assertThat(countBuySell(results), is(0L)); + assertThat(countAccountTransactions(results), is(1L)); assertThat(results.size(), is(1)); new AssertImportActions().check(results, CurrencyUnit.EUR); - // check transaction - Iterator iter = results.stream().filter(TransactionItem.class::isInstance).iterator(); - assertThat(results.stream().filter(TransactionItem.class::isInstance).count(), is(1L)); - - Item item = iter.next(); - - // assert transaction - AccountTransaction transaction = (AccountTransaction) item.getSubject(); - assertThat(transaction.getType(), is(AccountTransaction.Type.INTEREST)); - assertThat(transaction.getDateTime(), is(LocalDateTime.parse("2023-01-31T00:00"))); - assertThat(transaction.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0.88)))); - assertThat(transaction.getSource(), is("Zinsabrechnung01.txt")); - assertNull(transaction.getNote()); + // check interest transaction + assertThat(results, hasItem(interest( // + hasDate("2023-01-31T00:00"), // + hasSource("Zinsabrechnung01.txt"), // + hasNote("2,00%"), // + hasAmount("EUR", 0.88), hasGrossValue("EUR", 0.88), // + hasTaxes("EUR", 0.00), hasFees("EUR", 0.00)))); } @Test @@ -3713,22 +3710,45 @@ public void testZinsabrechnung02() errors); assertThat(errors, empty()); + assertThat(countSecurities(results), is(0L)); + assertThat(countBuySell(results), is(0L)); + assertThat(countAccountTransactions(results), is(1L)); assertThat(results.size(), is(1)); new AssertImportActions().check(results, CurrencyUnit.EUR); - // check transaction - Iterator iter = results.stream().filter(TransactionItem.class::isInstance).iterator(); - assertThat(results.stream().filter(TransactionItem.class::isInstance).count(), is(1L)); + // check interest transaction + assertThat(results, hasItem(interest( // + hasDate("2023-01-31T00:00"), // + hasSource("Zinsabrechnung02.txt"), // + hasNote("2,00%"), // + hasAmount("EUR", 2.58), hasGrossValue("EUR", 2.58), // + hasTaxes("EUR", 0.00), hasFees("EUR", 0.00)))); + } - Item item = iter.next(); + @Test + public void testZinsabrechnung03() + { + TradeRepublicPDFExtractor extractor = new TradeRepublicPDFExtractor(new Client()); - // assert transaction - AccountTransaction transaction = (AccountTransaction) item.getSubject(); - assertThat(transaction.getType(), is(AccountTransaction.Type.INTEREST)); - assertThat(transaction.getDateTime(), is(LocalDateTime.parse("2023-01-31T00:00"))); - assertThat(transaction.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(2.58)))); - assertThat(transaction.getSource(), is("Zinsabrechnung02.txt")); - assertNull(transaction.getNote()); + List errors = new ArrayList<>(); + + List results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Zinsabrechnung03.txt"), + errors); + + assertThat(errors, empty()); + assertThat(countSecurities(results), is(0L)); + assertThat(countBuySell(results), is(0L)); + assertThat(countAccountTransactions(results), is(1L)); + assertThat(results.size(), is(1)); + new AssertImportActions().check(results, CurrencyUnit.EUR); + + // check interest transaction + assertThat(results, hasItem(interest( // + hasDate("2023-10-31T00:00"), // + hasSource("Zinsabrechnung03.txt"), // + hasNote("01.10.2023 - 31.10.2023 (4,00%)"), // + hasAmount("EUR", 112.40), hasGrossValue("EUR", 152.67), // + hasTaxes("EUR", 38.17 + 2.10), hasFees("EUR", 0.00)))); } @Test @@ -3741,6 +3761,7 @@ public void testRescontoInteressiMaturati01() List results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "RescontoInteressiMaturati01.txt"), errors); + assertThat(errors, empty()); assertThat(errors, empty()); assertThat(countSecurities(results), is(0L)); assertThat(countBuySell(results), is(0L)); @@ -3748,9 +3769,13 @@ public void testRescontoInteressiMaturati01() assertThat(results.size(), is(1)); new AssertImportActions().check(results, CurrencyUnit.EUR); - // assert transaction - assertThat(results, hasItem(interest(hasDate("2023-05-31"), hasAmount("EUR", 0.12), // - hasSource("RescontoInteressiMaturati01.txt"), hasNote(null)))); + // check interest transaction + assertThat(results, hasItem(interest( // + hasDate("2023-05-31"), // + hasSource("RescontoInteressiMaturati01.txt"), // + hasNote("2,00%"), // + hasAmount("EUR", 0.12), hasGrossValue("EUR", 0.12), // + hasTaxes("EUR", 0.00), hasFees("EUR", 0.00)))); } @Test @@ -3763,6 +3788,7 @@ public void testInterestInvoice01() List results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "InterestInvoice01.txt"), errors); + assertThat(errors, empty()); assertThat(errors, empty()); assertThat(countSecurities(results), is(0L)); assertThat(countBuySell(results), is(0L)); @@ -3770,8 +3796,12 @@ public void testInterestInvoice01() assertThat(results.size(), is(1)); new AssertImportActions().check(results, CurrencyUnit.EUR); - // assert transaction - assertThat(results, hasItem(interest(hasDate("2023-09-30"), hasAmount("EUR", 1.47), // - hasSource("InterestInvoice01.txt"), hasNote(null)))); + // check interest transaction + assertThat(results, hasItem(interest( // + hasDate("2023-09-30"), // + hasSource("InterestInvoice01.txt"), // + hasNote("2,00%"), // + hasAmount("EUR", 1.47), hasGrossValue("EUR", 1.47), // + hasTaxes("EUR", 0.00), hasFees("EUR", 0.00)))); } } diff --git a/name.abuchen.portfolio.tests/src/name/abuchen/portfolio/datatransfer/pdf/traderepublic/Zinsabrechnung03.txt b/name.abuchen.portfolio.tests/src/name/abuchen/portfolio/datatransfer/pdf/traderepublic/Zinsabrechnung03.txt new file mode 100644 index 0000000000..71f255483a --- /dev/null +++ b/name.abuchen.portfolio.tests/src/name/abuchen/portfolio/datatransfer/pdf/traderepublic/Zinsabrechnung03.txt @@ -0,0 +1,25 @@ +PDFBox Version: 1.8.17 +Portfolio Performance Version: 0.65.4 +----------------------------------------- +TRADE REPUBLIC BANK GMBH BRUNNENSTRASSE 19-21 10119 BERLIN +Max Mustermann SEITE 1 von 1 +Musterstraße 123 DATUM 01.11.2023 +01234 Musterstadt VERRECHNUNGSKONTO 0123456789 +STEUER-ID 01234567890 +ABRECHNUNG ZINSEN +zum 31.10.2023 +ÜBERSICHT +VERMÖGENSWERT EINKOMMENSART ZINSEN DATUM GESAMT +Cash Zinsen 4,00% 01.10.2023 - 31.10.2023 152,67 EUR +ABRECHNUNG +POSITION BETRAG +Besteuerungsgrundlage 152,67 EUR +Kapitalertragssteuer -38,17 EUR +Solidaritätszuschlag -2,10 EUR +Gesamt 112,40 EUR +BUCHUNG +IBAN BUCHUNGSDATUM GUTSCHRIFT NACH STEUERN +DE99012345670123456789 01.11.2023 112,40 EUR +Trade Republic Bank GmbH www.traderepublic.com Sitz der Gesellschaft: Berlin Geschäftsführer +Brunnenstraße 19-21 service@traderepublic.com AG Charlottenburg HRB 244347 B Andreas Torner +10119 Berlin USt-ID DE307510626 Gernot Mittendorfer \ No newline at end of file diff --git a/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/TradeRepublicPDFExtractor.java b/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/TradeRepublicPDFExtractor.java index 7f06a3df4f..79aea2f728 100644 --- a/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/TradeRepublicPDFExtractor.java +++ b/name.abuchen.portfolio/src/name/abuchen/portfolio/datatransfer/pdf/TradeRepublicPDFExtractor.java @@ -1135,15 +1135,41 @@ private void addInterestStatementTransaction() .assign((t, v) -> t.setDateTime(asDate(v.get("date")))) // @formatter:off + // IBAN BUCHUNGSDATUM GUTSCHRIFT NACH STEUERN // DE10123456789123456789 01.02.2023 0,88 EUR + // + // IBAN DATA EMISSIONE TOTALE + // DE93752109007837402856 01.06.2023 0,12 EUR + // + // IBAN BOOKING DATE TOTAL + // DE27502109007011534672 02.10.2023 1,47 EUR // @formatter:on .section("currency", "amount") // + .find("IBAN (BUCHUNGSDATUM|DATA EMISSIONE|BOOKING DATE) (GUTSCHRIFT NACH STEUERN|TOTALE|TOTAL)") // .match("^.* [\\d]{2}\\.[\\d]{2}\\.[\\d]{4} (?[\\.,\\d]+) (?[\\w]{3})$") // .assign((t, v) -> { t.setAmount(asAmount(v.get("amount"))); t.setCurrencyCode(asCurrencyCode(v.get("currency"))); }) + .optionalOneOf( // + // @formatter:off + // Cash Zinsen 4,00% 01.10.2023 - 31.10.2023 152,67 EUR + // @formatter:on + section -> section // + .attributes("note1", "note2") // + .match("^.* (Zinsen|Interessi|Interest) (?[\\.,\\d]+%) (?.*[\\d]{4}).*$") // + .assign((t, v) -> t.setNote(trim(v.get("note2")) + " (" + trim(v.get("note1")) + ")")), + // @formatter:off + // Cash Zinsen 2,00% 2,58 EUR + // Liquidità Interessi 2,00% 0,12 EUR + // Cash Interest 2,00% 1,47 EUR + // @formatter:on + section -> section // + .attributes("note") // + .match("^.* (Zinsen|Interessi|Interest) (?[\\.,\\d]+%).*$") + .assign((t, v) -> t.setNote(v.get("note")))) + .wrap(TransactionItem::new); addTaxesSectionsTransaction(pdfTransaction, type);