Fix calendar detail showing all workers when filtering by one
When filtering by a single worker, log.workers.all() still returned every worker on the WorkLog. Now the detail panel and cost calculation only show the filtered worker, not the entire group. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
19e565a088
commit
94c061fc19
@ -496,13 +496,27 @@ def work_history(request):
|
||||
# the JS reads this JSON to populate the detail panel below the calendar.
|
||||
# NOTE: Pass raw Python dict, not json.dumps() — the template's
|
||||
# |json_script filter handles serialization.
|
||||
#
|
||||
# IMPORTANT: When a worker filter is active, log.workers.all() would
|
||||
# still return ALL workers on that WorkLog (not just the filtered one).
|
||||
# We need to narrow the displayed workers to match the filter.
|
||||
calendar_detail = {}
|
||||
for date_key, day_logs in logs_by_date.items():
|
||||
calendar_detail[date_key] = []
|
||||
for log in day_logs:
|
||||
# Get the workers to show — if filtering by worker,
|
||||
# only show that worker (not everyone else on the log)
|
||||
if worker_filter:
|
||||
display_workers = [
|
||||
w for w in log.workers.all()
|
||||
if str(w.id) == worker_filter
|
||||
]
|
||||
else:
|
||||
display_workers = list(log.workers.all())
|
||||
|
||||
entry = {
|
||||
'project': log.project.name,
|
||||
'workers': [w.name for w in log.workers.all()],
|
||||
'workers': [w.name for w in display_workers],
|
||||
'supervisor': (
|
||||
log.supervisor.get_full_name() or log.supervisor.username
|
||||
) if log.supervisor else '-',
|
||||
@ -510,10 +524,10 @@ def work_history(request):
|
||||
'is_paid': log.payroll_records.exists(),
|
||||
'overtime': log.get_overtime_amount_display() if log.overtime_amount > 0 else '',
|
||||
}
|
||||
# Only show cost data to admins
|
||||
# Only show cost data to admins — use filtered workers for amount
|
||||
if is_admin(user):
|
||||
entry['amount'] = float(
|
||||
sum(w.daily_rate for w in log.workers.all())
|
||||
sum(w.daily_rate for w in display_workers)
|
||||
)
|
||||
calendar_detail[date_key].append(entry)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user