From ea0b2a6f07217e8f31e41bfd5abf3a6df07ea22a Mon Sep 17 00:00:00 2001 From: sonnyv Date: Wed, 8 Apr 2026 13:19:50 +0200 Subject: [PATCH 1/2] vscode: add defaultEnvManager --- .vscode/settings.json | 1 + 1 file changed, 1 insertion(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index 7ce7dc4..87b6d7d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,4 +6,5 @@ "editor.rulers": [ 120 ], + "python-envs.defaultEnvManager": "ms-python.python:venv", } \ No newline at end of file From 38f1bb7ebe4e4effb4d74220351e9838a830b922 Mon Sep 17 00:00:00 2001 From: sonnyv Date: Wed, 8 Apr 2026 13:20:17 +0200 Subject: [PATCH 2/2] timesheets: show only days in the past when SelectMissingDays is activated --- .../timesheets/telegrambot/steps/select.py | 10 ++++-- src/apps/timesheets/tests.py | 33 +++++++++++++------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/apps/timesheets/telegrambot/steps/select.py b/src/apps/timesheets/telegrambot/steps/select.py index 8f25baf..3a3c306 100644 --- a/src/apps/timesheets/telegrambot/steps/select.py +++ b/src/apps/timesheets/telegrambot/steps/select.py @@ -224,11 +224,17 @@ def handle(self, telegram_update: "TelegramUpdate"): class SelectMissingDay(SelectDay): - """Represent the missing day selection step in a Telegram bot command.""" + """Represent the missing day selection step in a Telegram bot command. + + This shows only the days in the past that are missing from the timesheet. + """ def get_days(self): """Get the missing days for the settings' user's project.""" - draft_timesheets = Timesheet.objects.filter(status=Timesheet.Status.DRAFT, user=self.command.settings.user) + now = timezone.now().date() + draft_timesheets = Timesheet.objects.filter( + status=Timesheet.Status.DRAFT, user=self.command.settings.user, year__lte=now.year, month__lte=now.month + ) missing = [(timesheet.project, date) for timesheet in draft_timesheets for date in timesheet.get_missing_days()] return sorted(missing, key=lambda x: x[1]) diff --git a/src/apps/timesheets/tests.py b/src/apps/timesheets/tests.py index 70f8885..e4c9c30 100644 --- a/src/apps/timesheets/tests.py +++ b/src/apps/timesheets/tests.py @@ -126,6 +126,12 @@ class TimesheetsTelegramBotTestCase(TelegramBotTestCase): fixtures = ["companies", "relations", "users", "timesheets", "projects"] + @property + def available_button_texts(self) -> list[str]: + """Return the texts of the buttons available in the last bot message.""" + inline_keyboard = self.fake_bot_post.call_args[1]["payload"]["reply_markup"]["inline_keyboard"] + return [item["text"] for row in inline_keyboard for item in row] + @classmethod def setUpTestData(cls): """Set up the test data.""" @@ -136,16 +142,23 @@ def setUpTestData(cls): def test_telegram_registerwork(self): """Test the telegram registerwork command.""" - existing_timesheet_items = self.timesheet.timesheetitem_set.count() - self.send_text("/registerwork") - self.click_on_text("➡️ Next") - self.click_on_text("⬅️ Back") - self.click_on_text("Dummy Project: 2025-01-03") - self.click_on_text("⬅️ Previous step") - self.click_on_text("Dummy Project: 2025-01-03") - self.assertEqual(self.timesheet.timesheetitem_set.count(), existing_timesheet_items) - self.click_on_text("Full day (8h)") - self.assertEqual(self.timesheet.timesheetitem_set.count(), existing_timesheet_items + 1) + Timesheet.objects.create( + user=self.user, project=self.project, year=2025, month=2, status=Timesheet.Status.DRAFT + ) + fixed_now = datetime(2025, 1, 13, 0, 0, 0, tzinfo=timezone.utc) + with patch("django.utils.timezone.now", return_value=fixed_now): + existing_timesheet_items = self.timesheet.timesheetitem_set.count() + self.send_text("/registerwork") + self.click_on_text("➡️ Next") + self.assertIn("Dummy Project: 2025-01-13", self.available_button_texts) + self.assertNotIn("Dummy Project: 2025-01-14", self.available_button_texts) + self.click_on_text("⬅️ Back") + self.click_on_text("Dummy Project: 2025-01-03") + self.click_on_text("⬅️ Previous step") + self.click_on_text("Dummy Project: 2025-01-03") + self.assertEqual(self.timesheet.timesheetitem_set.count(), existing_timesheet_items) + self.click_on_text("Full day (8h)") + self.assertEqual(self.timesheet.timesheetitem_set.count(), existing_timesheet_items + 1) def test_telegram_editwork(self): """Test the telegram editwork command."""