Esempio n. 1
0
    def apply_filters(self):
        self.entries = self.all_entries

        if self.filters['time']:
            try:
                begin_date, end_date = parse_date(self.filters['time'])
                self.entries, _ = summarize.clamp_opt(self.entries, begin_date, end_date, self.options)
            except TypeError:
                raise FilterException('Failed to parse date string: {}'.format(self.filters['time']))

        if self.filters['tag']:
            self.entries = [entry
                            for entry in self.entries
                            if isinstance(entry, Transaction) and entry.tags and (entry.tags & set(self.filters['tag']))]

        if self.filters['payee']:
            self.entries = [entry
                            for entry in self.entries
                            if (isinstance(entry, Transaction) and entry.payee and (entry.payee in self.filters['payee']))
                            or (isinstance(entry, Transaction) and not entry.payee and ('' in self.filters['payee']))]

        if self.filters['account']:
            self.entries = [entry
                            for entry in self.entries
                            if isinstance(entry, Transaction) and
                                any(has_component(posting.account, self.filters['account'])
                                    for posting in entry.postings)]

        self.root_account = realization.realize(self.entries, self.account_types)
        self.all_accounts = self._account_components()
        self.all_accounts_leaf_only = self._account_components(leaf_only=True)

        self.closing_entries = summarize.cap_opt(self.entries, self.options)
        self.closing_real_accounts = realization.realize(self.closing_entries, self.account_types)
Esempio n. 2
0
    def monthly_income_expenses_totals(self):
        month_tuples = self._month_tuples(self.entries)
        monthly_totals = []
        for begin_date, end_date in month_tuples:
            entries, index = summarize.clamp_opt(self.entries, begin_date, end_date + timedelta(days=1),
                                                          self.options_map)

            income_totals = self._table_totals(realization.get(realization.realize(entries, self.account_types), self.options_map['name_income']))
            expenses_totals = self._table_totals(realization.get(realization.realize(entries, self.account_types), self.options_map['name_expenses']))

            # FIXME find better way to only include relevant totals (lots of ZERO-ones at the beginning)
            sum_ = ZERO
            for currency, number in income_totals.items():
                sum_ += number
            for currency, number in expenses_totals.items():
                sum_ += number

            if sum_ != ZERO:
                monthly_totals.append({
                    'begin_date': begin_date,
                    'end_date': end_date,
                    'income_totals': income_totals,
                    'expenses_totals': expenses_totals
                })

        return monthly_totals
Esempio n. 3
0
 def apply_filter(self, entries, options_map):
     # Clamp to the desired period.
     begin_date = datetime.date(self.year, self.first_month, 1)
     end_date = datetime.date(self.year + 1, self.first_month, 1)
     with misc_utils.log_time('clamp', logging.info):
         entries, index = summarize.clamp_opt(entries, begin_date, end_date,
                                              options_map)
     return entries, index
Esempio n. 4
0
    def apply_filters(self):
        self.entries = self.all_entries

        if self.filters['time']:
            try:
                begin_date, end_date = parse_date(self.filters['time'])
                self.entries, _ = summarize.clamp_opt(self.entries, begin_date,
                                                      end_date, self.options)
            except TypeError:
                raise FilterException('Failed to parse date string: {}'.format(
                    self.filters['time']))

        if self.filters['tag']:
            self.entries = [
                entry for entry in self.entries
                if isinstance(entry, Transaction) and entry.tags and (
                    entry.tags & set(self.filters['tag']))
            ]

        if self.filters['payee']:
            self.entries = [
                entry for entry in self.entries
                if (isinstance(entry, Transaction) and entry.payee and
                    (entry.payee in self.filters['payee'])) or (
                        isinstance(entry, Transaction) and not entry.payee and
                        ('' in self.filters['payee']))
            ]

        if self.filters['account']:
            self.entries = [
                entry for entry in self.entries
                if isinstance(entry, Transaction) and any(
                    has_component(posting.account, self.filters['account'])
                    for posting in entry.postings)
            ]

        self.root_account = realization.realize(self.entries,
                                                self.account_types)
        self.all_accounts = self._account_components()
        self.all_accounts_leaf_only = self._account_components(leaf_only=True)

        self.closing_entries = summarize.cap_opt(self.entries, self.options)
        self.closing_real_accounts = realization.realize(
            self.closing_entries, self.account_types)
Esempio n. 5
0
    def _real_accounts(self, account_name, begin_date=None, end_date=None):
        """
        Returns the realization.RealAccount instances for account_name, and their entries
        clamped by the optional begin_date and end_date.

        Returns:
            realization.RealAccount instances
        """
        begin_date_, end_date_ = getters.get_min_max_dates(self.entries, (Transaction))
        if begin_date:
            begin_date_ = begin_date
        if end_date:
            end_date_ = end_date

        entries, index = summarize.clamp_opt(self.entries, begin_date_, end_date_ + timedelta(days=1),
                                                     self.options_map)

        real_accounts = realization.get(realization.realize(entries, self.account_types), account_name)

        return real_accounts
Esempio n. 6
0
    def _net_worth_in_periods(self):
        month_tuples = self._month_tuples(self.entries)
        monthly_totals = []
        date_start = month_tuples[0][0]
        networthtable = holdings_reports.NetWorthReport(None, None)

        for begin_date, end_date in month_tuples:
            entries, index = summarize.clamp_opt(self.entries, date_start, end_date + timedelta(days=1),
                                                          self.options_map)

            networth_as_table = networthtable.generate_table(entries, self.errors, self.options_map)

            totals = dict(networth_as_table[2])
            for key, value in totals.items():
                totals[key] = float(value.replace(',', ''))

            monthly_totals.append({
                'begin_date': begin_date,
                'end_date': end_date,
                'totals': totals
            })

        return monthly_totals
Esempio n. 7
0
 def _filter(self, entries, options):
     entries, _ = summarize.clamp_opt(entries, self.begin_date,
                                      self.end_date, options)
     return entries
Esempio n. 8
0
 def _filter(self, entries: Entries) -> Entries:
     entries, _ = clamp_opt(entries, self.begin_date, self.end_date,
                            self.options)
     return entries
Esempio n. 9
0
 def _filter(self, entries, options):
     entries, _ = summarize.clamp_opt(entries, self.begin_date,
                                      self.end_date, options)
     return entries