From 6c2a1a3fbd214060a16f48fbaf1682dd80103f8c Mon Sep 17 00:00:00 2001 From: Sarey Hamarneh Date: Mon, 12 Jun 2017 14:07:00 -0400 Subject: [PATCH] Fix style; validate one balance sheet per year --- bpfin/financials/cash_balance.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bpfin/financials/cash_balance.py b/bpfin/financials/cash_balance.py index 1076083..28f48e9 100644 --- a/bpfin/financials/cash_balance.py +++ b/bpfin/financials/cash_balance.py @@ -1,8 +1,14 @@ +"""Calculate historical cash balance value for each year from the proforma start date.""" + + def cash_balance(analysis_date, cash_dictionary): - """Returns current cash balance + """Returns current cash balance. If more than 1 balance sheet per year, raise ValueError. + Args: - analysis_date (dictionary) = {starting_date: months} + analysis_date (dict) = {start_date, duration in years} cash_dictionary (dictionary): {datetime:(cash value,year)} + Raises: + ValueError when more than 1 balance sheet for one year. Returns: dictionary: {datetime, cash value} """ @@ -18,6 +24,8 @@ def cash_balance(analysis_date, cash_dictionary): for date, value_tuple in cash_dictionary.items(): if value_tuple[1] is True: + if date.year in cash_dictionary: + raise ValueError("Only one balance sheet per year is allowed") cash_balance_dictionary[date.year] = value_tuple[0] else: if date.year not in bank_statement: -- GitLab