Example #1
0
    def delete_entries(self, entries):
        """Remove transactions in which ``entries`` belong from the document's transaction list.

        :param entries: list of :class:`.Entry`
        """
        from_account = first(entries).account
        transactions = dedupe(e.transaction for e in entries)
        self.delete_transactions(transactions, from_account=from_account)
Example #2
0
    def delete_entries(self, entries):
        """Remove transactions in which ``entries`` belong from the document's transaction list.

        :param entries: list of :class:`.Entry`
        """
        from_account = first(entries).account
        transactions = dedupe(e.transaction for e in entries)
        self.delete_transactions(transactions, from_account=from_account)
Example #3
0
 def _swap_fields(self, panes, switch_func):
     seen = set()
     for pane in panes:
         entries = self.loader.accounts.entries_for_account(pane.account)
         txns = dedupe(e.transaction for e in entries)
         for txn in txns:
             if txn.affected_accounts() & seen:
                 # We've already swapped this txn in a previous pane.
                 continue
             switch_func(txn)
         seen.add(pane.account)
     self.import_table.refresh()
Example #4
0
 def _invert_amounts(self, apply_to_all):
     if apply_to_all:
         panes = self.panes
     else:
         panes = [self.selected_pane]
     for pane in panes:
         entries = self.loader.accounts.entries_for_account(pane.account)
         txns = dedupe(e.transaction for e in entries)
         for txn in txns:
             for split in txn.splits:
                 split.amount = -split.amount
     self.import_table.refresh()
Example #5
0
def guess_date_format(str_dates, formats_to_try):
    if not str_dates:
        return None
    for format in dedupe(formats_to_try):
        for str_date in str_dates:
            try:
                datetime.datetime.strptime(str_date, format)
            except ValueError:
                break
        else:
            return format
    return None
Example #6
0
 def _swap_fields(self, panes, switch_func):
     seen = set()
     for pane in panes:
         entries = self.loader.accounts.entries_for_account(pane.account)
         txns = dedupe(e.transaction for e in entries)
         for txn in txns:
             if txn.affected_accounts() & seen:
                 # We've already swapped this txn in a previous pane.
                 continue
             switch_func(txn)
         seen.add(pane.account)
     self.import_table.refresh()
Example #7
0
 def _invert_amounts(self, apply_to_all):
     if apply_to_all:
         panes = self.panes
     else:
         panes = [self.selected_pane]
     for pane in panes:
         entries = self.loader.accounts.entries_for_account(pane.account)
         txns = dedupe(e.transaction for e in entries)
         for txn in txns:
             for split in txn.splits:
                 split.amount = -split.amount
     self.import_table.refresh()
Example #8
0
 def show_transfer_account(self, row_index=None):
     if row_index is None:
         if not self.selected_entries:
             return
         row_index = self.selected_index
     entry = self[row_index].entry
     splits = entry.transaction.splits
     accounts = dedupe(split.account for split in splits if split.account is not None)
     if len(accounts) < 2:
         return # no transfer
     index = accounts.index(entry.account)
     if index < len(accounts) - 1:
         account_to_show = accounts[index+1]
     else:
         account_to_show = accounts[0]
     self.mainwindow.open_account(account_to_show)
Example #9
0
def guess_date_format(str_dates, formats_to_try):
    for format in dedupe(formats_to_try):
        found_at_least_one = False
        for str_date in str_dates:
            try:
                datetime.datetime.strptime(str_date, format)
                found_at_least_one = True
            except ValueError:
                logging.debug(
                    "Failed try to read the date %s with the format %s",
                    str_date, format)
                break
        else:
            if found_at_least_one:
                logging.debug("Correct date format: %s", format)
                return format
    return None
Example #10
0
 def _revalidate(self):
     if self.mainwindow is None or not self.attrname:
         return
     doc = self.mainwindow.document
     attrname = self.attrname
     if attrname == 'description':
         self._candidates = doc.transactions.descriptions
     elif attrname == 'payee':
         self._candidates = doc.transactions.payees
     elif attrname in {'from', 'to', 'account', 'transfer'}:
         result = doc.transactions.account_names
         # `result` doesn't contain empty accounts' name, so we'll add them.
         result += [a.name for a in doc.accounts if not a.inactive]
         if attrname == 'transfer' and self.account is not None:
             result = [name for name in result if name != self.account.name]
         self._candidates = result
     self._candidates = dedupe([name for name in self._candidates if name.strip()])
Example #11
0
    def __init__(self, partial, candidates):
        """Build a completion list.

        'partial' is the partial value to be completed
        'candidates' is the list of candidate values to be tried, the most likely candidate first."""
        if not partial:
            self._completions = None
            return
        partial = sort_string(partial)
        candidates = dedupe(c.strip() for c in candidates)
        self._completions = []
        for candidate in candidates:
            normalized = sort_string(candidate)
            if normalized.startswith(partial):
                self._completions.append(candidate)
        self._completions.reverse()
        if self._completions:
            self._index = len(self._completions) - 1
Example #12
0
 def _revalidate(self):
     if self.mainwindow is None or not self.attrname:
         return
     doc = self.mainwindow.document
     attrname = self.attrname
     if attrname == 'description':
         self._candidates = doc.transactions.descriptions
     elif attrname == 'payee':
         self._candidates = doc.transactions.payees
     elif attrname in {'from', 'to', 'account', 'transfer'}:
         result = doc.transactions.account_names
         # `result` doesn't contain empty accounts' name, so we'll add them.
         result += [a.name for a in doc.accounts if not a.inactive]
         if attrname == 'transfer' and self.account is not None:
             result = [name for name in result if name != self.account.name]
         self._candidates = result
     self._candidates = dedupe(
         [name for name in self._candidates if name.strip()])
Example #13
0
    def __init__(self, partial, candidates):
        """Build a completion list.

        'partial' is the partial value to be completed
        'candidates' is the list of candidate values to be tried, the most likely candidate first."""
        if not partial:
            self._completions = None
            return
        partial = sort_string(partial)
        candidates = dedupe(c.strip() for c in candidates)
        self._completions = []
        for candidate in candidates:
            normalized = sort_string(candidate)
            if normalized.startswith(partial):
                self._completions.append(candidate)
        self._completions.reverse()
        if self._completions:
            self._index = len(self._completions) - 1
Example #14
0
 def _insertItem(self, item):
     self._items = dedupe([item] + self._items)[:self._maxItemCount]