예제 #1
0
 def test_get_open_entries__closed_without_open(self, entries, errors, _):
     """
       2011-02-02 close Assets:AccountA
     """
     self.assertEqualEntries(
         """
     """, summarize.get_open_entries(entries, date(2013, 1, 1)))
예제 #2
0
 def test_get_open_entries__after_first_close(self):
     # On the day after the first close.
     self.assertEqualEntries(
         """
       2011-02-01 open Assets:AccountB
       2011-03-01 open Assets:AccountC
     """, summarize.get_open_entries(self.entries, date(2011, 3, 16)))
예제 #3
0
def get_holdings_entries(entries, options_map):
    """Summarizes the entries to list of entries representing the final holdings..

    This list includes the latest prices entries as well. This can be used to
    load a full snapshot of holdings without including the entire history. This
    is a way of summarizing a balance sheet in a way that filters away history.

    Args:
      entries: A list of directives.
      options_map: A dict of parsed options.
    Returns:
      A string, the entries to print out.
    """

    # The entries will be created at the latest date, against an equity account.
    latest_date = entries[-1].date
    _, equity_account, _ = options.get_previous_accounts(options_map)

    # Get all the assets.
    holdings_list, _ = holdings.get_assets_holdings(entries, options_map)

    # Create synthetic entries for them.
    holdings_entries = []

    for index, holding in enumerate(holdings_list):
        meta = data.new_metadata('report_holdings_print', index)
        entry = data.Transaction(meta, latest_date, flags.FLAG_SUMMARIZE, None,
                                 "", None, None, [])

        # Convert the holding to a position.
        pos = holdings.holding_to_position(holding)
        entry.postings.append(
            data.Posting(holding.account, pos.units, pos.cost, None, None,
                         None))

        cost = -convert.get_cost(pos)
        entry.postings.append(
            data.Posting(equity_account, cost, None, None, None, None))

        holdings_entries.append(entry)

    # Get opening directives for all the accounts.
    used_accounts = {holding.account for holding in holdings_list}
    open_entries = summarize.get_open_entries(entries, latest_date)
    used_open_entries = [
        open_entry for open_entry in open_entries
        if open_entry.account in used_accounts
    ]

    # Add an entry for the equity account we're using.
    meta = data.new_metadata('report_holdings_print', -1)
    used_open_entries.insert(
        0, data.Open(meta, latest_date, equity_account, None, None))

    # Get the latest price entries.
    price_entries = prices.get_last_price_entries(entries, None)

    return used_open_entries + holdings_entries + price_entries
예제 #4
0
 def test_get_open_entries__duplicate_open(self, entries, errors, _):
     """
       2011-01-01 open Assets:AccountA
       2011-02-01 open Assets:AccountA
     """
     self.assertEqualEntries(
         """
       2011-01-01 open Assets:AccountA
     """, summarize.get_open_entries(entries, date(2013, 1, 1)))
예제 #5
0
 def test_get_open_entries__after_new_opens(self):
     # Other days after new opens.
     self.assertEqualEntries(
         """
       2011-02-01 open Assets:AccountB
       2011-03-01 open Assets:AccountC
       2011-04-01 open Assets:AccountD
       2011-05-01 open Assets:AccountE
     """, summarize.get_open_entries(self.entries, date(2011, 5, 3)))
예제 #6
0
 def test_get_open_entries__after_all_entries(self):
     # After all entries.
     self.assertEqualEntries(
         """
       2011-02-01 open Assets:AccountB
       2011-03-01 open Assets:AccountC
       2011-04-01 open Assets:AccountD
       2011-05-01 open Assets:AccountE
       2011-06-01 open Assets:AccountF
     """, summarize.get_open_entries(self.entries, date(2013, 1, 1)))
예제 #7
0
 def test_get_open_entries__after_all_opens(self):
     # After all opens.
     self.assertEqualEntries(
         """
       2011-02-01 open Assets:AccountB
       2011-03-01 open Assets:AccountC
       2011-04-01 open Assets:AccountD
       2011-05-01 open Assets:AccountE
       2011-06-01 open Assets:AccountF
       2011-07-01 open Assets:AccountG
       2011-08-01 open Assets:AccountH
       2011-09-01 open Assets:AccountI
       2011-10-01 open Assets:AccountJ
       2011-11-01 open Assets:AccountK
       2011-12-01 open Assets:AccountL
     """, summarize.get_open_entries(self.entries, date(2012, 1, 1)))
예제 #8
0
 def test_get_open_entries__after_first_entry_open(self):
     # On the day after the first entry is open.
     self.assertEqualEntries(
         """
       2011-01-01 open Assets:AccountA
     """, summarize.get_open_entries(self.entries, date(2011, 1, 2)))
예제 #9
0
 def test_get_open_entries__first_entry_open(self):
     # On the day of the first entry is open.
     self.assertEqualEntries(
         """
     """, summarize.get_open_entries(self.entries, date(2011, 1, 1)))
예제 #10
0
 def test_get_open_entries__before(self):
     self.assertEqualEntries(
         """
     """, summarize.get_open_entries(self.entries, date(2010, 12, 1)))