-
Notifications
You must be signed in to change notification settings - Fork 31
Cancel shifttemplate #773
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
crosspolar
wants to merge
17
commits into
master
Choose a base branch
from
cancel_shifttemplate
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+422
−101
Open
Cancel shifttemplate #773
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9a29ded
init
crosspolar 1d7136f
translation
crosspolar 122758e
init TestShiftTemplateEndView
crosspolar 46547b9
test_createShiftForGroup_endDate_noShiftsCreatedPastEndDate
crosspolar ea0635d
fix test
crosspolar 5e756c0
end_date should not be before start date
crosspolar 3db24b4
translation
crosspolar 266c6ff
Merge branch 'master' into cancel_shifttemplate
crosspolar 406fc37
translation
crosspolar 0fad0d0
fix migration
crosspolar f80d56a
Merge branch 'master' into cancel_shifttemplate
crosspolar 1a8cdc6
Merge branch 'master' into cancel_shifttemplate
crosspolar 61aeb93
transl
crosspolar 0f3de75
transl
crosspolar ced1e2d
remove comment
crosspolar 4e4083f
remove cancel button
crosspolar f1a6270
acknowledge that start_date can be None
crosspolar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Generated by Django 5.2.15 on 2026-06-14 17:37 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
|
|
||
| dependencies = [ | ||
| ("shifts", "0075_shiftwatch_watched_capabilities"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="shifttemplate", | ||
| name="end_date", | ||
| field=models.DateField( | ||
| blank=True, | ||
| help_text="All shifts after this date will be cancelled.", | ||
| null=True, | ||
| ), | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
tapir/shifts/templates/shifts/shift_template_set_end_date.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| {% extends "shifts/base.html" %} | ||
| {% load django_bootstrap5 %} | ||
| {% load static %} | ||
| {% load i18n %} | ||
| {% load core %} | ||
| {% block title %} | ||
| {% translate 'Set end date for' %}: {{ shift_template.get_display_name }} | ||
| {% endblock title %} | ||
| {% block content %} | ||
| <div class="card"> | ||
| <h5 class="card-header">{% translate 'Set end date for' %}: {{ shift_template.get_display_name }}</h5> | ||
| <div class="card-body"> | ||
| <form method="post"> | ||
| {% csrf_token %} | ||
| {% bootstrap_form form %} | ||
| <div class="alert alert-warning " role="alert"> | ||
| <strong>{% translate 'Warning' %}</strong> | ||
| {% translate 'All shifts generated from this ABCD-shift after the selected date will be cancelled. Registered members will be notified.' %} | ||
| </div> | ||
| <div class="d-flex justify-content-end"> | ||
| <button type="submit" class="{% tapir_button_action %}"> | ||
| <span class="material-icons">event_busy</span> | ||
| {% translate 'Set end date and cancel shifts' %} | ||
| </button> | ||
| </div> | ||
| </form> | ||
| </div> | ||
| </div> | ||
| {% endblock content %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,3 +113,22 @@ def test_createShiftsForGroup_withoutHolidayCancellation_doesntCancelsHolidays( | |
| ) | ||
| self.assertFalse(shift.cancelled) | ||
| self.assertIsNone(shift.cancelled_reason) | ||
|
|
||
| def test_createShiftForGroup_endDate_noShiftsCreatedPastEndDate(self): | ||
| group_a = ShiftTemplateGroup.objects.create(name="A") | ||
|
|
||
| template_with_future_end_date = ShiftTemplateFactory.create( | ||
| group=group_a, end_date=datetime.date(2025, 11, 20) | ||
| ) | ||
|
|
||
| # should be created | ||
| ShiftGenerator.create_shifts_for_group( | ||
| at_date=datetime.date(2025, 11, 10), group=group_a | ||
| ) | ||
|
|
||
| # should not be created | ||
| ShiftGenerator.create_shifts_for_group( | ||
| at_date=datetime.date(2025, 11, 24), group=group_a | ||
| ) | ||
|
|
||
|
Comment on lines
+124
to
+133
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should make 2 test cases for this, or at least assert between the creations. |
||
| self.assertEqual(1, template_with_future_end_date.generated_shifts.count()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import datetime | ||
|
|
||
| from django.contrib.messages import get_messages | ||
| from django.urls import reverse | ||
| from django.utils import timezone | ||
| from django_extensions.jobs import weekly | ||
|
|
||
| from tapir.accounts.tests.factories.factories import TapirUserFactory | ||
| from tapir.shifts.tests.factories import ShiftTemplateFactory | ||
| from tapir.shifts.tests.utils import register_user_to_shift_template | ||
| from tapir.utils.tests_utils import TapirFactoryTestBase | ||
|
|
||
|
|
||
| class TestShiftTemplateEndView(TapirFactoryTestBase): | ||
|
|
||
| def setUp(self): | ||
| super().setUp() | ||
| self.shift_template = ShiftTemplateFactory.create( | ||
| start_date=timezone.now().date(), weekday=0 | ||
| ) | ||
| self.url = reverse( | ||
| "shifts:shift_template_set_end_date", kwargs={"pk": self.shift_template.pk} | ||
| ) | ||
|
|
||
| def test_shiftTemplate_setEndDateInBetween_futureShiftsAfterEndDateAreCancelled( | ||
| self, | ||
| ): | ||
| self.login_as_employee() | ||
|
|
||
| user = TapirUserFactory.create(is_in_member_office=False) | ||
| register_user_to_shift_template(self.client, user, self.shift_template) | ||
|
|
||
| today = timezone.now().date() | ||
| shift_1 = self.shift_template.create_shift_if_necessary( | ||
| today + datetime.timedelta(days=7) | ||
| ) | ||
| shift_2 = self.shift_template.create_shift_if_necessary( | ||
| today + datetime.timedelta(days=14) | ||
| ) | ||
| shift_3 = self.shift_template.create_shift_if_necessary( | ||
| today + datetime.timedelta(days=21) | ||
| ) | ||
|
|
||
| end_date = today + datetime.timedelta(days=14) | ||
| cancellation_reason = "Shift Template ended" | ||
|
|
||
| response = self.client.post( | ||
| self.url, | ||
| { | ||
| "end_date": end_date.strftime("%Y-%m-%d"), | ||
| "cancellation_reason": cancellation_reason, | ||
| }, | ||
| ) | ||
|
|
||
| self.assertRedirects( | ||
| response, | ||
| reverse( | ||
| "shifts:shift_template_detail", kwargs={"pk": self.shift_template.pk} | ||
| ), | ||
| ) | ||
|
|
||
| self.shift_template.refresh_from_db() | ||
| shift_1.refresh_from_db() | ||
| shift_2.refresh_from_db() | ||
| shift_3.refresh_from_db() | ||
|
|
||
| self.assertEqual(self.shift_template.end_date, end_date) | ||
|
|
||
| self.assertFalse(shift_1.cancelled) | ||
| self.assertFalse(shift_2.cancelled) | ||
|
|
||
| self.assertTrue(shift_3.cancelled) | ||
| self.assertEqual(shift_3.cancelled_reason, cancellation_reason) | ||
|
|
||
| def test_shiftTemplate_sendEndDateAfterAllShifts_noShiftIsCancelled(self): | ||
| self.login_as_employee() | ||
| today = timezone.now().date() | ||
| end_date = today + datetime.timedelta(days=365) | ||
| cancellation_reason = "Shift Template ended" | ||
| shift = self.shift_template.create_shift_if_necessary( | ||
| today + datetime.timedelta(days=7) | ||
| ) | ||
|
|
||
| response = self.client.post( | ||
| self.url, | ||
| { | ||
| "end_date": end_date.strftime("%Y-%m-%d"), | ||
| "cancellation_reason": cancellation_reason, | ||
| }, | ||
| ) | ||
|
|
||
| self.shift_template.refresh_from_db() | ||
| shift.refresh_from_db() | ||
| self.assertEqual(self.shift_template.end_date, end_date) | ||
|
|
||
| self.assertFalse(shift.cancelled) | ||
|
|
||
| msgs = list(get_messages(response.wsgi_request)) | ||
| self.assertGreater(len(msgs), 0) | ||
|
|
||
| def test_shiftTemplate_sendEndDate_endDateBeforeStartDate_showsValidationError( | ||
| self, | ||
| ): | ||
| self.login_as_employee() | ||
|
|
||
| end_date = self.shift_template.start_date - datetime.timedelta(days=7) | ||
|
|
||
| response = self.client.post( | ||
| self.url, | ||
| { | ||
| "end_date": end_date.strftime("%Y-%m-%d"), | ||
| "cancellation_reason": "Test", | ||
| }, | ||
| ) | ||
|
|
||
| self.assertEqual(response.status_code, 200) | ||
| self.assertIn("end_date", response.context["form"].errors) | ||
|
|
||
| self.shift_template.refresh_from_db() | ||
| self.assertIsNone(self.shift_template.end_date) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can merge the two ifs.