Restrict possible tickets to merge to the ones that haven't been already merged.

Also check that all selected tickets are within the same queue.
This commit is contained in:
bbe 2020-10-30 20:19:50 +01:00
parent da5028d51a
commit 00a18d8f54

View File

@ -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