diff --git a/core/tickets/admin.py b/core/tickets/admin.py index e519fa6..d842482 100644 --- a/core/tickets/admin.py +++ b/core/tickets/admin.py @@ -1,6 +1,6 @@ from django.contrib import admin -from tickets.models import IssueThread, Comment, StateChange, Assignment, ItemRelation, ShippingCode +from tickets.models import IssueThread, Comment, StateChange, Assignment, ItemRelation, ShippingVoucher class IssueThreadAdmin(admin.ModelAdmin): @@ -23,7 +23,7 @@ class ItemRelationAdmin(admin.ModelAdmin): pass -class ShippingCodesAdmin(admin.ModelAdmin): +class ShippingVouchersAdmin(admin.ModelAdmin): pass @@ -32,4 +32,4 @@ admin.site.register(Comment, CommentAdmin) admin.site.register(StateChange, StateChangeAdmin) admin.site.register(Assignment, AssignmentAdmin) admin.site.register(ItemRelation, ItemRelationAdmin) -admin.site.register(ShippingCode, ShippingCodesAdmin) +admin.site.register(ShippingVoucher, ShippingVouchersAdmin) diff --git a/core/tickets/api_v2.py b/core/tickets/api_v2.py index c32f7b3..23679c2 100644 --- a/core/tickets/api_v2.py +++ b/core/tickets/api_v2.py @@ -13,8 +13,8 @@ from core.settings import MAIL_DOMAIN from mail.models import Email from mail.protocol import send_smtp, make_reply, collect_references from notify_sessions.models import SystemEvent -from tickets.models import IssueThread, Comment, STATE_CHOICES, ShippingCode -from tickets.serializers import IssueSerializer, CommentSerializer, ShippingCodeSerializer +from tickets.models import IssueThread, Comment, STATE_CHOICES, ShippingVoucher +from tickets.serializers import IssueSerializer, CommentSerializer, ShippingVoucherSerializer class IssueViewSet(viewsets.ModelViewSet): @@ -118,7 +118,7 @@ def add_comment(request, pk): router = routers.SimpleRouter() router.register(r'tickets', IssueViewSet, basename='issues') -router.register(r'shipping_codes', ShippingCodeViewSet, basename='shipping_codes') +router.register(r'shipping_vouchers', ShippingVoucherViewSet, basename='shipping_vouchers') urlpatterns = ([ re_path(r'^tickets/(?P\d+)/reply/$', reply, name='reply'), diff --git a/core/tickets/migrations/0012_shippingcode.py b/core/tickets/migrations/0012_shippingcode.py deleted file mode 100644 index b38d901..0000000 --- a/core/tickets/migrations/0012_shippingcode.py +++ /dev/null @@ -1,25 +0,0 @@ -# Generated by Django 4.2.7 on 2024-06-15 17:37 - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('tickets', '0011_issuethread_related_items'), - ] - - operations = [ - migrations.CreateModel( - name='ShippingCode', - fields=[ - ('id', models.AutoField(primary_key=True, serialize=False)), - ('code', models.CharField(max_length=255)), - ('type', models.CharField(max_length=255)), - ('timestamp', models.DateTimeField(auto_now_add=True)), - ('used_at', models.DateTimeField(null=True)), - ('issue_thread', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='shipping_codes', to='tickets.issuethread')), - ], - ), - ] diff --git a/core/tickets/models.py b/core/tickets/models.py index d61638a..a1e6c91 100644 --- a/core/tickets/models.py +++ b/core/tickets/models.py @@ -138,9 +138,9 @@ class ItemRelation(models.Model): return str(self.issue_thread) + ' related to ' + str(self.item) -class ShippingCode(models.Model): +class ShippingVoucher(models.Model): id = models.AutoField(primary_key=True) - issue_thread = models.ForeignKey(IssueThread, on_delete=models.CASCADE, related_name='shipping_codes', null=True) + issue_thread = models.ForeignKey(IssueThread, on_delete=models.CASCADE, related_name='shipping_vouchers', null=True) code = models.CharField(max_length=255) type = models.CharField(max_length=255) timestamp = models.DateTimeField(auto_now_add=True) diff --git a/core/tickets/serializers.py b/core/tickets/serializers.py index 897fdf8..acd8afc 100644 --- a/core/tickets/serializers.py +++ b/core/tickets/serializers.py @@ -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, ShippingCode +from tickets.models import IssueThread, Comment, STATE_CHOICES, ShippingVoucher from inventory.serializers import ItemSerializer @@ -29,9 +29,9 @@ class StateSerializer(serializers.Serializer): return obj['value'] -class ShippingCodeSerializer(serializers.ModelSerializer): +class ShippingVoucherSerializer(serializers.ModelSerializer): class Meta: - model = ShippingCode + model = ShippingVoucher fields = ('id', 'code', 'type', 'timestamp', 'issue_thread', 'used_at') read_only_fields = ('id', 'timestamp', 'used_at') @@ -122,13 +122,13 @@ class IssueSerializer(serializers.ModelSerializer): 'timestamp': relation.timestamp, 'item': ItemSerializer(relation.item).data, }) - for shipping_code in obj.shipping_codes.all(): + for shipping_voucher in obj.shipping_vouchers.all(): timeline.append({ - 'type': 'shipping_code', - 'id': shipping_code.id, - 'timestamp': shipping_code.used_at, - 'code': shipping_code.code, - 'code_type': shipping_code.type, + 'type': 'shipping_voucher', + 'id': shipping_voucher.id, + 'timestamp': shipping_voucher.used_at, + 'code': shipping_voucher.code, + 'code_type': shipping_voucher.type, }) return sorted(timeline, key=lambda x: x['timestamp']) diff --git a/core/tickets/tests/v2/test_shipping_codes.py b/core/tickets/tests/v2/test_shipping_vouchers.py similarity index 80% rename from core/tickets/tests/v2/test_shipping_codes.py rename to core/tickets/tests/v2/test_shipping_vouchers.py index 2115e50..9cfb8df 100644 --- a/core/tickets/tests/v2/test_shipping_codes.py +++ b/core/tickets/tests/v2/test_shipping_vouchers.py @@ -4,12 +4,12 @@ from django.test import TestCase, Client from authentication.models import ExtendedUser from mail.models import Email, EmailAttachment -from tickets.models import IssueThread, StateChange, Comment, ShippingCode +from tickets.models import IssueThread, StateChange, Comment, ShippingVoucher from django.contrib.auth.models import Permission from knox.models import AuthToken -class ShippingCodeApiTest(TestCase): +class ShippingVoucherApiTest(TestCase): def setUp(self): super().setUp() @@ -20,13 +20,13 @@ class ShippingCodeApiTest(TestCase): self.client = Client(headers={'Authorization': 'Token ' + self.token[1]}) def test_issues_empty(self): - response = self.client.get('/api/2/shipping_codes/') + response = self.client.get('/api/2/shipping_vouchers/') self.assertEqual(response.status_code, 200) self.assertEqual(response.json(), []) def test_issues_list(self): - ShippingCode.objects.create(code='1234', type='2kg-eu') - response = self.client.get('/api/2/shipping_codes/') + ShippingVoucher.objects.create(code='1234', type='2kg-eu') + response = self.client.get('/api/2/shipping_vouchers/') self.assertEqual(response.status_code, 200) self.assertEqual(response.json()[0]['code'], '1234') self.assertEqual(response.json()[0]['used_at'], None) @@ -34,7 +34,7 @@ class ShippingCodeApiTest(TestCase): self.assertEqual(response.json()[0]['type'], '2kg-eu') def test_issues_create(self): - response = self.client.post('/api/2/shipping_codes/', {'code': '1234', 'type': '2kg-eu'}) + response = self.client.post('/api/2/shipping_vouchers/', {'code': '1234', 'type': '2kg-eu'}) self.assertEqual(response.status_code, 201) self.assertEqual(response.json()['code'], '1234') self.assertEqual(response.json()['used_at'], None) diff --git a/web/src/components/TimelineShippingCode.vue b/web/src/components/TimelineShippingCode.vue deleted file mode 100644 index 5529422..0000000 --- a/web/src/components/TimelineShippingCode.vue +++ /dev/null @@ -1,91 +0,0 @@ - - - - - \ No newline at end of file diff --git a/web/src/store.js b/web/src/store.js index c9ad60f..74f5873 100644 --- a/web/src/store.js +++ b/web/src/store.js @@ -21,7 +21,7 @@ const store = createStore({ state_options: [], messageTemplates: [], messageTemplateVariables: [], - shippingCodes: [], + shippingVouchers: [], lastEvent: '37C3', lastUsed: {}, @@ -51,7 +51,7 @@ const store = createStore({ showAddBoxModal: false, test: ['foo', 'bar', 'baz'], - shippingCodeTypes: { + shippingVoucherTypes: { '2kg-de': '2kg Paket (DE)', '5kg-de': '5kg Paket (DE)', '10kg-de': '10kg Paket (DE)', @@ -219,8 +219,8 @@ const store = createStore({ setMessageTemplateVariables(state, variables) { state.messageTemplateVariables = variables; }, - setShippingCodes(state, codes) { - state.shippingCodes = codes; + setShippingVouchers(state, codes) { + state.shippingVouchers = codes; }, }, actions: { @@ -465,16 +465,16 @@ const store = createStore({ dispatch('fetchMessageTemplates'); } }, - async fetchShippingCodes({commit, state}) { - const {data, success} = await http.get('/2/shipping_codes/', state.user.token); + async fetchShippingVouchers({commit, state}) { + const {data, success} = await http.get('/2/shipping_vouchers/', state.user.token); if (data && success) { - commit('setShippingCodes', data); + commit('setShippingVouchers', data); } }, - async createShippingCode({dispatch, state}, code) { - const {data, success} = await http.post('/2/shipping_codes/', code, state.user.token); + async createShippingVoucher({dispatch, state}, code) { + const {data, success} = await http.post('/2/shipping_vouchers/', code, state.user.token); if (data && success) { - dispatch('fetchShippingCodes'); + dispatch('fetchShippingVouchers'); } } }, @@ -506,7 +506,7 @@ const store = createStore({ "loadedItems", "messageTemplates", "messageTemplatesVariables", - "shippingCodes", + "shippingVouchers", ], watch: [ "test", @@ -519,7 +519,7 @@ const store = createStore({ "loadedItems", "messageTemplates", "messageTemplatesVariables", - "shippingCodes", + "shippingVouchers", ], mutations: [ //"replaceTickets", diff --git a/web/src/views/admin/Shipping.vue b/web/src/views/admin/Shipping.vue index 20d7341..edd2191 100644 --- a/web/src/views/admin/Shipping.vue +++ b/web/src/views/admin/Shipping.vue @@ -1,9 +1,9 @@