add /shipping_vouchers endpoint
This commit is contained in:
parent
2f354130da
commit
f11758607e
6 changed files with 123 additions and 5 deletions
|
@ -2,7 +2,7 @@ from rest_framework import serializers
|
|||
|
||||
from authentication.models import ExtendedUser
|
||||
from mail.api_v2 import AttachmentSerializer
|
||||
from tickets.models import IssueThread, Comment, STATE_CHOICES
|
||||
from tickets.models import IssueThread, Comment, STATE_CHOICES, ShippingVoucher
|
||||
|
||||
|
||||
class CommentSerializer(serializers.ModelSerializer):
|
||||
|
@ -28,6 +28,13 @@ class StateSerializer(serializers.Serializer):
|
|||
return obj['value']
|
||||
|
||||
|
||||
class ShippingVoucherSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
model = ShippingVoucher
|
||||
fields = ('id', 'voucher', 'type', 'timestamp', 'issue_thread', 'used_at')
|
||||
read_only_fields = ('id', 'timestamp', 'used_at')
|
||||
|
||||
|
||||
class IssueSerializer(serializers.ModelSerializer):
|
||||
timeline = serializers.SerializerMethodField()
|
||||
last_activity = serializers.SerializerMethodField()
|
||||
|
@ -60,7 +67,10 @@ class IssueSerializer(serializers.ModelSerializer):
|
|||
if self.state_changes.count() > 0 else None
|
||||
last_comment = self.comments.order_by('-timestamp').first().timestamp if self.comments.count() > 0 else None
|
||||
last_mail = self.emails.order_by('-timestamp').first().timestamp if self.emails.count() > 0 else None
|
||||
args = [x for x in [last_state_change, last_comment, last_mail] if x is not None]
|
||||
last_assignment = self.assignments.order_by('-timestamp').first().timestamp if \
|
||||
self.assignments.count() > 0 else None
|
||||
args = [x for x in [last_state_change, last_comment, last_mail, last_assignment] if
|
||||
x is not None]
|
||||
return max(args)
|
||||
except AttributeError:
|
||||
return None
|
||||
|
@ -100,6 +110,14 @@ class IssueSerializer(serializers.ModelSerializer):
|
|||
'timestamp': assignment.timestamp,
|
||||
'assigned_to': assignment.assigned_to.username,
|
||||
})
|
||||
for shipping_voucher in obj.shipping_vouchers.all():
|
||||
timeline.append({
|
||||
'type': 'shipping_voucher',
|
||||
'id': shipping_voucher.id,
|
||||
'timestamp': shipping_voucher.used_at,
|
||||
'voucher': shipping_voucher.voucher,
|
||||
'voucher_type': shipping_voucher.type,
|
||||
})
|
||||
return sorted(timeline, key=lambda x: x['timestamp'])
|
||||
|
||||
def get_queryset(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue