示例#1
0
文件: charts.py 项目: SSITB/fava
    def linechart(self, account_name):
        """The balance of an account.

        Args:
            account_name: A string.

        Returns:
            A list of dicts for all dates on which the balance of the given
            account has changed containing the balance (in units) of the
            account at that date.
        """
        real_account = realization.get_or_create(self.ledger.root_account,
                                                 account_name)
        postings = realization.get_postings(real_account)
        journal = realization.iterate_with_balance(postings)

        # When the balance for a commodity just went to zero, it will be
        # missing from the 'balance' so keep track of currencies that last had
        # a balance.
        last_currencies = None

        for entry, _, change, balance in journal:
            if change.is_empty():
                continue

            balance = inv_to_dict(cost_or_value(balance, entry.date))

            currencies = set(balance.keys())
            if last_currencies:
                for currency in last_currencies - currencies:
                    balance[currency] = 0
            last_currencies = currencies

            yield {"date": entry.date, "balance": balance}
示例#2
0
    def account_journal(self, account_name, with_journal_children=False):
        """Journal for an account.

        Args:
            account_name: An account name.
            with_journal_children: Whether to include postings of subaccounts
                of the given account.

        Returns:
            A list of tuples ``(entry, postings, change, balance)``.
            change and balance have already been reduced to units.
        """
        real_account = realization.get_or_create(self.root_account,
                                                 account_name)

        if with_journal_children:
            # pylint: disable=unused-variable
            postings = realization.get_postings(real_account)
        else:
            postings = real_account.txn_postings

        return [(entry, postings_,
                 copy.copy(change),
                 copy.copy(balance)) for
                (entry, postings_, change, balance) in
                realization.iterate_with_balance(postings)]
示例#3
0
    def account_journal(
        self,
        filtered: FilteredLedger,
        account_name: str,
        with_journal_children: bool = False,
    ) -> list[tuple[Directive, list[Posting], Inventory, Inventory]]:
        """Journal for an account.

        Args:
            filtered: The currently filtered ledger.
            account_name: An account name.
            with_journal_children: Whether to include postings of subaccounts
                of the given account.

        Returns:
            A list of tuples ``(entry, postings, change, balance)``.
            change and balance have already been reduced to units.
        """
        real_account = realization.get_or_create(filtered.root_account,
                                                 account_name)

        if with_journal_children:
            postings = realization.get_postings(real_account)
        else:
            postings = real_account.txn_postings

        return [(entry, postings_, copy.copy(change), copy.copy(balance)) for (
            entry,
            postings_,
            change,
            balance,
        ) in realization.iterate_with_balance(postings)]
示例#4
0
    def account_journal(self, account_name, with_journal_children=False):
        """Journal for an account.

        Args:
            account_name: An account name.
            with_journal_children: Whether to include postings of subaccounts
                of the given account.

        Returns:
            A list of tuples ``(entry, postings, change, balance)``.
            change and balance have already been reduced to units.
        """
        real_account = realization.get_or_create(self.root_account,
                                                 account_name)

        if with_journal_children:
            postings = realization.get_postings(real_account)
        else:
            postings = real_account.txn_postings

        return [(entry, postings_, copy.copy(change), copy.copy(balance)) for (
            entry,
            postings_,
            change,
            balance,
        ) in realization.iterate_with_balance(postings)]
示例#5
0
文件: charts.py 项目: mhansen/fava
    def linechart(self, account_name):
        """The balance of an account.

        Args:
            account_name: A string.

        Returns:
            A list of dicts for all dates on which the balance of the given
            account has changed containing the balance (in units) of the
            account at that date.
        """
        real_account = realization.get_or_create(self.ledger.root_account,
                                                 account_name)
        postings = realization.get_postings(real_account)
        journal = realization.iterate_with_balance(postings)

        # When the balance for a commodity just went to zero, it will be
        # missing from the 'balance' field but appear in the 'change' field.
        # Use 0 for those commodities.
        return [{
            'date':
            entry.date,
            'balance':
            dict({curr: 0
                  for curr in list(change.currencies())},
                 **_inventory_units(balance)),
        } for entry, _, change, balance in journal if len(change)]
示例#6
0
 def account_open_metadata(self, account_name):
     real_account = realization.get_or_create(self.root_account,
                                              account_name)
     postings = realization.get_postings(real_account)
     for posting in postings:
         if isinstance(posting, Open):
             return posting.meta
     return {}
示例#7
0
文件: __init__.py 项目: cgrinds/fava
 def account_open_metadata(self, account_name):
     real_account = realization.get_or_create(self.root_account,
                                              account_name)
     postings = realization.get_postings(real_account)
     for posting in postings:
         if isinstance(posting, Open):
             return posting.meta
     return {}
示例#8
0
    def journal(self, account_name=None):
        if account_name:
            real_account = realization.get(self.real_accounts, account_name)
        else:
            real_account = self.real_accounts

        postings = realization.get_postings(real_account)
        return self._journal_for_postings(postings)
示例#9
0
文件: __init__.py 项目: yagebu/fava
    def account_journal(self, account_name, with_journal_children=False):
        real_account = realization.get_or_create(self.root_account, account_name)

        if with_journal_children:
            postings = realization.get_postings(real_account)
        else:
            postings = real_account.txn_postings

        return realization.iterate_with_balance(postings)
示例#10
0
    def account_journal(self, account_name, with_journal_children=False):
        real_account = realization.get_or_create(self.root_account,
                                                 account_name)

        if with_journal_children:
            postings = realization.get_postings(real_account)
        else:
            postings = real_account.txn_postings

        return realization.iterate_with_balance(postings)
示例#11
0
    def account_journal(self, account_name, with_journal_children=False):
        real_account = realization.get_or_create(self.root_account,
                                                 account_name)

        if with_journal_children:
            postings = realization.get_postings(real_account)
        else:
            postings = real_account.txn_postings

        return [serialize_entry_with(entry, change, balance)
                for entry, _, change, balance in
                realization.iterate_with_balance(postings)]
示例#12
0
    def account_journal(self, account_name, with_journal_children=False):
        real_account = realization.get_or_create(self.root_account,
                                                 account_name)

        if with_journal_children:
            postings = realization.get_postings(real_account)
        else:
            postings = real_account.txn_postings

        return [
            serialize_entry_with(entry, change, balance) for entry, _, change,
            balance in realization.iterate_with_balance(postings)
        ]
示例#13
0
文件: charts.py 项目: yagebu/fava
    def linechart(self, account_name):
        real_account = realization.get_or_create(self.api.root_account,
                                                 account_name)
        postings = realization.get_postings(real_account)
        journal = realization.iterate_with_balance(postings)

        return [{
            'date': entry.date,
            # when there's no holding for a commodity, it will be missing from
            # 'balance' field but appear in 'change' field. Use 0 for those
            # commodities.
            'balance': dict({curr: 0 for curr in list(change.currencies())},
                            **_serialize_inventory(balance)),
        } for entry, _, change, balance in journal if len(change)]
示例#14
0
    def linechart(self, account_name):
        real_account = realization.get_or_create(self.ledger.root_account,
                                                 account_name)
        postings = realization.get_postings(real_account)
        journal = realization.iterate_with_balance(postings)

        return [{
            'date': entry.date,
            # when there's no holding for a commodity, it will be missing from
            # 'balance' field but appear in 'change' field. Use 0 for those
            # commodities.
            'balance': dict({curr: 0 for curr in list(change.currencies())},
                            **_serialize_inventory(balance)),
        } for entry, _, change, balance in journal if len(change)]
示例#15
0
文件: __init__.py 项目: cgrinds/fava
    def journal(self, account_name=None, with_change_and_balance=False,
                with_journal_children=True):
        if account_name:
            real_account = realization.get_or_create(self.root_account,
                                                     account_name)

            if with_journal_children:
                postings = realization.get_postings(real_account)
            else:
                postings = real_account.txn_postings

            return self._journal(postings, with_change_and_balance=True)
        else:
            return self._journal(
                self.entries, with_change_and_balance=with_change_and_balance)
示例#16
0
    def journal(self, account_name=None, with_change_and_balance=False,
                with_journal_children=True):
        if account_name:
            real_account = realization.get_or_create(self.root_account,
                                                     account_name)

            if with_journal_children:
                postings = realization.get_postings(real_account)
            else:
                postings = real_account.txn_postings

            return self._journal(postings, with_change_and_balance=True)
        else:
            return self._journal(
                self.entries, with_change_and_balance=with_change_and_balance)
示例#17
0
    def journal(self, account_name=None, with_change_and_balance=False, with_journal_children=True):
        if account_name:
            if not account_name in [account['full_name'] for account in self.all_accounts]:
                return []

            real_account = realization.get(self.root_account, account_name)

            if with_journal_children:
                postings = realization.get_postings(real_account)
            else:
                postings = []
                postings.extend(real_account.txn_postings)
                postings.sort(key=posting_sortkey)

            return self._journal_for_postings(postings, with_change_and_balance=with_change_and_balance)
        else:
            return self._journal_for_postings(self.entries, with_change_and_balance=with_change_and_balance)
示例#18
0
    def get_postings(self, real_root):
        """Return the postings corresponding to the account filter option.

        Args:
          real_root: A RealAccount node for the root of all accounts.
        Returns:
          A list of posting or directive instances.
        """
        if self.args.account:
            real_account = realization.get(real_root, self.args.account)
            if real_account is None:
                raise report.ReportError("Invalid account name: {}".format(
                    self.args.account))
        else:
            real_account = real_root

        return realization.get_postings(real_account)
示例#19
0
文件: __init__.py 项目: miaoluda/fava
    def _last_posting_for_account(self, account_name):
        """
        Returns the last posting for an account (ignores Close)
        """
        real_account = realization.get_or_create(self.all_root_account,
                                                 account_name)

        last_posting = realization.find_last_active_posting(
            real_account.txn_postings)

        if not isinstance(last_posting, Close):
            return last_posting

        postings = realization.get_postings(real_account)
        if len(postings) >= 2:
            return postings[-2]

        return None
示例#20
0
    def setUp(self, entries, _, __):
        """
        plugin "beancount.plugins.implicit_prices"

        2014-01-01 open Assets:Checking
        2014-01-01 open Assets:Investing
        2014-01-01 open Assets:Savings
        2014-01-01 open Income:MountainOfMoney
        2014-01-01 open Equity:Opening-Balances

        2014-01-05 pad Assets:Checking Equity:Opening-Balances

        2014-02-10 balance Assets:Checking   100.00 USD

        2014-03-04 ! "Salary"
          Income:MountainOfMoney    -4000.00 USD
          Assets:Checking

        2014-03-05 balance Assets:Checking   4100.00 USD

        2014-03-10 note Assets:Checking "Something to say"
        2014-03-11 document Assets:Checking "/path/to/document.pdf"

        ;; With link.
        2014-03-17 * "Transfer" ^784375fd5a68
          Assets:Checking          -2000 USD
          Assets:Checking          -1500 USD
          Assets:Investing:Cash     3500 USD

        2014-03-25 * "Investment"
          Assets:Investing:Cash      -3000 USD
          Assets:Investing:Stock        30 STOCK {100 USD}

        ;; Failing.
        2014-05-01 balance  Assets:Checking   0.00 USD

        2014-12-31 close Assets:Checking
        """
        self.entries = entries
        real_root = realization.realize(self.entries)
        self.real_account = realization.get(real_root, 'Assets:Checking')
        self.postings = realization.get_postings(self.real_account)
示例#21
0
    def get_postings(self, real_root):
        """Return the postings corresponding to the account filter option.

        Args:
          real_root: A RealAccount node for the root of all accounts.
        Returns:
          A list of posting or directive instances.
        """
        if self.args.account:
            real_account = realization.get(real_root, self.args.account)
            if real_account is None:
                # If the account isn't found, return an empty list of postings.
                # Note that this used to return the following error.
                # raise base.ReportError(
                #     "Invalid account name: {}".format(self.args.account))
                return []
        else:
            real_account = real_root

        return realization.get_postings(real_account)
示例#22
0
    def linechart(self, account_name):
        """The balance of an account.

        Args:
            account_name: A string.

        Returns:
            A list of dicts for all dates on which the balance of the given
            account has changed containing the balance (in units) of the
            account at that date.
        """
        real_account = realization.get_or_create(self.ledger.root_account,
                                                 account_name)
        postings = realization.get_postings(real_account)
        journal = realization.iterate_with_balance(postings)

        # When the balance for a commodity just went to zero, it will be
        # missing from the 'balance' field but appear in the 'change' field.
        # Use 0 for those commodities.
        for entry, _, change, balance in journal:
            if change.is_empty():
                continue

            if g.conversion == 'units':
                bal = {curr: 0 for curr in list(change.currencies())}
                bal.update({
                    p.units.currency: p.units.number
                    for p in balance.reduce(convert.get_units)
                })
            else:
                bal = {
                    p.units.currency: p.units.number
                    for p in cost_or_value(balance, entry.date)
                }

            yield {
                'date': entry.date,
                'balance': bal,
            }
示例#23
0
    def linechart(self, account_name):
        """The balance of an account.

        Args:
            account_name: A string.

        Returns:
            A list of dicts for all dates on which the balance of the given
            account has changed containing the balance (in units) of the
            account at that date.
        """
        real_account = realization.get_or_create(self.ledger.root_account,
                                                 account_name)
        postings = realization.get_postings(real_account)
        journal = realization.iterate_with_balance(postings)

        # When the balance for a commodity just went to zero, it will be
        # missing from the 'balance' field but appear in the 'change' field.
        # Use 0 for those commodities.
        for entry, _, change, balance in journal:
            if change.is_empty():
                continue

            if g.conversion == 'units':
                bal = {curr: 0 for curr in list(change.currencies())}
                bal.update({
                    p.units.currency: p.units.number
                    for p in balance.reduce(convert.get_units)
                })
            else:
                bal = {
                    p.units.currency: p.units.number
                    for p in cost_or_value(balance, entry.date)
                }

            yield {
                'date': entry.date,
                'balance': bal,
            }
示例#24
0
    def linechart(self, filtered: FilteredLedger, account_name: str,
                  conversion: str) -> Generator[DateAndBalance, None, None]:
        """The balance of an account.

        Args:
            account_name: A string.
            conversion: The conversion to use.

        Returns:
            A list of dicts for all dates on which the balance of the given
            account has changed containing the balance (in units) of the
            account at that date.
        """
        real_account = realization.get_or_create(filtered.root_account,
                                                 account_name)
        postings = realization.get_postings(real_account)
        journal = realization.iterate_with_balance(postings)

        # When the balance for a commodity just went to zero, it will be
        # missing from the 'balance' so keep track of currencies that last had
        # a balance.
        last_currencies = None

        price_map = self.ledger.price_map
        for entry, _, change, balance_inventory in journal:
            if change.is_empty():
                continue

            balance = inv_to_dict(
                cost_or_value(balance_inventory, conversion, price_map,
                              entry.date))

            currencies = set(balance.keys())
            if last_currencies:
                for currency in last_currencies - currencies:
                    balance[currency] = 0
            last_currencies = currencies

            yield DateAndBalance(entry.date, balance)
示例#25
0
文件: __init__.py 项目: TomJohnZ/fava
    def account_journal(self, account_name, with_journal_children=False):
        """Journal for an account.

        Args:
            account_name: An account name.
            with_journal_children: Whether to include postings of subaccounts
                of the given account.

        Returns:
            A list of tuples ``(entry, postings, change, balance)``.

        """
        real_account = realization.get_or_create(self.root_account,
                                                 account_name)

        if with_journal_children:
            # pylint: disable=unused-variable
            postings = realization.get_postings(real_account)
        else:
            postings = real_account.txn_postings

        return [(entry, postings, change, copy.copy(balance))
                for (entry, postings, change,
                     balance) in realization.iterate_with_balance(postings)]
示例#26
0
    def journal(self,
                account_name=None,
                with_change_and_balance=False,
                with_journal_children=True):
        if account_name:
            if not account_name in [
                    account['full_name'] for account in self.all_accounts
            ]:
                return []

            real_account = realization.get(self.root_account, account_name)

            if with_journal_children:
                postings = realization.get_postings(real_account)
            else:
                postings = []
                postings.extend(real_account.txn_postings)
                postings.sort(key=posting_sortkey)

            return self._journal_for_postings(
                postings, with_change_and_balance=with_change_and_balance)
        else:
            return self._journal_for_postings(
                self.entries, with_change_and_balance=with_change_and_balance)
示例#27
0
 def documents(self, account_name=None):
     postings = realization.get_postings(self.real_accounts)
     return self._journal_for_postings(postings, Document)
示例#28
0
    def test_get_postings(self, entries, errors, _):
        """
        option "plugin_processing_mode" "raw"

        2012-01-01 open Assets:Bank:Checking
        2012-01-01 open Expenses:Restaurant
        2012-01-01 open Expenses:Movie
        2012-01-01 open Liabilities:CreditCard
        2012-01-01 open Equity:Opening-Balances

        2012-01-15 pad Assets:Bank:Checking Equity:Opening-Balances

        2012-03-01 * "Food"
          Expenses:Restaurant     11.11 CAD
          Assets:Bank:Checking   -11.11 CAD

        2012-03-05 * "Food"
          Expenses:Movie         22.22 CAD
          Assets:Bank:Checking  -22.22 CAD

        2012-03-10 * "Paying off credit card"
          Assets:Bank:Checking     -33.33 CAD
          Liabilities:CreditCard    33.33 CAD

        2012-03-20 note Assets:Bank:Checking "Bla bla 444.44"

        2013-04-01 balance Assets:Bank:Checking   555.00 CAD

        2013-04-20 price CAD 0.91 USD

        2013-04-21 event "location" "Somewhere, USA"

        2013-05-01 close Assets:Bank:Checking
        """
        real_account = realization.realize(entries)
        postings = list(realization.get_postings(real_account))

        for (exp_type, exp_account, exp_number), entpost in zip(
            [
                (data.Open, 'Assets:Bank:Checking', None),
                (data.Open, 'Expenses:Restaurant', None),
                (data.Open, 'Expenses:Movie', None),
                (data.Open, 'Liabilities:CreditCard', None),
                (data.Open, 'Equity:Opening-Balances', None),
                (data.Pad, 'Assets:Bank:Checking', None),
                #(data.TxnPosting, 'Assets:Bank:Checking', '621.66'),
                (data.Pad, 'Assets:Bank:Checking', None),
                #(data.TxnPosting, 'Equity:Opening-Balances', '-621.66'),
                (data.TxnPosting, 'Assets:Bank:Checking', '-11.11'),
                (data.TxnPosting, 'Expenses:Restaurant', '11.11'),
                (data.TxnPosting, 'Assets:Bank:Checking', '-22.22'),
                (data.TxnPosting, 'Expenses:Movie', '22.22'),
                (data.TxnPosting, 'Assets:Bank:Checking', '-33.33'),
                (data.TxnPosting, 'Liabilities:CreditCard', '33.33'),
                (data.Note, 'Assets:Bank:Checking', None),
                (data.Balance, 'Assets:Bank:Checking', None),
                (data.Close, 'Assets:Bank:Checking', None),
            ],
                postings):
            self.assertEqual(exp_type, type(entpost))
            if isinstance(entpost, data.TxnPosting):
                entpost = entpost.posting
            if exp_account:
                self.assertEqual(exp_account, entpost.account)
            if exp_number:
                self.assertEqual(D(exp_number), entpost.units.number)