Пример #1
0
async def get_month_statistics(message: types.Message):
    """ Gets month stats for the current budget """
    budget_name = await state_budget_name(message)
    budget_id = budgets.get_budget_id(budget_name)
    now_year_month = expenses.get_year_month_now()
    stats_str = expenses.get_month_stats(budget_id, now_year_month)
    kb = buttons.mrkup_chs_month_stats(expenses.get_budget_months(budget_id))
    await message.answer(text(bold("Расходы за месяц\n\n")) + stats_str,
                         parse_mode=ParseMode.MARKDOWN,
                         reply_markup=kb)
Пример #2
0
async def add_expense(message: types.Message):
    """ Adds an expense to the needed budget """
    budget_name = message.from_user.username + "_personal"
    budget_id = budgets.get_budget_id(budget_name)
    try:
        expense = expenses.add_expense(message.text, message.from_user.id,
                                       budget_id)
    except exceptions.NotCorrectMessage as e:
        await message.answer(str(e))
        return
    answer_text = (
        f"В бюджет \"{budget_name}\" "
        f"добавлена трата {expense.amount} руб. на {expense.category_name}.\n")
    await message.answer(answer_text)
Пример #3
0
async def choose_month_stats(callback_query: types.CallbackQuery):
    """ Gets stats for the chosen month """
    await bot.answer_callback_query(callback_query.id)

    year_month = str(callback_query.data[6:])
    budget_name = await state_budget_name(callback_query)
    budget_id = budgets.get_budget_id(budget_name)
    stats_str = expenses.get_month_stats(budget_id, year_month)
    month_name = expenses.month_name(year_month)
    await bot.send_message(
        callback_query.from_user.id,
        text(bold("Расходы за выбранный месяц\n{0}\n\n".format(month_name))) +
        stats_str,
        parse_mode=ParseMode.MARKDOWN)
Пример #4
0
async def deleting_expenses_state(callback_query: types.CallbackQuery):
    """ Sends each expense from the last ten, offering to delete each of them """
    await bot.answer_callback_query(callback_query.id)
    budget_name = await state_budget_name(callback_query)
    budget_id = budgets.get_budget_id(budget_name)
    last_expenses = expenses.get_last_expenses(callback_query.from_user.id,
                                               budget_id)
    if not last_expenses:
        await bot.send_message(callback_query.from_user.id,
                               "Трат ещё не было.")
        return
    await bot.send_message(callback_query.from_user.id,
                           text(bold("Удаление трат\n\n")),
                           parse_mode=ParseMode.MARKDOWN)
    for expense in last_expenses:
        expense_str = f"- {expense.amount} руб. на {expense.category_name}, добавил {expense.username}\n"
        await bot.send_message(
            callback_query.from_user.id,
            expense_str,
            reply_markup=buttons.markup_del_expense(expense))
Пример #5
0
async def get_last_expenses(message: types.Message):
    """ Gets last ten expenses for the current budget """
    budget_name = await state_budget_name(message)
    budget_id = budgets.get_budget_id(budget_name)
    last_expenses = expenses.get_last_expenses(message.from_user.id, budget_id)
    budget_name_mrkdwn = budget_name.replace("_", "\\_")
    kb = None
    answer_text = text(
        bold(f"Последние траты\n\n") + f"Бюджет: \"{budget_name_mrkdwn}\"\n\n")
    if not last_expenses:
        answer_text += "Трат ещё не было."
    else:
        expenses_to_send = [
            f"- {expense.amount} руб. на {expense.category_name}, добавил {expense.username}\n"
            for expense in last_expenses
        ]
        answer_text += "\n".join(expenses_to_send)
        kb = buttons.kb_del_expenses
    params = {"text": answer_text, "parse_mode": ParseMode.MARKDOWN}
    if kb: params["reply_markup"] = kb
    await message.answer(**params)
Пример #6
0
async def add_expense(message: types.Message):
    """ Adds an expense to the needed budget """
    budget_id = budgets.get_budget_id("joint")
    users_list = budgets.get_all_users(budget_id)
    try:
        expense = expenses.add_expense(message.text, message.from_user.id,
                                       budget_id)
    except exceptions.NotCorrectMessage as e:
        await message.answer(str(e))
        return
    answer_text = (
        f"В бюждет \"joint\" "
        f"добавлена трата {expense.amount} руб. на {expense.category_name}.\n")
    for user in users_list:
        if user.id == message.from_user.id:
            continue
        else:
            await bot.send_message(user.id, (text(
                bold("В бюджет \"joint\" была добавлена трата\n\n") +
                f"Добавил: {message.from_user.username}\n" +
                f"Сумма: {expense.amount}\n" +
                f"Категория: {expense.category_name}\n")),
                                   parse_mode=ParseMode.MARKDOWN)
    await message.answer(answer_text)
Пример #7
0
async def get_overall_statistics(message: types.Message):
    budget_name = await state_budget_name(message)
    budget_id = budgets.get_budget_id(budget_name)
    stats_str = expenses.get_overall_stats(message.from_user.id)
    await message.answer(text(bold(f"Общая статистика\n\n")) + stats_str,
                         parse_mode=ParseMode.MARKDOWN)
Пример #8
0
async def get_day_statistics(message: types.Message):
    budget_name = await state_budget_name(message)
    budget_id = budgets.get_budget_id(budget_name)
    stats_str = expenses.get_day_stats(budget_id)
    await message.answer(text(bold("Расходы за сегодня\n\n")) + stats_str,
                         parse_mode=ParseMode.MARKDOWN)