Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
"editor.rulers": [
120
],
"python-envs.defaultEnvManager": "ms-python.python:venv",
}
10 changes: 8 additions & 2 deletions src/apps/timesheets/telegrambot/steps/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down
33 changes: 23 additions & 10 deletions src/apps/timesheets/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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."""
Expand Down
Loading