Skip to content

Commit 7a4b6bc

Browse files
committed
[BUG FIX] subcate & subpayment and also first day bug (testing)
1 parent ab2376c commit 7a4b6bc

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

bot/telegram_bot.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@ def category(update, context) -> int:
411411
update.callback_query.edit_message_text(
412412
f"Category type: {reply}", reply_markup=None
413413
)
414+
payment_list = get_payment_text(sheet_id)
415+
update.callback_query.message.reply_text(
416+
DEFAULT_PAYMENT_TEXT,
417+
reply_markup=create_inline_markup(payment_list),
418+
)
414419
return CS.PAYMENT
415420
except Exception as e:
416421
update.callback_query.reply_text(ERROR_TEXT)
@@ -457,6 +462,14 @@ def payment(update, context) -> int:
457462
DEFAULT_PAYMENT_TEXT, reply_markup=create_inline_markup(sub_markup_list)
458463
)
459464
return CS.SUBPAYMENT
465+
# This won't be called as there will always be a subpayment, but just in case
466+
else:
467+
update.callback_query.edit_message_text(
468+
f'Payment type: {context.user_data["payment"]}', reply_markup=None
469+
)
470+
log_transaction(context.user_data, update)
471+
update.callback_query.message.reply_text("Transaction logged.")
472+
return ConversationHandler.END
460473
except Exception as e:
461474
update.callback_query.message.reply_text(ERROR_TEXT)
462475
return ConversationHandler.END
@@ -514,12 +527,13 @@ def log_transaction(user_data, update):
514527
if day_tracker != day:
515528
msg = f"New entry for {day} {month}"
516529
prev_month = month
517-
if day == 1:
530+
# this should fix the bug regarding if first day of month not keyed in, but not tested
531+
if day == 1 | day < day_tracker:
518532
prev_month = (current_datetime - dt.timedelta(days=1)).strftime("%b")
519533
# update prev day
520534
msg = f"{msg}\nCreating sum for day {day_tracker}"
521535
gs.update_prev_day(sheet_id, prev_month, first_row)
522-
if day == 1:
536+
if day == 1 | day < day_tracker:
523537
new_row = 4
524538
first_row = 5
525539
gs.update_rows(sheet_id, 1, new_row, first_row)

test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,9 @@ def index():
3131
print("#" * 50)
3232
print(f"# Bot is running at @{updater.bot.get_me().username} #")
3333
print("#" * 50)
34-
app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 5000)))
34+
app.run(
35+
host="0.0.0.0",
36+
port=int(os.environ.get("PORT", 5000)),
37+
debug=True,
38+
use_reloader=False,
39+
)

0 commit comments

Comments
 (0)