Search in sources :

Example 51 with Portfolio

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

the class AccountContextMenu method menuAboutToShow.

public void menuAboutToShow(IMenuManager manager, final Account account, final Security security) {
    if (account == null)
        return;
    for (final AccountTransaction.Type type : // 
    EnumSet.of(// 
    AccountTransaction.Type.DEPOSIT, // 
    AccountTransaction.Type.REMOVAL, // 
    AccountTransaction.Type.TAXES, // 
    AccountTransaction.Type.TAX_REFUND, // 
    AccountTransaction.Type.FEES, // 
    AccountTransaction.Type.FEES_REFUND, // 
    AccountTransaction.Type.INTEREST, AccountTransaction.Type.INTEREST_CHARGE)) {
        // $NON-NLS-1$
        new OpenDialogAction(owner, type.toString() + "...").type(// 
        AccountTransactionDialog.class).parameters(// 
        type).with(// 
        account).with(// 
        security).addTo(manager);
    }
    manager.add(new Separator());
    // 
    new OpenDialogAction(owner, Messages.AccountMenuTransfer).type(// 
    AccountTransferDialog.class).with(// 
    account).addTo(manager);
    manager.add(new Separator());
    if (!owner.getClient().getActivePortfolios().isEmpty() && !owner.getClient().getSecurities().isEmpty()) {
        // preselect a portfolio that has the current
        // account as a reference account
        final Portfolio[] portfolio = new Portfolio[1];
        for (Portfolio p : owner.getClient().getActivePortfolios()) {
            if (p.getReferenceAccount().equals(account)) {
                portfolio[0] = p;
                break;
            }
        }
        // $NON-NLS-1$
        new OpenDialogAction(owner, Messages.SecurityMenuBuy + "...").type(// 
        SecurityTransactionDialog.class).parameters(// 
        PortfolioTransaction.Type.BUY).with(// 
        portfolio[0]).with(// 
        security).addTo(manager);
        // $NON-NLS-1$
        new OpenDialogAction(owner, Messages.SecurityMenuSell + "...").type(// 
        SecurityTransactionDialog.class).parameters(// 
        PortfolioTransaction.Type.SELL).with(// 
        portfolio[0]).with(// 
        security).addTo(manager);
        // $NON-NLS-1$
        new OpenDialogAction(owner, Messages.SecurityMenuDividends + "...").type(// 
        AccountTransactionDialog.class).parameters(// 
        AccountTransaction.Type.DIVIDENDS).with(// 
        account).with(// 
        security).addTo(manager);
    }
}
Also used : Portfolio(name.abuchen.portfolio.model.Portfolio) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Separator(org.eclipse.jface.action.Separator) OpenDialogAction(name.abuchen.portfolio.ui.dialogs.transactions.OpenDialogAction)

Example 52 with Portfolio

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

the class ClientFilterMenu method buildItem.

private Item buildItem(Object[] selected) {
    List<Portfolio> portfolios = Arrays.stream(selected).filter(o -> o instanceof Portfolio).map(o -> (Portfolio) o).collect(Collectors.toList());
    List<Account> accounts = Arrays.stream(selected).filter(o -> o instanceof Account).map(o -> (Account) o).collect(Collectors.toList());
    String label = // $NON-NLS-1$
    String.join(// $NON-NLS-1$
    ", ", Arrays.stream(selected).map(String::valueOf).collect(Collectors.toList()));
    String uuids = // $NON-NLS-1$
    String.join(// $NON-NLS-1$
    ",", Arrays.stream(selected).map(o -> o instanceof Account ? ((Account) o).getUUID() : ((Portfolio) o).getUUID()).collect(Collectors.toList()));
    return new Item(label, uuids, new PortfolioClientFilter(portfolios, accounts));
}
Also used : Arrays(java.util.Arrays) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Client(name.abuchen.portfolio.model.Client) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Messages(name.abuchen.portfolio.ui.Messages) Map(java.util.Map) ListSelectionDialog(name.abuchen.portfolio.ui.dialogs.ListSelectionDialog) LinkedList(java.util.LinkedList) Portfolio(name.abuchen.portfolio.model.Portfolio) Separator(org.eclipse.jface.action.Separator) Account(name.abuchen.portfolio.model.Account) ClientFilter(name.abuchen.portfolio.snapshot.filter.ClientFilter) Action(org.eclipse.jface.action.Action) Display(org.eclipse.swt.widgets.Display) PortfolioClientFilter(name.abuchen.portfolio.snapshot.filter.PortfolioClientFilter) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) Stream(java.util.stream.Stream) IMenuManager(org.eclipse.jface.action.IMenuManager) Collections(java.util.Collections) IMenuListener(org.eclipse.jface.action.IMenuListener) LabelProvider(org.eclipse.jface.viewers.LabelProvider) Account(name.abuchen.portfolio.model.Account) Portfolio(name.abuchen.portfolio.model.Portfolio) PortfolioClientFilter(name.abuchen.portfolio.snapshot.filter.PortfolioClientFilter)

Example 53 with Portfolio

use of name.abuchen.portfolio.model.Portfolio 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 54 with Portfolio

use of name.abuchen.portfolio.model.Portfolio 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 55 with Portfolio

use of name.abuchen.portfolio.model.Portfolio 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)

Aggregations

Portfolio (name.abuchen.portfolio.model.Portfolio)75 Security (name.abuchen.portfolio.model.Security)52 PortfolioTransaction (name.abuchen.portfolio.model.PortfolioTransaction)44 Test (org.junit.Test)41 Account (name.abuchen.portfolio.model.Account)39 Client (name.abuchen.portfolio.model.Client)38 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)24 PortfolioBuilder (name.abuchen.portfolio.PortfolioBuilder)21 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)20 Unit (name.abuchen.portfolio.model.Transaction.Unit)19 SecurityBuilder (name.abuchen.portfolio.SecurityBuilder)17 LocalDate (java.time.LocalDate)16 CurrencyConverter (name.abuchen.portfolio.money.CurrencyConverter)12 BuySellEntry (name.abuchen.portfolio.model.BuySellEntry)11 Money (name.abuchen.portfolio.money.Money)11 ArrayList (java.util.ArrayList)10 Values (name.abuchen.portfolio.money.Values)10 AccountTransferEntry (name.abuchen.portfolio.model.AccountTransferEntry)9 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)9 Collections (java.util.Collections)8