Search in sources :

Example 56 with Account

use of name.abuchen.portfolio.model.Account in project portfolio by buchen.

the class CheckCurrenciesAccountTransactionTest method testCheckTransactionUnitIfCurrenciesAreEqual.

@Test
public void testCheckTransactionUnitIfCurrenciesAreEqual() {
    Account account = new Account();
    account.setCurrencyCode("EUR");
    Security security = new Security("", "EUR");
    AccountTransaction t = new AccountTransaction();
    t.setMonetaryAmount(Money.of("EUR", 1_00));
    t.setSecurity(security);
    assertThat(action.process(t, account).getCode(), is(Status.Code.OK));
    Unit unit = new Unit(Unit.Type.GROSS_VALUE, Money.of("EUR", 1_00), Money.of("USD", 2_00), BigDecimal.valueOf(0.5));
    t.addUnit(unit);
    assertThat(action.process(t, account).getCode(), is(Status.Code.ERROR));
}
Also used : Account(name.abuchen.portfolio.model.Account) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Security(name.abuchen.portfolio.model.Security) Unit(name.abuchen.portfolio.model.Transaction.Unit) Test(org.junit.Test)

Example 57 with Account

use of name.abuchen.portfolio.model.Account in project portfolio by buchen.

the class CheckCurrenciesAccountTransactionTest method testCheckTransactionUnitIfCurrenciesAreDifferent.

@Test
public void testCheckTransactionUnitIfCurrenciesAreDifferent() {
    Account account = new Account();
    account.setCurrencyCode("EUR");
    Security security = new Security("", "USD");
    Unit unit = new Unit(Unit.Type.GROSS_VALUE, Money.of("EUR", 1_00), Money.of("USD", 2_00), BigDecimal.valueOf(0.5));
    AccountTransaction t = new AccountTransaction();
    t.setMonetaryAmount(Money.of("EUR", 1_00));
    t.setSecurity(security);
    t.addUnit(unit);
    assertThat(action.process(t, account).getCode(), is(Status.Code.OK));
    t.removeUnit(unit);
    assertThat(action.process(t, account).getCode(), is(Status.Code.ERROR));
    Unit other = new Unit(Unit.Type.GROSS_VALUE, Money.of("EUR", 1_00), Money.of("JPY", 2_00), BigDecimal.valueOf(0.5));
    t.addUnit(other);
    assertThat(action.process(t, account).getCode(), is(Status.Code.ERROR));
}
Also used : Account(name.abuchen.portfolio.model.Account) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Security(name.abuchen.portfolio.model.Security) Unit(name.abuchen.portfolio.model.Transaction.Unit) Test(org.junit.Test)

Example 58 with Account

use of name.abuchen.portfolio.model.Account in project portfolio by buchen.

the class InsertActionTest method testConversionOfBuySellEntry.

@Test
public void testConversionOfBuySellEntry() {
    Account account = client.getAccounts().get(0);
    Portfolio portfolio = client.getPortfolios().get(0);
    InsertAction action = new InsertAction(client);
    action.setConvertBuySellToDelivery(true);
    action.process(entry, account, portfolio);
    assertThat(account.getTransactions().isEmpty(), is(true));
    assertThat(portfolio.getTransactions().size(), is(1));
    PortfolioTransaction delivery = portfolio.getTransactions().get(0);
    assertThat(delivery.getType(), is(Type.DELIVERY_INBOUND));
    assertTransaction(delivery);
}
Also used : Account(name.abuchen.portfolio.model.Account) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) Test(org.junit.Test)

Example 59 with Account

use of name.abuchen.portfolio.model.Account in project portfolio by buchen.

the class InsertActionTest method testInsertOfBuySellEntry.

@Test
public void testInsertOfBuySellEntry() {
    Account account = client.getAccounts().get(0);
    Portfolio portfolio = client.getPortfolios().get(0);
    InsertAction action = new InsertAction(client);
    action.process(entry, account, portfolio);
    assertThat(account.getTransactions().size(), is(1));
    assertThat(portfolio.getTransactions().size(), is(1));
    PortfolioTransaction t = portfolio.getTransactions().get(0);
    assertThat(t.getType(), is(Type.BUY));
    assertTransaction(t);
}
Also used : Account(name.abuchen.portfolio.model.Account) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) Test(org.junit.Test)

Example 60 with Account

use of name.abuchen.portfolio.model.Account in project portfolio by buchen.

the class InsertActionTest method prepare.

@Before
public void prepare() {
    client = new Client();
    Security security = new Security();
    client.addSecurity(security);
    Portfolio portfolio = new Portfolio();
    client.addPortfolio(portfolio);
    Account account = new Account();
    client.addAccount(account);
    entry = new BuySellEntry();
    entry.setType(Type.BUY);
    entry.setMonetaryAmount(Money.of(CurrencyUnit.EUR, 9_99));
    entry.setShares(99);
    entry.setDate(transactionDate);
    entry.setSecurity(security);
    entry.setNote("note");
    entry.getPortfolioTransaction().addUnit(new Unit(Unit.Type.TAX, Money.of(CurrencyUnit.EUR, 1_99)));
}
Also used : Account(name.abuchen.portfolio.model.Account) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Portfolio(name.abuchen.portfolio.model.Portfolio) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit) Unit(name.abuchen.portfolio.model.Transaction.Unit) Before(org.junit.Before)

Aggregations

Account (name.abuchen.portfolio.model.Account)75 Security (name.abuchen.portfolio.model.Security)39 Client (name.abuchen.portfolio.model.Client)38 Portfolio (name.abuchen.portfolio.model.Portfolio)37 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)35 Test (org.junit.Test)31 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)25 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)22 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)21 ArrayList (java.util.ArrayList)17 LocalDate (java.time.LocalDate)16 AccountBuilder (name.abuchen.portfolio.AccountBuilder)14 Unit (name.abuchen.portfolio.model.Transaction.Unit)14 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)13 PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)12 Money (name.abuchen.portfolio.money.Money)12 Collections (java.util.Collections)11 List (java.util.List)11 AccountTransferEntry (name.abuchen.portfolio.model.AccountTransferEntry)11 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)11