diff --git a/core/tickets/admin.py b/core/tickets/admin.py index 6e28aec..e519fa6 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 +from tickets.models import IssueThread, Comment, StateChange, Assignment, ItemRelation, ShippingCode class IssueThreadAdmin(admin.ModelAdmin): @@ -23,8 +23,13 @@ class ItemRelationAdmin(admin.ModelAdmin): pass +class ShippingCodesAdmin(admin.ModelAdmin): + pass + + admin.site.register(IssueThread, IssueThreadAdmin) 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) diff --git a/core/tickets/tests/v2/test_shipping_codes.py b/core/tickets/tests/v2/test_shipping_codes.py index 7c64460..2115e50 100644 --- a/core/tickets/tests/v2/test_shipping_codes.py +++ b/core/tickets/tests/v2/test_shipping_codes.py @@ -4,7 +4,7 @@ from django.test import TestCase, Client from authentication.models import ExtendedUser from mail.models import Email, EmailAttachment -from tickets.models import IssueThread, StateChange, Comment +from tickets.models import IssueThread, StateChange, Comment, ShippingCode from django.contrib.auth.models import Permission from knox.models import AuthToken @@ -24,8 +24,17 @@ class ShippingCodeApiTest(TestCase): 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/') + self.assertEqual(response.status_code, 200) + self.assertEqual(response.json()[0]['code'], '1234') + self.assertEqual(response.json()[0]['used_at'], None) + self.assertEqual(response.json()[0]['issue_thread'], None) + self.assertEqual(response.json()[0]['type'], '2kg-eu') + def test_issues_create(self): - response = self.client.post('/api/2/shipping_codes/', {'code': '1234'}) + response = self.client.post('/api/2/shipping_codes/', {'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/store.js b/web/src/store.js index ff7a014..0dcb2bb 100644 --- a/web/src/store.js +++ b/web/src/store.js @@ -434,12 +434,11 @@ const store = createStore({ commit('setMessageTemplates', data); } }, - async updateMessageTemplate({commit, state}, template) { + async updateMessageTemplate({dispatch, state}, template) { const {data, success} = await http.patch(`/2/message_templates/${template.id}/`, {'message': template.message}, state.user.token); - const {data: newTemplates, success: newSuccess} = await http.get('/2/message_templates/', state.user.token); if (data && success) { - commit('setMessageTemplates', data); + dispatch('fetchMessageTemplates'); } }, async fetchMessageTemplateVariables({commit, state}) { @@ -448,11 +447,13 @@ const store = createStore({ commit('setMessageTemplateVariables', data); } }, - async createMessageTemplate({commit, state}, template_name) { - const {data, success} = await http.post('/2/message_templates/', {name: template_name, message: '-'}, state.user.token); - const {data: newTemplates, success: newSuccess} = await http.get('/2/message_templates/', state.user.token); + async createMessageTemplate({dispatch, state}, template_name) { + const {data, success} = await http.post('/2/message_templates/', { + name: template_name, + message: '-' + }, state.user.token); if (data && success) { - commit('setMessageTemplates', data); + dispatch('fetchMessageTemplates'); } }, async fetchShippingCodes({commit, state}) { @@ -461,10 +462,10 @@ const store = createStore({ commit('setShippingCodes', data); } }, - async createShippingCode({commit, state}, code) { + async createShippingCode({dispatch, state}, code) { const {data, success} = await http.post('/2/shipping_codes/', code, state.user.token); if (data && success) { - commit('setShippingCodes', data); + dispatch('fetchShippingCodes'); } } }, diff --git a/web/src/views/admin/Shipping.vue b/web/src/views/admin/Shipping.vue index 4c79dda..227dfe8 100644 --- a/web/src/views/admin/Shipping.vue +++ b/web/src/views/admin/Shipping.vue @@ -3,7 +3,9 @@