Skip to content

Commit

Permalink
Modify Directa SIM PDF-Importer to support new transaction
Browse files Browse the repository at this point in the history
Closes #4445
  • Loading branch information
Nirus2000 committed Jan 4, 2025
1 parent 3202aa6 commit d75c8e9
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
PDFBox Version: 1.8.17
Portfolio Performance Version: 0.73.0
System: linux | x86_64 | 23 | Arch Linux
-----------------------------------------
Signor
NySCUtY IyWjXm
WTmNCh QIjIafB f BBszIwhEpy 7
51961 kQjxQ btJ OukDTd'
Goszrd
PErSD O2036
Nota Informativa per l'ordine c6954896449059
Vi Confermiamo il Vs. ordine sopra riportato del 23.09.2023 Data scadenza 23.10.2023
per l'acquisto di: 9 CROCS INC ISIN US2270461096
sottostante cod. mult. 1
eseguito per: 9
tramite l'intermediario ViewTrade
Tipo di Operazione: Acquisto Mercato di esecuzione: Borsa - NASDAQ
Quantita' USD Euro Prezzo Valuta
24.09.2023 19:02:34 Richiesta Immissione 9 780,3000 732,88* 86,70
25.09.2023 14:30:10 Inoltro
25.09.2023 14:30:15 In negoziazione
25.09.2023 15:30:14 Eseguito (09:30:14) 9 769,7700 722,99* 85,53 27.09.2023
Controvalore: 769,7700 722,99* 85,53
Commissioni: 9,0000 8,45*
Totale a Vs. Debito : 778,7700 731,44
Gli effetti fiscali saranno disponibili a data valuta nel menu Info - 2b.Capital Gain
=C/$= 1,06470
* - cambio provvisorio
Torino, 25.09.2023
DIRECTA SIM
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package name.abuchen.portfolio.datatransfer.pdf.directasim;

import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.check;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasAmount;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasCurrencyCode;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasDate;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasFees;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasForexGrossValue;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasGrossValue;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasIsin;
import static name.abuchen.portfolio.datatransfer.ExtractorMatchers.hasName;
Expand All @@ -29,10 +31,15 @@
import org.junit.Test;

import name.abuchen.portfolio.datatransfer.Extractor.Item;
import name.abuchen.portfolio.datatransfer.ImportAction.Status;
import name.abuchen.portfolio.datatransfer.actions.AssertImportActions;
import name.abuchen.portfolio.datatransfer.actions.CheckCurrenciesAction;
import name.abuchen.portfolio.datatransfer.pdf.DirectaSimPDFExtractor;
import name.abuchen.portfolio.datatransfer.pdf.PDFInputFile;
import name.abuchen.portfolio.model.Client;
import name.abuchen.portfolio.model.Portfolio;
import name.abuchen.portfolio.model.PortfolioTransaction;
import name.abuchen.portfolio.model.Security;
import name.abuchen.portfolio.money.CurrencyUnit;

@SuppressWarnings("nls")
Expand Down Expand Up @@ -62,7 +69,7 @@ public void testSecurityBuy01()

// check buy sell transaction
assertThat(results, hasItem(purchase( //
hasDate("2024-01-05T14:02:36"), hasShares(29), //
hasDate("2024-01-05T14:02:36"), hasShares(29.00), //
hasSource("Buy01.txt"), //
hasNote("Ordine T1673620593440"), //
hasAmount("EUR", 3079.29), hasGrossValue("EUR", 3074.29), //
Expand Down Expand Up @@ -93,7 +100,7 @@ public void testSecurityBuy02()

// check buy sell transaction
assertThat(results, hasItem(purchase( //
hasDate("2024-01-09T11:57:34"), hasShares(2900), //
hasDate("2024-01-09T11:57:34"), hasShares(2900.00), //
hasSource("Buy02.txt"), //
hasNote("Ordine X4171246514720"), //
hasAmount("EUR", 1511.58), hasGrossValue("EUR", 1502.08), //
Expand Down Expand Up @@ -124,11 +131,78 @@ public void testSecurityBuy03()

// check buy sell transaction
assertThat(results, hasItem(purchase( //
hasDate("2024-04-12T09:04:21"), hasShares(7), //
hasDate("2024-04-12T09:04:21"), hasShares(7.00), //
hasSource("Buy03.txt"), //
hasNote("Ordine P9417565891845"), //
hasAmount("EUR", 829.15), hasGrossValue("EUR", 829.15), //
hasTaxes("EUR", 0.00), hasFees("EUR", 0.00))));
}

@Test
public void testSecurityBuy04()
{
DirectaSimPDFExtractor extractor = new DirectaSimPDFExtractor(new Client());

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

List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Buy04.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("US2270461096"), hasWkn(null), hasTicker(null), //
hasName("CROCS INC"), //
hasCurrencyCode("USD"))));

// check buy sell transaction
assertThat(results, hasItem(purchase( //
hasDate("2023-09-25T15:30:14"), hasShares(9.00), //
hasSource("Buy04.txt"), //
hasNote("Ordine c6954896449059"), //
hasAmount("EUR", 731.44), hasGrossValue("EUR", 722.99), //
hasForexGrossValue("USD", 769.77), //
hasTaxes("EUR", 0.00), hasFees("EUR", 8.45))));
}

@Test
public void testSecurityBuy04WithSecurityInEUR()
{
Security security = new Security("CROCS INC", CurrencyUnit.EUR);
security.setIsin("US2270461096");

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

DirectaSimPDFExtractor extractor = new DirectaSimPDFExtractor(client);

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

List<Item> results = extractor.extract(PDFInputFile.loadTestCase(getClass(), "Buy04.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(purchase( //
hasDate("2023-09-25T15:30:14"), hasShares(9.00), //
hasSource("Buy04.txt"), //
hasNote("Ordine c6954896449059"), //
hasAmount("EUR", 731.44), hasGrossValue("EUR", 722.99), //
hasTaxes("EUR", 0.00), hasFees("EUR", 8.45), //
check(tx -> {
CheckCurrenciesAction c = new CheckCurrenciesAction();
Status s = c.process((PortfolioTransaction) tx, new Portfolio());
assertThat(s, is(Status.OK_STATUS));
}))));
}
}
Loading

0 comments on commit d75c8e9

Please sign in to comment.