diff --git a/helpdesk/admin.py b/helpdesk/admin.py index 58d5ef09..d2e4914f 100644 --- a/helpdesk/admin.py +++ b/helpdesk/admin.py @@ -14,7 +14,8 @@ class QueueAdmin(admin.ModelAdmin): @admin.register(Ticket) class TicketAdmin(admin.ModelAdmin): - list_display = ('title', 'status', 'assigned_to', 'queue', 'hidden_submitter_email',) + list_display = ('title', 'status', 'assigned_to', 'queue', + 'hidden_submitter_email', 'time_spent') date_hierarchy = 'created' list_filter = ('queue', 'assigned_to', 'status') @@ -28,6 +29,9 @@ class TicketAdmin(admin.ModelAdmin): return ticket.submitter_email hidden_submitter_email.short_description = _('Submitter E-Mail') + def time_spent(self, ticket): + return ticket.time_spent + class TicketChangeInline(admin.StackedInline): model = TicketChange @@ -40,7 +44,8 @@ class AttachmentInline(admin.StackedInline): @admin.register(FollowUp) class FollowUpAdmin(admin.ModelAdmin): inlines = [TicketChangeInline, AttachmentInline] - list_display = ('ticket_get_ticket_for_url', 'title', 'date', 'ticket', 'user', 'new_status') + list_display = ('ticket_get_ticket_for_url', 'title', 'date', 'ticket', + 'user', 'new_status', 'time_spent') list_filter = ('user', 'date', 'new_status') def ticket_get_ticket_for_url(self, obj): diff --git a/helpdesk/migrations/0024_time_spent.py b/helpdesk/migrations/0024_time_spent.py new file mode 100644 index 00000000..bbb0f22f --- /dev/null +++ b/helpdesk/migrations/0024_time_spent.py @@ -0,0 +1,18 @@ +# Generated by Django 2.0.5 on 2019-02-06 13:24 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('helpdesk', '0023_add_enable_notifications_on_email_events_to_ticket'), + ] + + operations = [ + migrations.AddField( + model_name='followup', + name='time_spent', + field=models.DurationField(blank=True, help_text='Time spent on this follow up', null=True), + ), + ] diff --git a/helpdesk/models.py b/helpdesk/models.py index e05c4b7d..c772ade0 100644 --- a/helpdesk/models.py +++ b/helpdesk/models.py @@ -17,6 +17,7 @@ from django.utils import timezone from django.utils.translation import ugettext_lazy as _, ugettext from io import StringIO import re +import datetime import uuid @@ -301,6 +302,17 @@ class Queue(models.Model): return u'%s <%s>' % (self.title, self.email_address) from_address = property(_from_address) + @property + def time_spent(self): + """Return back total time spent on the ticket. This is calculated value + based on total sum from all FollowUps + """ + total = datetime.timedelta(0) + for val in self.ticket_set.all(): + if val.time_spent: + total = total + val.time_spent + return total + def prepare_permission_name(self): """Prepare internally the codename for the permission and store it in permission_name. :return: The codename that can be used to create a new Permission object. @@ -497,6 +509,17 @@ class Ticket(models.Model): default=mk_secret, ) + @property + def time_spent(self): + """Return back total time spent on the ticket. This is calculated value + based on total sum from all FollowUps + """ + total = datetime.timedelta(0) + for val in self.followup_set.all(): + if val.time_spent: + total = total + val.time_spent + return total + def send(self, roles, dont_send_to=None, **kwargs): """ Send notifications to everyone interested in this ticket. @@ -771,6 +794,11 @@ class FollowUp(models.Model): objects = FollowUpManager() + time_spent = models.DurationField( + help_text=_("Time spent on this follow up"), + blank=True, null=True + ) + class Meta: ordering = ('date',) verbose_name = _('Follow-up') diff --git a/helpdesk/serializers.py b/helpdesk/serializers.py index e5c7dc7d..046509c4 100644 --- a/helpdesk/serializers.py +++ b/helpdesk/serializers.py @@ -22,7 +22,9 @@ class TicketSerializer(serializers.ModelSerializer): class Meta: model = Ticket # fields = '__all__' - fields = ('ticket', 'id', 'priority', 'title', 'queue', 'status', 'created', 'due_date', 'assigned_to', 'row_class') + fields = ('ticket', 'id', 'priority', 'title', 'queue', 'status', + 'created', 'due_date', 'assigned_to', 'row_class', + 'time_spent') def get_ticket(self, obj): return (str(obj.id) + " " + obj.ticket) diff --git a/helpdesk/templates/helpdesk/followup_edit.html b/helpdesk/templates/helpdesk/followup_edit.html index 0afff6e8..bbd2f0ca 100644 --- a/helpdesk/templates/helpdesk/followup_edit.html +++ b/helpdesk/templates/helpdesk/followup_edit.html @@ -46,6 +46,8 @@
If the status was changed, what was it changed to?
+ +{{ followup.comment|force_escape|urlizetrunc:50|num_to_link|linebreaksbr }}
{% endif %} + {% if followup.time_spent %} + {% trans "Time spent" %}: {{ followup.time_spent }} + {% endif %} {% for change in followup.ticketchange_set.all %} {% if forloop.first %}