diff --git a/bars_transactions/migrations/0004_transaction_uncanceled.py b/bars_transactions/migrations/0004_transaction_uncanceled.py new file mode 100644 index 0000000..cf8b2af --- /dev/null +++ b/bars_transactions/migrations/0004_transaction_uncanceled.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('bars_transactions', '0003_transaction_moneyflow'), + ] + + operations = [ + migrations.AddField( + model_name='transaction', + name='uncanceled', + field=models.BooleanField(default=False), + ), + ] diff --git a/bars_transactions/models.py b/bars_transactions/models.py index ed47ef7..ed7484e 100644 --- a/bars_transactions/models.py +++ b/bars_transactions/models.py @@ -19,6 +19,7 @@ class Meta: type = models.CharField(max_length=25) timestamp = models.DateTimeField(auto_now_add=True) canceled = models.BooleanField(default=False) + uncanceled = models.BooleanField(default=False) last_modified = models.DateTimeField(auto_now=True) _type = VirtualField("Transaction") moneyflow = models.FloatField(default=0) diff --git a/bars_transactions/tests/test_transactions.py b/bars_transactions/tests/test_transactions.py index 2bbe009..b9c0967 100644 --- a/bars_transactions/tests/test_transactions.py +++ b/bars_transactions/tests/test_transactions.py @@ -56,6 +56,7 @@ def setUpTestData(self): def setUp(self): self.transaction.canceled = False + self.transaction.uncanceled = False self.transaction.save() Role.objects.get_or_create(user=self.user, bar=self.bar, name='customer') self.user = reload(self.user) @@ -69,6 +70,7 @@ def test_cancel_transaction(self): def test_restore_transaction(self): self.transaction.canceled = True + self.transaction.uncanceled = True self.transaction.save() self.client.force_authenticate(user=self.user) diff --git a/bars_transactions/views.py b/bars_transactions/views.py index 147d674..9f2aca5 100644 --- a/bars_transactions/views.py +++ b/bars_transactions/views.py @@ -75,7 +75,7 @@ def cancel(self, request, pk=None): except Transaction.DoesNotExist: raise Http404() - if request.user.has_perm('bars_transactions.change_transaction', transaction): + if request.user.has_perm('bars_transactions.change_transaction', transaction) and (not transaction.uncanceled): transaction.canceled = True transaction.save() @@ -100,6 +100,7 @@ def restore(self, request, pk=None): if request.user.has_perm('bars_transactions.change_transaction', transaction): transaction.canceled = False + transaction.uncanceled = True transaction.save() for aop in transaction.accountoperation_set.all():