def __call__(self): total_income = Decimal(0.0) total_taxes = Decimal(0.0) for account_name in self.income_accounts: account = get_account(account_name) for split in get_splits(account, self._start.date, self._end.date): value = get_decimal(split.GetAmount()) * -1 total_income += value for account_name in self.tax_accounts: account = get_account(account_name) for split in get_splits(account, self._start.date, self._end.date): value = get_decimal(split.GetAmount()) total_taxes += value tax_value = calculate_tax(self._tax_name, self._tax_status, total_income) result = self._generate_result() result['data']['income'] = total_income result['data']['tax_value'] = tax_value result['data']['taxes_paid'] = total_taxes return result
def store_investment(bucket, value): other_account_name = get_corr_account_full_name(value) other_account = get_account(other_account_name) account_type = AccountTypes(other_account.GetType()) # Find the correct amount that was paid from the account into this account. change_amount = get_decimal(value.GetValue()) if change_amount > 0: # Need to get the value from the corr account split. for parent_splits in value.parent.GetSplitList(): if parent_splits.GetAccount().get_full_name() == other_account_name: change_amount = -get_decimal(parent_splits.GetValue()) if account_type == AccountTypes.mutual_fund or account_type == AccountTypes.asset or \ account_type == AccountTypes.equity: # Asset or mutual fund transfer bucket['money_in'] += change_amount elif account_type == AccountTypes.income: bucket['income'] += get_decimal(value.GetValue()) elif account_type == AccountTypes.expense: bucket['expense'] += get_decimal(value.GetValue()) else: print 'Unknown account type: %s' % account_type return bucket
def __call__(self): balance = Decimal('0.0') for account in account_walker(self.account_name, self.ignore_accounts): split_list = get_splits(account, PeriodStart.this_month.date, PeriodEnd.today.date, debit=False) for split in split_list: balance += get_decimal(split.GetAmount()) payload = self._generate_result() payload['data']['balance'] = balance payload['data']['month'] = PeriodEnd.today.date.month payload['data']['daysInMonth'] = monthrange(PeriodEnd.today.date.year, PeriodEnd.today.date.month)[1] payload['data']['today'] = PeriodEnd.today.date.day payload['data']['budgetValue'] = self.budget_value if self._year_to_date: yearly_balance = Decimal('0.0') for account in account_walker(self.account_name, self.ignore_accounts): split_list = get_splits(account, PeriodStart.this_year.date, PeriodEnd.this_year.date, debit=False) for split in split_list: yearly_balance += get_decimal(split.GetAmount()) today = date.today() payload['data']['yearlyBalance'] = yearly_balance payload['data']['daysInYear'] = (date(today.year+1, 1, 1) - date(today.year, 1, 1)).days payload['data']['currentYearDay'] = today.timetuple().tm_yday return payload
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
def split_summation(bucket, value): """ sum the new value to the value in the bucket. :param bucket: Decimal object :param value: Split object :return: new bucket value """ bucket += get_decimal(value.GetAmount()) return bucket
def store_credit_debit(bucket, value): if isinstance(value, Decimal): decimal_value = value else: decimal_value = get_decimal(value.GetAmount()) if decimal_value < 0: bucket['debit'] += decimal_value else: bucket['credit'] += decimal_value return bucket
def __call__(self): account = get_account(self.account_name) todays_date = datetime.today() beginning_of_month = datetime(todays_date.year, todays_date.month, 1) start_of_trend = beginning_of_month - relativedelta(months=self.past_trend) end_of_trend = start_of_trend + relativedelta(months=self.past_trend + self.future_trend) payload = self._generate_result() payload['data']['trend'] = [] for dt in rrule(MONTHLY, dtstart=start_of_trend, until=end_of_trend): time_value = time.mktime(dt.timetuple()) balance = account.GetBalanceAsOfDate(time_value) payload['data']['trend'].append(dict(date=dt.strftime('%Y-%m-%d'), balance=get_decimal(balance))) return payload
def __call__(self): today = date.today() today_time = time.mktime(today.timetuple()) credit_amount = Decimal(0.0) credit_used = Decimal(0.0) for credit_definition in self._credit_accounts: account = get_account(credit_definition['account']) limit = credit_definition.get('limit', '0.0') credit_amount += Decimal(limit) balance = get_decimal(account.GetBalanceAsOfDate(today_time)) credit_used += balance payload = self._generate_result() payload['data']['credit_limit'] = credit_amount + credit_used payload['data']['credit_amount'] = -credit_used return payload
def __call__(self): contribution_total = Decimal("0.0") today = date.today() beginning_of_year = date(today.year, 1, 1) for account_name in self.income_accounts: account = get_account(account_name) for split in get_splits(account, self._start.date, self._end.date): parent = split.parent for income_split in parent.GetSplitList(): if income_split.GetAccount().get_full_name() in self.retirement_accounts: contribution_total += get_decimal(income_split.GetAmount()) result = self._generate_result() result["data"]["contributionLimit"] = self.contribution_limit result["data"]["contribution"] = contribution_total result["data"]["dayOfYear"] = (today - beginning_of_year).days + 1 result["data"]["daysInYear"] = (date(today.year, 12, 31) - beginning_of_year).days + 1 return result
def __call__(self): account = get_account(self.account_name) data = dict(purchases=[], dividend=[], value=[]) last_dividend = Decimal('0.0') last_purchase = Decimal('0.0') currency = get_currency() purchases = dict() dividends = dict() values = dict() for split in account.GetSplitList(): other_account_name = get_corr_account_full_name(split) other_account = get_account(other_account_name) account_type = AccountTypes(other_account.GetType()) date = datetime.fromtimestamp(split.parent.GetDate()) # Store previous data if len(purchases): previous_date = date - relativedelta(days=1) previous_date_key = time.mktime(previous_date.timetuple()) purchases[previous_date_key] = last_purchase dividends[previous_date_key] = last_dividend values[previous_date_key] = get_balance_on_date(account, previous_date, currency) # Find the correct amount that was paid from the account into this account. change_amount = get_decimal(split.GetValue()) if change_amount > 0: # Need to get the value from the corr account split. for parent_splits in split.parent.GetSplitList(): if parent_splits.GetAccount().get_full_name() == other_account_name: change_amount = -get_decimal(parent_splits.GetValue()) if account_type == AccountTypes.mutual_fund or account_type == AccountTypes.asset: # Asset or mutual fund transfer last_purchase += change_amount else: last_dividend += get_decimal(split.GetValue()) key = time.mktime(date.timetuple()) purchases[key] = last_purchase dividends[key] = last_dividend values[key] = get_balance_on_date(account, date, currency) # Now get all of the price updates in the database. price_database = get_session().get_book().get_price_db() commodity = account.GetCommodity() for price in price_database.get_prices(commodity, None): date = time.mktime(price.get_time().timetuple()) values[date] = max(values.get(date, Decimal('0.0')), get_balance_on_date(account, price.get_time(), currency)) data['purchases'] = sorted([(key, value) for key, value in purchases.iteritems()], key=itemgetter(0)) data['dividend'] = sorted([(key, value) for key, value in dividends.iteritems()], key=itemgetter(0)) data['value'] = sorted([(key, value) for key, value in values.iteritems()], key=itemgetter(0)) results = self._generate_result() results['data'] = data return results