Search in sources :

Example 61 with Account

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

the class PortfolioBuilder method buysell.

private PortfolioBuilder buysell(Type type, Security security, String date, long shares, long amount, int fees) {
    if (portfolio.getReferenceAccount() == null) {
        account = new Account(UUID.randomUUID().toString());
        portfolio.setReferenceAccount(account);
    }
    BuySellEntry entry = new BuySellEntry(portfolio, portfolio.getReferenceAccount());
    entry.setType(type);
    entry.setDate(AccountBuilder.asDateTime(date));
    entry.setSecurity(security);
    entry.setShares(shares);
    entry.setCurrencyCode(CurrencyUnit.EUR);
    entry.setAmount(amount);
    entry.getPortfolioTransaction().addUnit(new Unit(Unit.Type.FEE, Money.of(CurrencyUnit.EUR, fees)));
    entry.insert();
    return this;
}
Also used : Account(name.abuchen.portfolio.model.Account) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) Unit(name.abuchen.portfolio.model.Transaction.Unit) CurrencyUnit(name.abuchen.portfolio.money.CurrencyUnit)

Example 62 with Account

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

the class CrossEntryCheckTest method setupClient.

@Before
public void setupClient() {
    client = new Client();
    account = new Account();
    client.addAccount(account);
    portfolio = new Portfolio();
    client.addPortfolio(portfolio);
    security = new Security();
    client.addSecurity(security);
}
Also used : Account(name.abuchen.portfolio.model.Account) Portfolio(name.abuchen.portfolio.model.Portfolio) Client(name.abuchen.portfolio.model.Client) Security(name.abuchen.portfolio.model.Security) Before(org.junit.Before)

Example 63 with Account

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

the class CrossEntryCheckTest method testThatNotTheSameAccountIsMatched.

@Test
public void testThatNotTheSameAccountIsMatched() {
    Account second = new Account();
    client.addAccount(second);
    LocalDateTime date = LocalDateTime.now();
    account.addTransaction(new AccountTransaction(date, CurrencyUnit.EUR, 2, security, AccountTransaction.Type.TRANSFER_IN));
    AccountTransaction umatched = new AccountTransaction(date, CurrencyUnit.EUR, 2, security, AccountTransaction.Type.TRANSFER_OUT);
    account.addTransaction(umatched);
    second.addTransaction(new AccountTransaction(date, CurrencyUnit.EUR, 2, security, AccountTransaction.Type.TRANSFER_OUT));
    List<Issue> issues = new CrossEntryCheck().execute(client);
    assertThat(issues.size(), is(1));
    assertThat(issues.get(0), is(instanceOf(MissingAccountTransferIssue.class)));
    assertThat(account.getTransactions(), hasItem(umatched));
    assertThat(second.getTransactions().get(0).getCrossEntry(), notNullValue());
    assertThat(second.getTransactions().get(0).getType(), is(AccountTransaction.Type.TRANSFER_OUT));
    applyFixes(client, issues);
}
Also used : LocalDateTime(java.time.LocalDateTime) Account(name.abuchen.portfolio.model.Account) Issue(name.abuchen.portfolio.checks.Issue) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Test(org.junit.Test)

Example 64 with Account

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

the class PortfolioListView method addNewButton.

private void addNewButton(ToolBar toolBar) {
    SimpleAction.Runnable newPortfolioAction = a -> {
        Portfolio portfolio = new Portfolio();
        portfolio.setName(Messages.LabelNoName);
        if (!getClient().getAccounts().isEmpty()) {
            portfolio.setReferenceAccount(getClient().getAccounts().get(0));
        } else {
            Account account = new Account();
            account.setName(Messages.LabelDefaultReferenceAccountName);
            getClient().addAccount(account);
            portfolio.setReferenceAccount(account);
        }
        getClient().addPortfolio(portfolio);
        markDirty();
        setInput();
        portfolios.editElement(portfolio, 0);
    };
    AbstractDropDown.create(toolBar, Messages.MenuCreatePortfolioOrTransaction, Images.PLUS.image(), SWT.NONE, (dd, manager) -> {
        manager.add(new SimpleAction(Messages.PortfolioMenuAdd, newPortfolioAction));
        manager.add(new Separator());
        Portfolio portfolio = (Portfolio) portfolios.getStructuredSelection().getFirstElement();
        new SecurityContextMenu(PortfolioListView.this).menuAboutToShow(manager, null, portfolio);
    });
}
Also used : NameColumn(name.abuchen.portfolio.ui.views.columns.NameColumn) NoteColumn(name.abuchen.portfolio.ui.views.columns.NoteColumn) TableViewer(org.eclipse.jface.viewers.TableViewer) CurrencyConverterImpl(name.abuchen.portfolio.money.CurrencyConverterImpl) NameColumnLabelProvider(name.abuchen.portfolio.ui.views.columns.NameColumn.NameColumnLabelProvider) ActionContributionItem(org.eclipse.jface.action.ActionContributionItem) ToolBar(org.eclipse.swt.widgets.ToolBar) Images(name.abuchen.portfolio.ui.Images) ListEditingSupport(name.abuchen.portfolio.ui.util.viewers.ListEditingSupport) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) Inject(javax.inject.Inject) ModificationListener(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport.ModificationListener) Composite(org.eclipse.swt.widgets.Composite) Messages(name.abuchen.portfolio.ui.Messages) Portfolio(name.abuchen.portfolio.model.Portfolio) Separator(org.eclipse.jface.action.Separator) Account(name.abuchen.portfolio.model.Account) CTabFolder(org.eclipse.swt.custom.CTabFolder) ExchangeRateProviderFactory(name.abuchen.portfolio.money.ExchangeRateProviderFactory) MenuManager(org.eclipse.jface.action.MenuManager) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Column(name.abuchen.portfolio.ui.util.viewers.Column) ColumnViewerSorter(name.abuchen.portfolio.ui.util.viewers.ColumnViewerSorter) Action(org.eclipse.jface.action.Action) Display(org.eclipse.swt.widgets.Display) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) PortfolioPart(name.abuchen.portfolio.ui.PortfolioPart) ColumnEditingSupport(name.abuchen.portfolio.ui.util.viewers.ColumnEditingSupport) PortfolioSnapshot(name.abuchen.portfolio.snapshot.PortfolioSnapshot) AbstractDropDown(name.abuchen.portfolio.ui.util.AbstractDropDown) ShowHideColumnHelper(name.abuchen.portfolio.ui.util.viewers.ShowHideColumnHelper) CTabItem(org.eclipse.swt.custom.CTabItem) Color(org.eclipse.swt.graphics.Color) IMenuManager(org.eclipse.jface.action.IMenuManager) CurrencyConverter(name.abuchen.portfolio.money.CurrencyConverter) LocalDate(java.time.LocalDate) SWT(org.eclipse.swt.SWT) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Account(name.abuchen.portfolio.model.Account) Portfolio(name.abuchen.portfolio.model.Portfolio) SimpleAction(name.abuchen.portfolio.ui.util.SimpleAction) Separator(org.eclipse.jface.action.Separator)

Example 65 with Account

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

the class ReviewExtractedItemsPage method preselectDropDowns.

private void preselectDropDowns() {
    // idea: generally one type of document (i.e. from the same bank) will
    // be imported into the same account
    List<Account> activeAccounts = client.getActiveAccounts();
    if (!activeAccounts.isEmpty()) {
        String uuid = preferences.getString(IMPORT_TARGET_ACCOUNT + extractor.getClass().getSimpleName());
        // do not trigger selection listener (-> do not user #setSelection)
        primaryAccount.getCombo().select(IntStream.range(0, activeAccounts.size()).filter(i -> activeAccounts.get(i).getUUID().equals(uuid)).findAny().orElse(0));
        secondaryAccount.getCombo().select(0);
    }
    List<Portfolio> activePortfolios = client.getActivePortfolios();
    if (!activePortfolios.isEmpty()) {
        String uuid = preferences.getString(IMPORT_TARGET_PORTFOLIO + extractor.getClass().getSimpleName());
        // do not trigger selection listener (-> do not user #setSelection)
        primaryPortfolio.getCombo().select(IntStream.range(0, activePortfolios.size()).filter(i -> activePortfolios.get(i).getUUID().equals(uuid)).findAny().orElse(0));
        secondaryPortfolio.getCombo().select(0);
    }
    if (extractor instanceof AssistantPDFExtractor) {
        String clazz = preferences.getString(IMPORT_TARGET_EXTRACTOR);
        List<Extractor> availableExtractors = ((AssistantPDFExtractor) extractor).getAvailableExtractors();
        OptionalInt index = IntStream.range(0, availableExtractors.size()).filter(i -> clazz.equals(availableExtractors.get(i).getClass().getName())).findAny();
        index.ifPresent(ii -> comboExtractors.getCombo().select(ii));
    }
}
Also used : IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Client(name.abuchen.portfolio.model.Client) TableViewer(org.eclipse.jface.viewers.TableViewer) StyledString(org.eclipse.jface.viewers.StyledString) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) AbstractWizardPage(name.abuchen.portfolio.ui.wizards.AbstractWizardPage) IStatus(org.eclipse.core.runtime.IStatus) Extractor(name.abuchen.portfolio.datatransfer.Extractor) ViewerCell(org.eclipse.jface.viewers.ViewerCell) Composite(org.eclipse.swt.widgets.Composite) ImportAction(name.abuchen.portfolio.datatransfer.ImportAction) AbstractClientJob(name.abuchen.portfolio.ui.AbstractClientJob) CheckCurrenciesAction(name.abuchen.portfolio.datatransfer.actions.CheckCurrenciesAction) Button(org.eclipse.swt.widgets.Button) Account(name.abuchen.portfolio.model.Account) MenuManager(org.eclipse.jface.action.MenuManager) Status(org.eclipse.core.runtime.Status) Security(name.abuchen.portfolio.model.Security) Display(org.eclipse.swt.widgets.Display) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) Collectors(java.util.stream.Collectors) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) List(java.util.List) Styler(org.eclipse.jface.viewers.StyledString.Styler) SWT(org.eclipse.swt.SWT) LabelOnly(name.abuchen.portfolio.ui.util.LabelOnly) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) Label(org.eclipse.swt.widgets.Label) IntStream(java.util.stream.IntStream) PortfolioTransaction(name.abuchen.portfolio.model.PortfolioTransaction) Money(name.abuchen.portfolio.money.Money) Values(name.abuchen.portfolio.money.Values) LocalDateTime(java.time.LocalDateTime) Images(name.abuchen.portfolio.ui.Images) Image(org.eclipse.swt.graphics.Image) TextStyle(org.eclipse.swt.graphics.TextStyle) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Table(org.eclipse.swt.widgets.Table) OptionalInt(java.util.OptionalInt) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) ArrayList(java.util.ArrayList) Annotated(name.abuchen.portfolio.model.Annotated) Messages(name.abuchen.portfolio.ui.Messages) CheckValidTypesAction(name.abuchen.portfolio.datatransfer.actions.CheckValidTypesAction) ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) DetectDuplicatesAction(name.abuchen.portfolio.datatransfer.actions.DetectDuplicatesAction) BuySellEntry(name.abuchen.portfolio.model.BuySellEntry) AccountTransferEntry(name.abuchen.portfolio.model.AccountTransferEntry) Portfolio(name.abuchen.portfolio.model.Portfolio) Combo(org.eclipse.swt.widgets.Combo) FormLayout(org.eclipse.swt.layout.FormLayout) AccountTransaction(name.abuchen.portfolio.model.AccountTransaction) Action(org.eclipse.jface.action.Action) FormAttachment(org.eclipse.swt.layout.FormAttachment) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) PortfolioPlugin(name.abuchen.portfolio.ui.PortfolioPlugin) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) AssistantPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor) FormDataFactory(name.abuchen.portfolio.ui.util.FormDataFactory) IMenuManager(org.eclipse.jface.action.IMenuManager) Menu(org.eclipse.swt.widgets.Menu) Collections(java.util.Collections) LabelProvider(org.eclipse.jface.viewers.LabelProvider) PortfolioTransferEntry(name.abuchen.portfolio.model.PortfolioTransferEntry) Account(name.abuchen.portfolio.model.Account) Portfolio(name.abuchen.portfolio.model.Portfolio) AssistantPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor) StyledString(org.eclipse.jface.viewers.StyledString) Extractor(name.abuchen.portfolio.datatransfer.Extractor) AssistantPDFExtractor(name.abuchen.portfolio.datatransfer.pdf.AssistantPDFExtractor) OptionalInt(java.util.OptionalInt)

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