use of name.abuchen.portfolio.model.AccountTransferEntry in project portfolio by buchen.
the class CSVAccountTransactionExtractorTest method testTransferTransaction.
@Test
public void testTransferTransaction() {
Client client = new Client();
CSVExtractor extractor = new CSVAccountTransactionExtractor(client);
List<Exception> errors = new ArrayList<Exception>();
List<Item> results = extractor.extract(0, //
Arrays.<String[]>asList(new String[] { "2013-01-01", "", "", "", "100", "EUR", "TRANSFER_OUT", "", "", "Notiz" }), buildField2Column(extractor), errors);
assertThat(results.size(), is(1));
assertThat(errors, empty());
AccountTransferEntry entry = (AccountTransferEntry) results.get(0).getSubject();
AccountTransaction t = entry.getSourceTransaction();
assertThat(t.getType(), is(AccountTransaction.Type.TRANSFER_OUT));
assertThat(t.getMonetaryAmount(), is(Money.of(CurrencyUnit.EUR, 100_00)));
assertThat(t.getNote(), is("Notiz"));
assertThat(t.getDateTime(), is(LocalDateTime.parse("2013-01-01T00:00")));
assertThat(t.getShares(), is(0L));
assertThat(t.getSecurity(), is(nullValue()));
}
use of name.abuchen.portfolio.model.AccountTransferEntry in project portfolio by buchen.
the class ClientClassificationFilter method createTransferEntry.
private AccountTransferEntry createTransferEntry(AccountTransferEntry entry, int weight) {
AccountTransferEntry copy = new AccountTransferEntry();
copy.setDate(entry.getSourceTransaction().getDateTime());
copy.setNote(entry.getSourceTransaction().getNote());
copy.getSourceTransaction().setCurrencyCode(entry.getSourceTransaction().getCurrencyCode());
copy.getTargetTransaction().setCurrencyCode(entry.getTargetTransaction().getCurrencyCode());
copy.getSourceTransaction().setAmount(value(entry.getSourceTransaction().getAmount(), weight));
copy.getTargetTransaction().setAmount(value(entry.getTargetTransaction().getAmount(), weight));
return copy;
}
use of name.abuchen.portfolio.model.AccountTransferEntry in project portfolio by buchen.
the class ClientClassificationFilter method addTransferT.
private void addTransferT(CalculationState state, Account inboundAccount, AccountTransaction t) {
Account outboundAccount = (Account) t.getCrossEntry().getCrossOwner(t);
int inboundWeight = state.getWeight(inboundAccount);
int outboundWeight = state.getWeight(outboundAccount);
if (inboundWeight == outboundWeight && inboundWeight == Classification.ONE_HUNDRED_PERCENT) {
state.asReadOnly(inboundAccount).internalAddTransaction(t);
state.asReadOnly(outboundAccount).internalAddTransaction((AccountTransaction) t.getCrossEntry().getCrossTransaction(t));
} else if (inboundWeight == outboundWeight) {
AccountTransferEntry entry = createTransferEntry((AccountTransferEntry) t.getCrossEntry(), inboundWeight);
// entry#insert does not work with ReadOnlyAccount
state.asReadOnly(inboundAccount).internalAddTransaction(entry.getTargetTransaction());
state.asReadOnly(outboundAccount).internalAddTransaction(entry.getSourceTransaction());
} else if (inboundWeight < outboundWeight) {
AccountTransferEntry entry = createTransferEntry((AccountTransferEntry) t.getCrossEntry(), inboundWeight);
// entry#insert does not work with ReadOnlyAccount
state.asReadOnly(inboundAccount).internalAddTransaction(entry.getTargetTransaction());
state.asReadOnly(outboundAccount).internalAddTransaction(entry.getSourceTransaction());
AccountTransaction ot = (AccountTransaction) t.getCrossEntry().getCrossTransaction(t);
state.asReadOnly(outboundAccount).internalAddTransaction(new AccountTransaction(ot.getDateTime(), ot.getCurrencyCode(), value(ot.getAmount(), outboundWeight - inboundWeight), null, AccountTransaction.Type.REMOVAL));
} else // inboundWeight > outboundWeight
{
AccountTransferEntry entry = createTransferEntry((AccountTransferEntry) t.getCrossEntry(), outboundWeight);
// entry#insert does not work with ReadOnlyAccount
state.asReadOnly(inboundAccount).internalAddTransaction(entry.getTargetTransaction());
state.asReadOnly(outboundAccount).internalAddTransaction(entry.getSourceTransaction());
state.asReadOnly(inboundAccount).internalAddTransaction(new AccountTransaction(t.getDateTime(), t.getCurrencyCode(), value(t.getAmount(), inboundWeight - outboundWeight), null, AccountTransaction.Type.DEPOSIT));
}
}
use of name.abuchen.portfolio.model.AccountTransferEntry in project portfolio by buchen.
the class ClientPerformanceSnapshotTest method testCurrencyGainsWithTransferalInOtherCurrencies.
@Test
public void testCurrencyGainsWithTransferalInOtherCurrencies() {
Client client = new Client();
Account usd = //
new AccountBuilder("USD").deposit_("2015-01-01", //
1000_00).addTo(client);
Account cad = //
new AccountBuilder("CAD").deposit_("2015-01-01", //
1000_00).addTo(client);
// insert account transfer
AccountTransferEntry entry = new AccountTransferEntry(usd, cad);
entry.setDate(LocalDateTime.parse("2015-01-10T00:00"));
AccountTransaction source = entry.getSourceTransaction();
AccountTransaction target = entry.getTargetTransaction();
source.setMonetaryAmount(Money.of("USD", 500_00));
target.setMonetaryAmount(Money.of("CAD", 1000_00));
source.addUnit(new Unit(Unit.Type.GROSS_VALUE, source.getMonetaryAmount(), target.getMonetaryAmount(), BigDecimal.valueOf(.5)));
entry.insert();
// check currency gain calculation of client performance snapshot
CurrencyConverter converter = new TestCurrencyConverter();
ClientPerformanceSnapshot snapshot = new //
ClientPerformanceSnapshot(//
client, //
converter, LocalDate.parse("2015-01-01"), LocalDate.parse("2015-01-15"));
MutableMoney currencyGains = MutableMoney.of(converter.getTermCurrency());
currencyGains.subtract(snapshot.getValue(CategoryType.INITIAL_VALUE));
currencyGains.subtract(snapshot.getValue(CategoryType.CAPITAL_GAINS));
currencyGains.subtract(snapshot.getValue(CategoryType.EARNINGS));
currencyGains.add(snapshot.getValue(CategoryType.FEES));
currencyGains.add(snapshot.getValue(CategoryType.TAXES));
currencyGains.add(snapshot.getValue(CategoryType.TRANSFERS));
currencyGains.add(snapshot.getValue(CategoryType.FINAL_VALUE));
assertThat(snapshot.getCategoryByType(CategoryType.CURRENCY_GAINS).getValuation(), is(currencyGains.toMoney()));
}
use of name.abuchen.portfolio.model.AccountTransferEntry in project portfolio by buchen.
the class PortfolioClientFilterTest method testCrossAccountTransfersAreKept.
@Test
public void testCrossAccountTransfersAreKept() {
Account accountA = client.getAccounts().get(0);
Account accountB = client.getAccounts().get(1);
AccountTransferEntry entry = new AccountTransferEntry(accountA, accountB);
entry.setDate(LocalDateTime.parse("2016-04-01T00:00"));
entry.setAmount(Values.Amount.factorize(10));
entry.setCurrencyCode(accountA.getCurrencyCode());
entry.insert();
Client result = new PortfolioClientFilter(Collections.emptyList(), Arrays.asList(accountA, accountB)).filter(client);
assertThat(result.getPortfolios(), empty());
assertThat(result.getAccounts().size(), is(2));
Account account = result.getAccounts().get(0);
// check that the 4 transactions are transformed:
// - buy -> removal
// - deposit
// - dividend -> deposit
// - transfer must exist
assertThat(account.getTransactions().size(), is(4));
assertThat(//
account.getTransactions().stream().filter(//
t -> t.getType() == AccountTransaction.Type.REMOVAL).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-02-01T00:00"))).findAny().isPresent(), is(true));
assertThat(//
account.getTransactions().stream().filter(//
t -> t.getType() == AccountTransaction.Type.DEPOSIT).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-01-01T00:00"))).findAny().isPresent(), is(true));
assertThat(//
account.getTransactions().stream().filter(//
t -> t.getType() == AccountTransaction.Type.DEPOSIT).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-03-01T00:00"))).findAny().isPresent(), is(true));
assertThat(//
account.getTransactions().stream().filter(//
t -> t.getType() == AccountTransaction.Type.TRANSFER_OUT).filter(t -> t.getDateTime().equals(LocalDateTime.parse("2016-04-01T00:00"))).findAny().isPresent(), is(true));
}
Aggregations