コード例 #1
0
    def setUp(self):

        self.year = "2008"

        self.client = Client()
        self.url = reverse('budget_summary_year', args=(self.year,))

        amount_groceries1 = Decimal('68.30')
        amount_groceries2 = Decimal('34.39')
        amount_loan = Decimal('800.0')
        # total_groceries = amount_groceries1 + amount_groceries2
        # total_transactions = total_groceries + amount_loan

        self.start_date = datetime.date(int(self.year), 1, 1)
        self.end_date = datetime.date(int(self.year), 12, 31)

        # Setup and crate needed budgets, estimates, etc.
        self.budget = BudgetFactory(start_date=datetime.datetime(2008, 1, 1))
        cat_food = CategoryFactory(name='Food')
        cat_groceries = CategoryFactory(name='Groceries',
                                        parent=cat_food,)

        cat_loan = CategoryFactory(name='Loan')
        cat_mortgage = CategoryFactory(name='Mortgage',
                                       parent=cat_loan,)

        BudgetEstimateFactory(amount=Decimal('9600.0'),
                              budget=self.budget,
                              category=cat_mortgage,)

        BudgetEstimateFactory(amount=Decimal('800.0'),
                              budget=self.budget,
                              category=cat_groceries,)

        TransactionFactory(amount=amount_groceries1,
                           category=cat_groceries,
                           date=datetime.datetime(2008, 2, 1))

        TransactionFactory(amount=amount_groceries2,
                           category=cat_groceries,
                           date=datetime.datetime(2008, 9, 15))

        TransactionFactory(amount=amount_loan,
                           category=cat_mortgage,
                           date=datetime.datetime(2008, 9, 20))
        root_nodes = Category.root_nodes.all()
        self.categories = get_queryset_descendants(root_nodes,
                                                   include_self=True)
        yearly_things = self.budget.yearly_data_per_category(self.categories,
                                                             self.budget,
                                                             self.year)
        self.estimates_and_actuals, self.actual_yearly_total = yearly_things
コード例 #2
0
    def test_categories_estimates_and_transactions(self):
        """
        This needs refactoring
        """

        amount_groceries1 = Decimal('68.30')
        amount_groceries2 = Decimal('34.39')
        total_transactions = amount_groceries1 + amount_groceries2

        # Setup and crate needed budgets, estimates, etc.
        budget = BudgetFactory(start_date=datetime.datetime(2008, 1, 1))
        start_date, end_date = calculate_start_end_date(2008, 2)
        cat_food = CategoryFactory(name='Food')
        cat_groceries = CategoryFactory(name='Groceries',
                                        parent=cat_food,)
        cat_loan = CategoryFactory(name='Loan')
        BudgetEstimateFactory(amount=Decimal('1000.0'),
                              budget=budget,
                              category=cat_loan,)

        BudgetEstimateFactory(amount=Decimal('800.0'),
                              budget=budget,
                              category=cat_groceries,)

        TransactionFactory(amount=amount_groceries1,
                           category=cat_groceries,
                           date=datetime.datetime(2008, 2, 1))

        TransactionFactory(amount=amount_groceries2,
                           category=cat_groceries,
                           date=datetime.datetime(2008, 2, 1))

        root_nodes = Category.root_nodes.all()
        categories = get_queryset_descendants(root_nodes, include_self=True)

        cat_est_trans, actual_total = (
            budget.categories_estimates_and_transactions(
                start_date, end_date, categories, 'all')
        )
        self.assertEqual(total_transactions, actual_total,
                         'Total amount does not match')
コード例 #3
0
def yearly_estimates_and_actuals():

    ActualYearlyData = namedtuple('ActualYearlyData',
                                  ['total_transactions',
                                   'total_groceries',
                                   'groceries_estimate',
                                   'yearly_estimated_total',])

    CalculatedYearlyData = namedtuple('CalculatedYearlyData',
                                      ['calculated_data',
                                       'calculated_estimation',])

    amount_groceries1 = Decimal('68.30')
    amount_groceries2 = Decimal('34.39')
    amount_loan = Decimal('800.0')
    total_groceries = amount_groceries1 + amount_groceries2
    total_transactions = total_groceries + amount_loan
    groceries_monthly_estimate = Decimal('800.0')
    groceries_yearly_estimate =  groceries_monthly_estimate * 12
    loan_monthly_estimate = Decimal('900.0')
    loan_yearly_estimate = loan_monthly_estimate * 12
    yearly_estimated_total = groceries_yearly_estimate + loan_yearly_estimate

    #Setup and crate needed budgets, estimates, etc.
    budget = BudgetFactory(start_date=datetime.datetime(2008, 1, 1))
    cat_food = CategoryFactory(name='Food')
    entire_year = '1,2,3,4,5,6,7,8,9,10,11,12'

    cat_groceries = CategoryFactory(name='Groceries',
                                    parent=cat_food,
                                )
    cat_loan = CategoryFactory(name='Loan')
    cat_mortgage = CategoryFactory(name='Mortgage',
                                   parent=cat_loan,
                               )
    est_loan = BudgetEstimateFactory(amount=loan_monthly_estimate,
                                     budget=budget,
                                     category=cat_mortgage,
                                     occurring_month=entire_year,)

    est_groceries = BudgetEstimateFactory(amount=groceries_monthly_estimate,
                                          budget=budget,
                                          category=cat_groceries,
                                          occurring_month=entire_year,)
    
    trans_groceries1 = TransactionFactory(amount=amount_groceries1, 
                                          category=cat_groceries, 
                                          date=datetime.datetime(2008, 2, 1))
    trans_groceries2 = TransactionFactory(amount=amount_groceries2, 
                                          category=cat_groceries, 
                                          date=datetime.datetime(2008, 9, 15))
    
    trans_loan1 = TransactionFactory(amount=amount_loan, 
                                     category=cat_mortgage, 
                                     date=datetime.datetime(2008, 9, 20))
    root_nodes = Category.root_nodes.all()
    categories = get_queryset_descendants(root_nodes, include_self=True)
    
    year = "2008"
    yearly_calculated_data = budget.yearly_data_per_category(categories,
                                                             budget, year)

    yearly_calculated_estimation = budget.yearly_estimated_total()

    actual_data = ActualYearlyData(total_transactions=total_transactions,
                                       total_groceries=total_groceries,
                                       groceries_estimate=groceries_yearly_estimate,
                                       yearly_estimated_total=yearly_estimated_total)
    calculated_data =CalculatedYearlyData(
        calculated_data=yearly_calculated_data,
        calculated_estimation=yearly_calculated_estimation,
    )
                                           
        # Return yearly things and toral_transcations
    return calculated_data, actual_data