Esempio n. 1
0
def networth():
	reload_journal_if_modified(source_filename)

	two_years_ago = utilities.date_add_months(datetime.date.today(), -24)
	two_years_ago = datetime.date(
		year=two_years_ago.year,
		month=two_years_ago.month,
		day=1)
	parameters = balance.MonthlySummaryParameters(
		title="Net Worth",
		accounts_with=["assets","liabilities"],
		exclude_accounts_with=["units"],
		period_start=two_years_ago,
		period_end=None)
	data = balance.generate_monthly_summary(journal, parameters)

	page = get_page_data(data)
	return render_template("linechart.html", page=page, command=None, path="networth")
Esempio n. 2
0
	def from_command(cls, command):
		"""
		Create a parameters object from a query command
		"""
		accounts_with = []
		exclude_accounts_with = []
		period = []
		period_start = None
		period_end = None
		title = []
		phase = "select"

		for token in command:
			if token == ":excluding":
				phase = "filter"
			elif token == ":period":
				phase = "period"
			elif token == ":since":
				phase = "periodstart"
			elif token == ":upto":
				phase = "periodend"
			elif token == ":title":
				phase = "title"
			elif phase == "select":
				accounts_with.append(token)
			elif phase == "filter":
				exclude_accounts_with.append(token)
			elif phase == "period":
				period.append(token)
			elif phase == "periodstart":
				period_start = datetime.datetime.strptime(token, "%Y/%m/%d").date()
				phase = "invalid"
			elif phase == "periodend":
				period_end = datetime.datetime.strptime(token, "%Y/%m/%d").date()
				phase = "invalid"
			elif phase == "title":
				title.append(token)
			else:
				raise Exception("Invalid token in balance command parameters: " + token)

		# parse period
		# TODO: should move this somewhere else eventually
		if len(period) > 0:
			period_str = " ".join(period)

			if period_str == "this month":
				today = datetime.date.today()
				period_start = datetime.date(year=today.year, month=today.month, day=1)
				period_end = datetime.date(year=today.year, month=today.month, day=calendar.monthrange(today.year, today.month)[1])
			elif period_str == "last month":
				today = datetime.date.today()
				month_ago = utilities.date_add_months(today, -1)
				period_start = datetime.date(year=month_ago.year, month=month_ago.month, day=1)
				period_end = datetime.date(year=month_ago.year, month=month_ago.month, day=calendar.monthrange(month_ago.year, month_ago.month)[1])
			else:
				raise Exception("Invalid period expression: " + period_str)

		return cls(title=" ".join(title) if len(title) > 0 else None,
			accounts_with=accounts_with if len(accounts_with) > 0 else None,
			exclude_accounts_with=exclude_accounts_with if len(exclude_accounts_with) > 0 else None,
			period_start=period_start,
			period_end=period_end)