Beispiel #1
0
    def test_last_day_current_month(self, today_mock: Mock):
        today_mock.return_value = datetime.date.today().replace(month=1)
        self.assertEqual(31, datetime_util.last_date_current_month().day)

        today_mock.return_value = datetime.date.today().replace(month=4)
        self.assertEqual(30, datetime_util.last_date_current_month().day)

        today_mock.return_value = datetime.date.today().replace(
            year=2021, month=2
        )
        self.assertEqual(28, datetime_util.last_date_current_month().day)
Beispiel #2
0
def _get_x_labels() -> List[str]:
    # labels on x axis
    # we only show important days
    important_days = (
        datetime_util.first_date_current_month(),
        datetime_util.today(),
        datetime_util.last_date_current_month(),
    )
    return [
        date.strftime('%d/%m') if date in important_days else ''
        for date in datetime_util.get_date_iterator(
            datetime_util.first_date_current_month(),
            datetime_util.last_date_current_month())
    ]
Beispiel #3
0
    def current_percent(self) -> int:
        expenses = Expense.get_expenses_in(
            start_date=datetime_util.first_date_current_month(),
            end_date=datetime_util.last_date_current_month(),
        ).filter(category__group=self.expense_group).only('value')

        total_value = sum([ex.value for ex in expenses])
        return int(total_value / self.limit * 100)
Beispiel #4
0
def _get_y_values(group: ExpenseGroup) -> Tuple[List[int], int]:
    """
    Returns accumulated expense for each day of this month and
    the index of the entry for today.
    """

    current_daily_acc_expenses = _get_current_accumulated_expenses(group)
    expense_projections = ml_util.expense_projection(
        current_daily_acc_expenses,
        project_for=range(
            len(current_daily_acc_expenses) + 1,
            datetime_util.last_date_current_month().day + 1))

    return current_daily_acc_expenses + expense_projections, len(
        current_daily_acc_expenses) - 1
Beispiel #5
0
 def test_get_y_values(self):
     expenses, index = admin._get_y_values(ExpenseGroup.objects.first())
     self.assertEqual(datetime_util.last_date_current_month().day,
                      len(expenses))
     self.assertEqual(datetime_util.today().day - 1, index)