diff --git a/helpdesk/forms.py b/helpdesk/forms.py index bb9072a0..d6779c69 100644 --- a/helpdesk/forms.py +++ b/helpdesk/forms.py @@ -515,14 +515,17 @@ class TicketDependencyForm(forms.ModelForm): class MultipleTicketSelectForm(forms.Form): tickets = forms.ModelMultipleChoiceField( label=_('Tickets to merge'), - queryset=Ticket.objects.all(), + queryset=Ticket.objects.filter(merged_to=None), widget=forms.SelectMultiple(attrs={'class': 'form-control'}) ) def clean_tickets(self): tickets = self.cleaned_data.get('tickets') if len(tickets) < 2: - raise ValidationError(_('Please choose at least 2 tickets')) + raise ValidationError(_('Please choose at least 2 tickets.')) if len(tickets) > 4: raise ValidationError(_('Impossible to merge more than 4 tickets...')) + queues = tickets.order_by('queue').distinct().values_list('queue', flat=True) + if len(queues) != 1: + raise ValidationError(_('All selected tickets must share the same queue in order to be merged.')) return tickets