refactor: revert post-attendance flow to redirect-home (SiteReport removal step 1)
Also deletes AttendanceLogRedirectsToSiteReportTests (it asserted only the removed redirect destination — a behavioural test, not a model test). Suite 209 -> 208. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
a502bac8ec
commit
f9b190a26d
@ -1891,39 +1891,6 @@ class SiteReportDetailViewTests(TestCase):
|
||||
self.assertContains(response, '7')
|
||||
|
||||
|
||||
class AttendanceLogRedirectsToSiteReportTests(TestCase):
|
||||
"""The two-step flow: after submitting attendance, the user lands
|
||||
on the site-report edit page for the most recently created log."""
|
||||
|
||||
def setUp(self):
|
||||
self.admin = User.objects.create_user(username='atrr-admin', password='pw', is_staff=True)
|
||||
self.project = Project.objects.create(name='AT Project')
|
||||
self.worker = Worker.objects.create(
|
||||
name='Test Worker',
|
||||
id_number='AT1',
|
||||
monthly_salary=Decimal('10000'),
|
||||
)
|
||||
|
||||
def test_successful_attendance_post_redirects_to_site_report_edit(self):
|
||||
"""The redirect target is the site-report form, not home — so
|
||||
the supervisor lands somewhere they can immediately log progress."""
|
||||
self.client.force_login(self.admin)
|
||||
response = self.client.post(reverse('attendance_log'), {
|
||||
'date': '2026-04-27',
|
||||
'project': self.project.id,
|
||||
'workers': [self.worker.id],
|
||||
'overtime_amount': '0.00',
|
||||
'notes': '',
|
||||
})
|
||||
self.assertEqual(response.status_code, 302)
|
||||
# The redirect URL contains '/site-report/' and ends with '/edit/'
|
||||
self.assertIn('/site-report/', response.url)
|
||||
self.assertTrue(response.url.endswith('/edit/'),
|
||||
msg=f"Expected redirect to .../edit/, got {response.url}")
|
||||
# And exactly one work log was created
|
||||
self.assertEqual(WorkLog.objects.count(), 1)
|
||||
|
||||
|
||||
# ====================================================================
|
||||
# === Worker Absence — Phase 1: Model layer ==========================
|
||||
# ====================================================================
|
||||
@ -2855,8 +2822,10 @@ class AbsenceAttendanceShortcutTests(TestCase):
|
||||
def setUp(self):
|
||||
self.client.force_login(self.admin)
|
||||
|
||||
def test_default_attendance_submit_unchanged(self):
|
||||
"""next_action absent or 'log_only' → existing Site Report redirect."""
|
||||
def test_default_attendance_submit_redirects_home(self):
|
||||
"""A plain attendance submit (no next_action) now redirects to
|
||||
the dashboard — the old forced Site Report redirect was removed
|
||||
(SiteReport feature deleted 17 May 2026)."""
|
||||
resp = self.client.post(reverse('attendance_log'), data={
|
||||
'date': '2026-05-14',
|
||||
'project': self.project.id,
|
||||
@ -2864,15 +2833,14 @@ class AbsenceAttendanceShortcutTests(TestCase):
|
||||
'workers': [self.worker.id],
|
||||
'overtime_amount': '0.00',
|
||||
'notes': '',
|
||||
# next_action omitted on purpose — should fall through to
|
||||
# the existing Site Report behaviour.
|
||||
# next_action omitted on purpose — default path → home.
|
||||
})
|
||||
self.assertEqual(resp.status_code, 302)
|
||||
self.assertIn('/site-report/', resp.url)
|
||||
self.assertEqual(resp.url, reverse('home'))
|
||||
|
||||
def test_log_only_explicit_value_still_goes_to_site_report(self):
|
||||
"""An explicit next_action='log_only' (the default button) keeps
|
||||
the existing behaviour — important for backwards compatibility."""
|
||||
def test_log_only_explicit_value_redirects_home(self):
|
||||
"""An explicit next_action='log_only' also lands on the
|
||||
dashboard (same default path; no Site Report anymore)."""
|
||||
resp = self.client.post(reverse('attendance_log'), data={
|
||||
'date': '2026-05-14',
|
||||
'project': self.project.id,
|
||||
@ -2883,7 +2851,7 @@ class AbsenceAttendanceShortcutTests(TestCase):
|
||||
'next_action': 'log_only',
|
||||
})
|
||||
self.assertEqual(resp.status_code, 302)
|
||||
self.assertIn('/site-report/', resp.url)
|
||||
self.assertEqual(resp.url, reverse('home'))
|
||||
|
||||
def test_log_absences_button_redirects_to_absence_log(self):
|
||||
"""next_action='log_absences' → redirect to /absences/log/ with
|
||||
|
||||
@ -693,9 +693,6 @@ def attendance_log(request):
|
||||
# --- Create work logs ---
|
||||
created_count = 0
|
||||
skipped_count = 0
|
||||
# Track the IDs of work logs we just created so we can redirect
|
||||
# the supervisor to the site-report form for the most recent one.
|
||||
created_log_ids = []
|
||||
|
||||
for log_date in dates_to_log:
|
||||
# Check which workers already have a log on this date
|
||||
@ -736,7 +733,6 @@ def attendance_log(request):
|
||||
)
|
||||
work_log.workers.set(workers_to_add)
|
||||
created_count += 1
|
||||
created_log_ids.append(work_log.id)
|
||||
|
||||
# Show success message
|
||||
if created_count > 0:
|
||||
@ -747,17 +743,14 @@ def attendance_log(request):
|
||||
else:
|
||||
messages.warning(request, 'No work logs created — all entries were conflicts.')
|
||||
|
||||
# === ROUND C: pick post-submit destination ===
|
||||
# The attendance form has TWO submit buttons, both named
|
||||
# `next_action` with different values. Whichever button the
|
||||
# user clicked, that value lands in request.POST:
|
||||
# - 'log_only' (default) → existing Site Report flow
|
||||
# - 'log_absences' → jump to /absences/log/ pre-filled
|
||||
# Konrad's ask: "it is tedious to find the absence form after
|
||||
# logging work — give us a 'Log and add Absence' button."
|
||||
# === Post-submit destination ===
|
||||
# The attendance form has two submit buttons (both POST
|
||||
# `next_action`):
|
||||
# - default / 'log_only' → dashboard (home) + success toast
|
||||
# - 'log_absences' → /absences/log/ pre-filled
|
||||
next_action = request.POST.get('next_action', 'log_only')
|
||||
|
||||
if next_action == 'log_absences' and created_log_ids:
|
||||
if next_action == 'log_absences' and created_count:
|
||||
# Pre-fill the absence form with the same date / team /
|
||||
# project the user just used. We use the LAST log's date
|
||||
# (matches the site_report_edit behaviour for date ranges:
|
||||
@ -772,16 +765,9 @@ def attendance_log(request):
|
||||
params['project'] = project.id
|
||||
return redirect(f"{reverse('absence_log')}?{urlencode(params)}")
|
||||
|
||||
# Two-step flow: after attendance, send the supervisor to the
|
||||
# site-report form so they can log progress + weather while it's
|
||||
# fresh in their head. The form has a "Skip" link to home for
|
||||
# supervisors who're in a hurry. If we created NO logs, fall
|
||||
# back to the old behaviour and just go home.
|
||||
if created_log_ids:
|
||||
# Redirect to the report for the LAST created log (most
|
||||
# recent date when a date range was used — typically today
|
||||
# for single-day entries).
|
||||
return redirect('site_report_edit', work_log_id=created_log_ids[-1])
|
||||
# SiteReport feature removed (17 May 2026) — a successful
|
||||
# attendance submit now simply returns to the dashboard;
|
||||
# the success toast above already confirms what was logged.
|
||||
return redirect('home')
|
||||
else:
|
||||
# Don't pre-fill the start date — force the user to pick one
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user