Пример #1
0
  @Override
  public Status process(BuySellEntry entry, Account account, Portfolio portfolio) {
    if (convertBuySellToDelivery) {
      PortfolioTransaction t = entry.getPortfolioTransaction();

      PortfolioTransaction delivery = new PortfolioTransaction();
      delivery.setType(
          t.getType() == PortfolioTransaction.Type.BUY
              ? PortfolioTransaction.Type.DELIVERY_INBOUND
              : PortfolioTransaction.Type.DELIVERY_OUTBOUND);

      delivery.setDate(t.getDate());
      delivery.setSecurity(t.getSecurity());
      delivery.setMonetaryAmount(t.getMonetaryAmount());
      delivery.setNote(t.getNote());
      delivery.setShares(t.getShares());
      delivery.addUnits(t.getUnits());

      return process(delivery, portfolio);
    } else {
      entry.setPortfolio(portfolio);
      entry.setAccount(account);
      entry.insert();
      return Status.OK_STATUS;
    }
  }
  @Test
  public void testWertpapierVerkauf2() throws IOException {
    DeutscheBankPDFExctractor extractor =
        new DeutscheBankPDFExctractor(new Client()) {
          @Override
          String strip(File file) throws IOException {
            return from("DeutscheBankVerkauf2.txt");
          }
        };
    List<Exception> errors = new ArrayList<Exception>();

    List<Item> results = extractor.extract(Arrays.asList(new File("t")), errors);

    assertThat(errors, empty());
    assertThat(results.size(), is(2));
    new AssertImportActions().check(results, CurrencyUnit.EUR);

    assertSecurity(results);

    // check buy sell transaction
    Optional<Item> item = results.stream().filter(i -> i instanceof BuySellEntryItem).findFirst();
    assertThat(item.isPresent(), is(true));
    assertThat(item.get().getSubject(), instanceOf(BuySellEntry.class));
    BuySellEntry entry = (BuySellEntry) item.get().getSubject();

    assertThat(entry.getPortfolioTransaction().getType(), is(PortfolioTransaction.Type.SELL));
    assertThat(entry.getAccountTransaction().getType(), is(AccountTransaction.Type.SELL));

    assertThat(
        entry.getPortfolioTransaction().getMonetaryAmount(),
        is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(453.66))));
    assertThat(entry.getPortfolioTransaction().getDate(), is(LocalDate.parse("2015-01-30")));
    assertThat(entry.getPortfolioTransaction().getShares(), is(Values.Share.factorize(8)));
    assertThat(
        entry.getPortfolioTransaction().getUnitSum(Unit.Type.TAX),
        is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(0))));
    assertThat(
        entry.getPortfolioTransaction().getUnitSum(Unit.Type.FEE),
        is(Money.of(CurrencyUnit.EUR, Values.Amount.factorize(7.90 + 0.60 + 2))));
  }