Search in sources :

Example 46 with Unit

use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.

the class CheckCurrenciesPortfolioTransactionTest method testNoForexGrossValueExistsIfCurrenciesMatch.

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

Example 47 with Unit

use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.

the class CheckCurrenciesPortfolioTransactionTest method testNoForexGrossValueExistsIfCurrenciesMatchEvenIfNoForex.

@Test
public void testNoForexGrossValueExistsIfCurrenciesMatchEvenIfNoForex() {
    Portfolio portfolio = new Portfolio();
    Security security = new Security("", "EUR");
    PortfolioTransaction t = new PortfolioTransaction();
    t.setType(Type.DELIVERY_INBOUND);
    t.setMonetaryAmount(Money.of("EUR", 1_00));
    t.setSecurity(security);
    t.addUnit(new Unit(Unit.Type.GROSS_VALUE, Money.of("EUR", 1_00)));
    assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) Security(name.abuchen.portfolio.model.Security) Unit(name.abuchen.portfolio.model.Transaction.Unit) Test(org.junit.Test)

Example 48 with Unit

use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.

the class CheckCurrenciesPortfolioTransactionTest method testTransactionTaxesAndFeesAddUpForOutboundDeliveries.

@Test
public void testTransactionTaxesAndFeesAddUpForOutboundDeliveries() {
    Portfolio portfolio = new Portfolio();
    Security security = new Security("", "EUR");
    Unit tax = new Unit(Unit.Type.TAX, Money.of("EUR", 5_00));
    Unit fee = new Unit(Unit.Type.FEE, Money.of("EUR", 5_00));
    PortfolioTransaction t = new PortfolioTransaction();
    t.setType(Type.DELIVERY_OUTBOUND);
    t.setMonetaryAmount(Money.of("EUR", 20_00));
    t.setSecurity(security);
    t.addUnit(fee);
    t.addUnit(tax);
    assertThat(action.process(t, portfolio).getCode(), is(Status.Code.OK));
    t.setMonetaryAmount(Money.of("EUR", 7_00));
    assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
    t.setType(Type.DELIVERY_INBOUND);
    assertThat(action.process(t, portfolio).getCode(), is(Status.Code.OK));
    t.setType(Type.DELIVERY_OUTBOUND);
    t.removeUnit(tax);
    assertThat(action.process(t, portfolio).getCode(), is(Status.Code.OK));
    t.setMonetaryAmount(Money.of("EUR", 3_00));
    assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
    t.setType(Type.DELIVERY_INBOUND);
    assertThat(action.process(t, portfolio).getCode(), is(Status.Code.OK));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) Security(name.abuchen.portfolio.model.Security) Unit(name.abuchen.portfolio.model.Transaction.Unit) Test(org.junit.Test)

Example 49 with Unit

use of name.abuchen.portfolio.model.Transaction.Unit in project portfolio by buchen.

the class CheckCurrenciesPortfolioTransactionTest method testTransactionForexTaxesAndFeesIfCurrenciesMatch.

@Test
public void testTransactionForexTaxesAndFeesIfCurrenciesMatch() {
    Portfolio portfolio = new Portfolio();
    Security security = new Security("", "EUR");
    Unit tax = new Unit(Unit.Type.TAX, Money.of("EUR", 5_00), Money.of("USD", 10_00), BigDecimal.valueOf(0.5));
    PortfolioTransaction t = new PortfolioTransaction();
    t.setType(Type.DELIVERY_OUTBOUND);
    t.setMonetaryAmount(Money.of("EUR", 20_00));
    t.setSecurity(security);
    t.addUnit(tax);
    assertThat(action.process(t, portfolio).getCode(), is(Status.Code.ERROR));
}
Also used : PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Portfolio(name.abuchen.portfolio.model.Portfolio) Security(name.abuchen.portfolio.model.Security) Unit(name.abuchen.portfolio.model.Transaction.Unit) Test(org.junit.Test)

Example 50 with Unit

use of name.abuchen.portfolio.model.Transaction.Unit 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

Unit (name.abuchen.portfolio.model.Transaction.Unit)75 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)58 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)51 Money (name.abuchen.portfolio.money.Money)51 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)50 Client (name.abuchen.portfolio.model.Client)50 IOException (java.io.IOException)44 Block (name.abuchen.portfolio.datatransfer.pdf.PDFParser.Block)37 DocumentType (name.abuchen.portfolio.datatransfer.pdf.PDFParser.DocumentType)37 Transaction (name.abuchen.portfolio.datatransfer.pdf.PDFParser.Transaction)37 BigDecimal (java.math.BigDecimal)32 Security (name.abuchen.portfolio.model.Security)26 Matcher (java.util.regex.Matcher)24 Pattern (java.util.regex.Pattern)24 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)24 Test (org.junit.Test)24 Map (java.util.Map)23 Values (name.abuchen.portfolio.money.Values)18 ArrayList (java.util.ArrayList)13 LocalDateTime (java.time.LocalDateTime)12