This commit is contained in:
j3d1 2024-06-18 14:15:29 +02:00
parent 4799a7cd5d
commit 69ce11c331
4 changed files with 50 additions and 26 deletions

View file

@ -1,6 +1,6 @@
from django.contrib import admin 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): class IssueThreadAdmin(admin.ModelAdmin):
@ -23,8 +23,13 @@ class ItemRelationAdmin(admin.ModelAdmin):
pass pass
class ShippingCodesAdmin(admin.ModelAdmin):
pass
admin.site.register(IssueThread, IssueThreadAdmin) admin.site.register(IssueThread, IssueThreadAdmin)
admin.site.register(Comment, CommentAdmin) admin.site.register(Comment, CommentAdmin)
admin.site.register(StateChange, StateChangeAdmin) admin.site.register(StateChange, StateChangeAdmin)
admin.site.register(Assignment, AssignmentAdmin) admin.site.register(Assignment, AssignmentAdmin)
admin.site.register(ItemRelation, ItemRelationAdmin) admin.site.register(ItemRelation, ItemRelationAdmin)
admin.site.register(ShippingCode, ShippingCodesAdmin)

View file

@ -4,7 +4,7 @@ from django.test import TestCase, Client
from authentication.models import ExtendedUser from authentication.models import ExtendedUser
from mail.models import Email, EmailAttachment 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 django.contrib.auth.models import Permission
from knox.models import AuthToken from knox.models import AuthToken
@ -24,8 +24,17 @@ class ShippingCodeApiTest(TestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), []) 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): 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.status_code, 201)
self.assertEqual(response.json()['code'], '1234') self.assertEqual(response.json()['code'], '1234')
self.assertEqual(response.json()['used_at'], None) self.assertEqual(response.json()['used_at'], None)

View file

@ -434,12 +434,11 @@ const store = createStore({
commit('setMessageTemplates', data); commit('setMessageTemplates', data);
} }
}, },
async updateMessageTemplate({commit, state}, template) { async updateMessageTemplate({dispatch, state}, template) {
const {data, success} = await http.patch(`/2/message_templates/${template.id}/`, const {data, success} = await http.patch(`/2/message_templates/${template.id}/`,
{'message': template.message}, state.user.token); {'message': template.message}, state.user.token);
const {data: newTemplates, success: newSuccess} = await http.get('/2/message_templates/', state.user.token);
if (data && success) { if (data && success) {
commit('setMessageTemplates', data); dispatch('fetchMessageTemplates');
} }
}, },
async fetchMessageTemplateVariables({commit, state}) { async fetchMessageTemplateVariables({commit, state}) {
@ -448,11 +447,13 @@ const store = createStore({
commit('setMessageTemplateVariables', data); commit('setMessageTemplateVariables', data);
} }
}, },
async createMessageTemplate({commit, state}, template_name) { async createMessageTemplate({dispatch, state}, template_name) {
const {data, success} = await http.post('/2/message_templates/', {name: template_name, message: '-'}, state.user.token); const {data, success} = await http.post('/2/message_templates/', {
const {data: newTemplates, success: newSuccess} = await http.get('/2/message_templates/', state.user.token); name: template_name,
message: '-'
}, state.user.token);
if (data && success) { if (data && success) {
commit('setMessageTemplates', data); dispatch('fetchMessageTemplates');
} }
}, },
async fetchShippingCodes({commit, state}) { async fetchShippingCodes({commit, state}) {
@ -461,10 +462,10 @@ const store = createStore({
commit('setShippingCodes', data); 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); const {data, success} = await http.post('/2/shipping_codes/', code, state.user.token);
if (data && success) { if (data && success) {
commit('setShippingCodes', data); dispatch('fetchShippingCodes');
} }
} }
}, },

View file

@ -3,7 +3,9 @@
<h3>Shipping Codes</h3> <h3>Shipping Codes</h3>
<ul> <ul>
<li v-for="code in shippingCodes" :key="code.code"> <li v-for="code in shippingCodes" :key="code.code">
{{ code.type }} - {{ code.code }} <span v-if="code.issue_thread == null">{{ code.type }} - {{ code.code }}</span>
<span v-else><s>{{ code.type }} - {{ code.code }}</s> <a
:href="'/'+ getEventSlug + '/ticket/' + code.issue_thread">Issue</a></span>
</li> </li>
</ul> </ul>
<!--Table <!--Table
@ -25,15 +27,16 @@
</template> </template>
</Table--> </Table-->
<div class="mt-3"> <div class="mt-3">
<textarea class="form-control mb-3" rows="5" placeholder="Shipping Code List" v-model="bulk_codes" v-if="bulk"></textarea> <textarea class="form-control mb-3" rows="5" placeholder="Shipping Code List" v-model="bulk_codes"
v-if="bulk"></textarea>
<div class="input-group"> <div class="input-group">
<input type="text" class="form-control" placeholder="Shipping Code" v-model="code" v-if="!bulk"> <input type="text" class="form-control" placeholder="Shipping Code" v-model="code" v-if="!bulk">
<select class="form-control" v-model="type"> <select class="form-control" v-model="type">
<option value="2kg-eu">2kg DE</option> <option value="2kg-de">2kg DE</option>
<option value="2kg-uk">2kg EU</option> <option value="2kg-eu">2kg EU</option>
<option value="2kg-us">5kg DE</option> <option value="5kg-de">5kg DE</option>
<option value="2kg-us">5kg EU</option> <option value="5kg-eu">5kg EU</option>
<option value="2kg-us">10kg DE</option> <option value="10kg-de">10kg DE</option>
</select> </select>
<div class="input-group-prepend"> <div class="input-group-prepend">
<div class="input-group-text"> <div class="input-group-text">
@ -51,7 +54,7 @@
</template> </template>
<script> <script>
import {mapActions, mapState} from 'vuex'; import {mapActions, mapGetters, mapState} from 'vuex';
import Table from '@/components/Table'; import Table from '@/components/Table';
export default { export default {
@ -65,18 +68,24 @@ export default {
bulk: false, bulk: false,
}; };
}, },
computed: mapState(['shippingCodes']), computed: {
...mapState(['shippingCodes']),
...mapGetters(['getEventSlug']),
},
methods: { methods: {
...mapActions(['fetchShippingCodes', 'createShippingCode']), ...mapActions(['fetchShippingCodes', 'createShippingCode']),
createSingleOrBulkShippingCode() { createSingleOrBulkShippingCode() {
if (this.bulk) { if (this.bulk) {
this.bulk_codes.split('\n').forEach(code => { const jobs = this.bulk_codes.split('\n').map(code => {
this.createShippingCode({code: code.trim(), type: this.type}); return this.createShippingCode({code: code.trim(), type: this.type});
});
Promise.all(jobs).then(() => {
this.bulk_codes = '';
}); });
this.bulk_codes = '';
} else { } else {
this.createShippingCode({code: this.code, type: this.type}); this.createShippingCode({code: this.code, type: this.type}).then(() => {
this.code = ''; this.code = '';
});
} }
}, },
}, },