Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify Baader Bank PDF-Importer to support new transaction #3886

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasTicker;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasWkn;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.interest;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.outboundDelivery;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.purchase;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.sale;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.security;
Expand Down Expand Up @@ -2324,6 +2325,168 @@ public void testWertpapierVerkauf17()
hasTaxes("EUR", 0.00), hasFees("EUR", 4.00 + 3.32))));
}

@Test
public void testWertpapierVerkauf18()
{
BaaderBankPDFExtractor extractor = new BaaderBankPDFExtractor(new Client());

List<Exception> errors = new ArrayList<>();

List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Verkauf18.txt"), errors);

assertThat(errors, empty());
assertThat(countSecurities(results), is(1L));
assertThat(countBuySell(results), is(1L));
assertThat(countAccountTransactions(results), is(0L));
assertThat(results.size(), is(2));
new AssertImportActions().check(results, CurrencyUnit.EUR);

// check security
assertThat(results, hasItem(security( //
hasIsin("DE000HB2KBG9"), hasWkn("HB2KBG"), hasTicker(null), //
hasName("UniCredit Bank AG HVB Inline 18.05.22 BASF 45-70"), //
hasCurrencyCode("EUR"))));

// check buy sell transaction
assertThat(results, hasItem(sale( //
hasDate("2022-05-25T00:00"), hasShares(6), //
hasSource("Verkauf18.txt"), //
hasNote("Vorgangs-Nr.: 8679954 | Ablauf der Optionsfrist"), //
hasAmount("EUR", 60.00), hasGrossValue("EUR", 60.00), //
hasTaxes("EUR", 0.00), hasFees("EUR", 0.00))));
}

@Test
public void testWertpapierVerkauf19()
{
BaaderBankPDFExtractor extractor = new BaaderBankPDFExtractor(new Client());

List<Exception> errors = new ArrayList<>();

List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Verkauf19.txt"), errors);

assertThat(errors, empty());
assertThat(countSecurities(results), is(1L));
assertThat(countBuySell(results), is(1L));
assertThat(countAccountTransactions(results), is(0L));
assertThat(results.size(), is(2));
new AssertImportActions().check(results, CurrencyUnit.EUR);

// check security
assertThat(results, hasItem(security( //
hasIsin("US60468T1051"), hasWkn("A1W1XV"), hasTicker(null), //
hasName("Mirati Therapeutics Inc. Registered Shares DL -,01"), //
hasCurrencyCode("USD"))));

// check buy sell transaction
assertThat(results, hasItem(sale( //
hasDate("2024-01-25T00:00"), hasShares(4), //
hasSource("Verkauf19.txt"), //
hasNote("Vorgangs-Nr.: 25742277 | Obligatorische Barabfindung"), //
hasAmount("EUR", 212.68), hasGrossValue("EUR", 212.68), //
hasForexGrossValue("USD", 232.00), //
hasTaxes("EUR", 0.00), hasFees("EUR", 0.00))));
}

@Test
public void testWertpapierVerkauf19WithSecurityInEUR()
{
Security security = new Security("Mirati Therapeutics Inc. Registered Shares DL -,01", CurrencyUnit.EUR);
security.setIsin("US60468T1051");
security.setWkn("A1W1XV");

Client client = new Client();
client.addSecurity(security);

BaaderBankPDFExtractor extractor = new BaaderBankPDFExtractor(client);

List<Exception> errors = new ArrayList<>();

List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Verkauf19.txt"), errors);

assertThat(errors, empty());
assertThat(countSecurities(results), is(0L));
assertThat(countBuySell(results), is(1L));
assertThat(countAccountTransactions(results), is(0L));
assertThat(results.size(), is(1));
new AssertImportActions().check(results, CurrencyUnit.EUR);

// check buy sell transaction
assertThat(results, hasItem(sale( //
hasDate("2024-01-25T00:00"), hasShares(4), //
hasSource("Verkauf19.txt"), //
hasNote("Vorgangs-Nr.: 25742277 | Obligatorische Barabfindung"), //
hasAmount("EUR", 212.68), hasGrossValue("EUR", 212.68), //
hasTaxes("EUR", 0.00), hasFees("EUR", 0.00), //
check(tx -> {
CheckCurrenciesAction c = new CheckCurrenciesAction();
Status s = c.process((PortfolioTransaction) tx, new Portfolio());
assertThat(s, is(Status.OK_STATUS));
}))));
}

@Test
public void testWertpapierVerkauf20()
{
BaaderBankPDFExtractor extractor = new BaaderBankPDFExtractor(new Client());

List<Exception> errors = new ArrayList<>();

List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Verkauf20.txt"), errors);

assertThat(errors, empty());
assertThat(countSecurities(results), is(1L));
assertThat(countBuySell(results), is(1L));
assertThat(countAccountTransactions(results), is(0L));
assertThat(results.size(), is(2));
new AssertImportActions().check(results, CurrencyUnit.EUR);

// check security
assertThat(results, hasItem(security( //
hasIsin("DE0001104875"), hasWkn("110487"), hasTicker(null), //
hasName("Bundesrep.Deutschland Bundesschatzanw. v.22(24)"), //
hasCurrencyCode("EUR"))));

// check buy sell transaction
assertThat(results, hasItem(sale( //
hasDate("2024-03-15T00:00"), hasShares(2080), //
hasSource("Verkauf20.txt"), //
hasNote("Vorgangs-Nr.: 06501068"), //
hasAmount("EUR", 206626.75), hasGrossValue("EUR", 208000.00), //
hasTaxes("EUR", 1301.66 + 71.59), hasFees("EUR", 0.00))));
}

@Test
public void testCryptoKauf01()
{
List<Exception> errors = new ArrayList<>();

List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "CryptoKauf01.txt"), errors);

assertThat(errors, empty());
assertThat(countSecurities(results), is(1L));
assertThat(countBuySell(results), is(1L));
assertThat(countAccountTransactions(results), is(0L));
assertThat(results.size(), is(2));
new AssertImportActions().check(results, CurrencyUnit.EUR);

// check security
assertThat(results, hasItem(security( //
hasIsin(null), hasWkn(null), hasTicker("BTC"), //
hasName("Bitcoin"), //
hasCurrencyCode("EUR"), //
hasFeed(CoinGeckoQuoteFeed.ID), //
hasFeedProperty(CoinGeckoQuoteFeed.COINGECKO_COIN_ID, "bitcoin"))));

// check buy sell transaction
assertThat(results, hasItem(purchase( //
hasDate("2024-01-02T11:04:16"), hasShares(0.0024), //
hasSource("CryptoKauf01.txt"), //
hasNote("Vorgangs-Nr.: KRY 000000123456"), //
hasAmount("EUR", 101.75), hasGrossValue("EUR", 100.75), //
hasTaxes("EUR", 0.00), hasFees("EUR", 1.00))));
}

@Test
public void testVorabpauschale01()
{
Expand Down Expand Up @@ -4801,146 +4964,35 @@ public void testEinbuchung01()
}

@Test
public void testAusbuchung01()
{
BaaderBankPDFExtractor extractor = new BaaderBankPDFExtractor(new Client());

List<Exception> errors = new ArrayList<>();

List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Ausbuchung01.txt"), errors);

assertThat(errors, empty());
assertThat(results.size(), is(2));
new AssertImportActions().check(results, CurrencyUnit.EUR);

// check security
Security security = results.stream().filter(SecurityItem.class::isInstance).findFirst()
.orElseThrow(IllegalArgumentException::new).getSecurity();
assertThat(security.getIsin(), is("DE000HB2KBG9"));
assertThat(security.getWkn(), is("HB2KBG"));
assertNull(security.getTickerSymbol());
assertThat(security.getName(), is("UniCredit Bank AG HVB Inline 18.05.22 BASF 45-70"));
assertThat(security.getCurrencyCode(), is(CurrencyUnit.EUR));

// check buy sell transaction
BuySellEntry entry = (BuySellEntry) results.stream().filter(BuySellEntryItem.class::isInstance).findFirst()
.orElseThrow(IllegalArgumentException::new).getSubject();

assertThat(entry.getPortfolioTransaction().getType(), is(PortfolioTransaction.Type.SELL));
assertThat(entry.getAccountTransaction().getType(), is(AccountTransaction.Type.SELL));

assertThat(entry.getPortfolioTransaction().getDateTime(), is(LocalDateTime.parse("2022-05-25T00:00")));
assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(6)));
assertThat(entry.getSource(), is("Ausbuchung01.txt"));
assertThat(entry.getNote(), is("Vorgangs-Nr.: 8679954 | Ablauf der Optionsfrist"));

assertThat(entry.getPortfolioTransaction().getMonetaryAmount(),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(60.00))));
assertThat(entry.getPortfolioTransaction().getGrossValue(),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(60.00))));
assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.TAX),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0.00))));
assertThat(entry.getPortfolioTransaction().getUnitSum(Unit.Type.FEE),
is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0.00))));
}

@Test
public void testAusbuchung02()
public void testFusion01()
{
BaaderBankPDFExtractor extractor = new BaaderBankPDFExtractor(new Client());

List<Exception> errors = new ArrayList<>();

List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Ausbuchung02.txt"), errors);

assertThat(errors, empty());
assertThat(countSecurities(results), is(1L));
assertThat(countBuySell(results), is(1L));
assertThat(countAccountTransactions(results), is(0L));
assertThat(results.size(), is(2));
new AssertImportActions().check(results, CurrencyUnit.EUR);

// check security
assertThat(results, hasItem(security( //
hasIsin("US60468T1051"), hasWkn("A1W1XV"), hasTicker(null), //
hasName("Mirati Therapeutics Inc. Registered Shares DL -,01"), //
hasCurrencyCode("USD"))));

// check buy sell transaction
assertThat(results, hasItem(sale( //
hasDate("2024-01-25T00:00"), hasShares(4), //
hasSource("Ausbuchung02.txt"), //
hasNote("Vorgangs-Nr.: 25742277 | Obligatorische Barabfindung"), //
hasAmount("EUR", 212.68), hasGrossValue("EUR", 212.68), //
hasForexGrossValue("USD", 232.00), //
hasTaxes("EUR", 0.00), hasFees("EUR", 0.00))));
}

@Test
public void testAusbuchung02WithSecurityInEUR()
{
Security security = new Security("Mirati Therapeutics Inc. Registered Shares DL -,01", CurrencyUnit.EUR);
security.setIsin("US60468T1051");
security.setWkn("A1W1XV");

Client client = new Client();
client.addSecurity(security);

BaaderBankPDFExtractor extractor = new BaaderBankPDFExtractor(client);

List<Exception> errors = new ArrayList<>();

List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Ausbuchung02.txt"), errors);

assertThat(errors, empty());
assertThat(countSecurities(results), is(0L));
assertThat(countBuySell(results), is(1L));
assertThat(countAccountTransactions(results), is(0L));
assertThat(results.size(), is(1));
new AssertImportActions().check(results, CurrencyUnit.EUR);

// check buy sell transaction
assertThat(results, hasItem(sale( //
hasDate("2024-01-25T00:00"), hasShares(4), //
hasSource("Ausbuchung02.txt"), //
hasNote("Vorgangs-Nr.: 25742277 | Obligatorische Barabfindung"), //
hasAmount("EUR", 212.68), hasGrossValue("EUR", 212.68), //
hasTaxes("EUR", 0.00), hasFees("EUR", 0.00), //
check(tx -> {
CheckCurrenciesAction c = new CheckCurrenciesAction();
Status s = c.process((PortfolioTransaction) tx, new Portfolio());
assertThat(s, is(Status.OK_STATUS));
}))));
}

@Test
public void testCryptoKauf01()
{
List<Exception> errors = new ArrayList<>();

List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "CryptoKauf01.txt"), errors);
List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Fusion01.txt"), errors);

assertThat(errors, empty());
assertThat(countSecurities(results), is(1L));
assertThat(countBuySell(results), is(1L));
assertThat(countAccountTransactions(results), is(0L));
assertThat(countBuySell(results), is(0L));
assertThat(countAccountTransactions(results), is(1L));
assertThat(results.size(), is(2));
new AssertImportActions().check(results, CurrencyUnit.EUR);

// check security
assertThat(results, hasItem(security( //
hasIsin(null), hasWkn(null), hasTicker("BTC"), //
hasName("Bitcoin"), //
hasCurrencyCode("EUR"), //
hasFeed(CoinGeckoQuoteFeed.ID), //
hasFeedProperty(CoinGeckoQuoteFeed.COINGECKO_COIN_ID, "bitcoin"))));
hasIsin("LU1861134382"), hasWkn("A2JSDA"), hasTicker(null), //
hasName("AIS-AM.WORLD SRI PAB Act.Nom. UCITS ETF DR (C)o.N."), //
hasCurrencyCode("EUR"))));

// check buy sell transaction
assertThat(results, hasItem(purchase( //
hasDate("2024-01-02T11:04:16"), hasShares(0.0024), //
hasSource("CryptoKauf01.txt"), //
hasNote("Vorgangs-Nr.: KRY 000000123456"), //
hasAmount("EUR", 101.75), hasGrossValue("EUR", 100.75), //
hasTaxes("EUR", 0.00), hasFees("EUR", 1.00))));
// check unsupported transaction
assertThat(results, hasItem(withFailureMessage( //
Messages.MsgErrorTransactionTypeNotSupported, //
outboundDelivery( //
hasDate("2024-01-18T00:00"), hasShares(277.691), //
hasSource("Fusion01.txt"), //
hasNote(null), //
hasAmount("EUR", 0.00), hasGrossValue("EUR", 0.00), //
hasTaxes("EUR", 0.00), hasFees("EUR", 0.00)))));
}
}