From e779b4da9480d50a3f20db0545c5b5b58251355c Mon Sep 17 00:00:00 2001 From: Denis Durepos Date: Tue, 12 Aug 2025 11:47:57 -0400 Subject: [PATCH] feat: Allow duplicate task-to-event conversions for different teams - Modified task-to-event wizard to allow same task to be converted to multiple events for different teams - Changed duplicate prevention from time-based to team-specific checking - Removed within-run duplicate prevention to support overlapping team events - Enhanced task messages to include team name for better audit trail - Supports therapists covering multiple teams with same background tasks Fixes issue where therapists couldn't create overlapping events for different teams from the same task. --- .../wizards/task_to_event_wizard.py | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/bemade_sports_clinic/wizards/task_to_event_wizard.py b/bemade_sports_clinic/wizards/task_to_event_wizard.py index 8f5aba3..bfe7b20 100644 --- a/bemade_sports_clinic/wizards/task_to_event_wizard.py +++ b/bemade_sports_clinic/wizards/task_to_event_wizard.py @@ -105,26 +105,23 @@ class TaskToEventWizard(models.TransientModel): if not unique_tasks: raise UserError("No valid tasks found for conversion.") - # Check if any tasks have already been converted by this wizard - from datetime import timedelta as dt_timedelta + # Check if any tasks have already been converted for THIS SPECIFIC TEAM + # Allow the same task to be converted for different teams (overlapping events) existing_events = self.env['sports.event'].search([ ('task_id', 'in', unique_tasks.ids), - ('create_date', '>=', fields.Datetime.now() - dt_timedelta(minutes=5)) # Recent conversions + ('team_id', '=', self.team_id.id) # Only check for same team ]) if existing_events: task_names = existing_events.mapped('task_id.name') - raise UserError(f"Some tasks appear to have been recently converted: {', '.join(task_names)}. " - f"Please check existing events before proceeding.") + raise UserError(f"Some tasks have already been converted for team '{self.team_id.name}': {', '.join(task_names)}. " + f"Each task can only be converted once per team.") created_events = self.env['sports.event'] - processed_task_ids = set() # Track processed tasks to prevent duplicates + # Note: Removed processed_task_ids tracking since we now allow the same task + # to be converted multiple times for different teams for task in unique_tasks: - # Skip if we've already processed this task (prevent duplicates within same run) - if task.id in processed_task_ids: - continue - processed_task_ids.add(task.id) # Validate task has required information if not task.name: @@ -177,8 +174,8 @@ class TaskToEventWizard(models.TransientModel): # Add a note to the task about the conversion (without sending emails) task.with_context(mail_notrack=True, mail_create_nolog=True).message_post( - body=f"Task converted to Sports Event: {event.name}", - subject="Converted to Sports Event" + body=f"Task converted to Sports Event for team '{self.team_id.name}': {event.name}", + subject=f"Converted to Sports Event ({self.team_id.name})" ) # Return action to view created events