def category_key_fetcher(data_key): """ Look up the category that is associated with the account defined in the split. :param data_key: split :return: """ return get_category_for_account(data_key.GetAccount().get_full_name())
def __call__(self): start_of_trend = self._start.date end_of_trend = self._end.date data = dict() for account in account_walker(self._accounts): for split in get_splits(account, start_of_trend, end_of_trend, credit=False): transaction = split.parent for transaction_split in transaction.GetSplitList(): transaction_account_name = transaction_split.GetAccount().get_full_name() if transaction_account_name != account.get_full_name(): category = get_category_for_account(transaction_account_name) current_balance = data.setdefault(category, Decimal('0.0')) current_balance += get_decimal(transaction_split.GetAmount()) data[category] = current_balance result = self._generate_result() result['data']['categories'] = sorted([[key, value] for key, value in data.iteritems()], key=itemgetter(0)) return result