diff --git a/core/tickets/models.py b/core/tickets/models.py index 7159470..b0bb2ca 100644 --- a/core/tickets/models.py +++ b/core/tickets/models.py @@ -1,3 +1,4 @@ +from django.utils import timezone from django.db import models from django_softdelete.models import SoftDeleteModel @@ -148,3 +149,10 @@ class ShippingVoucher(models.Model): def __str__(self): return self.voucher + ' (' + self.type + ')' + + def save(self, *args, **kwargs): + if self.used_at is None and self.issue_thread is not None: + self.used_at = timezone.now() + super().save(*args, **kwargs) + + diff --git a/web/src/store.js b/web/src/store.js index 74f5873..c022d23 100644 --- a/web/src/store.js +++ b/web/src/store.js @@ -88,6 +88,12 @@ const store = createStore({ } } }, + availableShippingVoucherTypes: state => { + return Object.keys(state.shippingVoucherTypes).map(key => { + var count = state.shippingVouchers.filter(voucher => voucher.type === key && voucher.issue_thread === null).length; + return {id: key, count: count, name: state.shippingVoucherTypes[key]}; + }); + }, layout: (state, getters) => { if (router.currentRoute.value.query.layout) return router.currentRoute.value.query.layout; @@ -476,6 +482,16 @@ const store = createStore({ if (data && success) { dispatch('fetchShippingVouchers'); } + }, + async claimShippingVoucher({dispatch, state}, {ticket, shipping_voucher_type}) { + const id = state.shippingVouchers.filter(voucher => voucher.type === shipping_voucher_type && voucher.issue_thread === null)[0].id; + const { + data, + success + } = await http.patch(`/2/shipping_vouchers/${id}/`, {issue_thread: ticket}, state.user.token); + if (data && success) { + dispatch('fetchShippingVouchers'); + } } }, plugins: [ diff --git a/web/src/views/Ticket.vue b/web/src/views/Ticket.vue index b4d1e0e..b8ca82a 100644 --- a/web/src/views/Ticket.vue +++ b/web/src/views/Ticket.vue @@ -13,10 +13,6 @@ Delete - - - Copy DHL contact to clipboard -
+ + + +
+ @@ -41,15 +54,21 @@