We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Show price on event before attending


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `apps/payment/models.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 import uuid
4 
5 from django.conf import settings
6 from django.contrib.contenttypes.fields import GenericForeignKey
7 from django.contrib.contenttypes.models import ContentType
8 from django.db import models
9 from django.utils import timezone
10 from django.utils.translation import ugettext as _
11 from rest_framework.exceptions import NotAcceptable
12 
13 from apps.events.models import AttendanceEvent, Attendee
14 from apps.marks.models import Suspension
15 
16 User = settings.AUTH_USER_MODEL
17 
18 
19 class Payment(models.Model):
20 
21     TYPE_CHOICES = (
22         (1, _('Umiddelbar')),
23         (2, _('Frist')),
24         (3, _('Utsettelse')),
25     )
26 
27     # creates tuples used as key choices.
28     STRIPE_KEY_CHOICES = zip(settings.STRIPE_PUBLIC_KEYS.keys(), settings.STRIPE_PUBLIC_KEYS.keys())
29 
30     content_type = models.ForeignKey(ContentType)
31     object_id = models.PositiveIntegerField()
32     content_object = GenericForeignKey()
33     stripe_key = models.CharField(
34         _('stripe key'),
35         max_length=10,
36         choices=STRIPE_KEY_CHOICES,
37         default="arrkom"
38     )
39 
40     payment_type = models.SmallIntegerField(_('type'), choices=TYPE_CHOICES)
41 
42     # Optional fields depending on payment type
43     deadline = models.DateTimeField(_("frist"), blank=True, null=True)
44     active = models.BooleanField(default=True)
45     delay = models.SmallIntegerField(_('utsettelse'), blank=True, null=True, default=2)
46 
47     # For logging and history
48     added_date = models.DateTimeField(_("opprettet dato"), auto_now=True)
49     changed_date = models.DateTimeField(auto_now=True, editable=False)
50     last_changed_by = models.ForeignKey(User, editable=False, null=True)  # Blank and null is temperarly
51 
52     def paid_users(self):
53         return [payment_relation.user for payment_relation in self.paymentrelation_set.filter(refunded=False)]
54 
55     def payment_delays(self):
56         return self.paymentdelay_set.filter(active=True)
57 
58     def payment_delay_users(self):
59         return [payment_delay.user for payment_delay in self.payment_delays()]
60 
61     def create_payment_delay(self, user, deadline):
62         payment_delays = self.paymentdelay_set.filter(payment=self, user=user)
63 
64         if payment_delays:
65             for payment_delay in payment_delays:
66                 payment_delay.valid_to = deadline
67                 payment_delay.save()
68         else:
69             PaymentDelay.objects.create(payment=self, user=user, valid_to=deadline)
70 
71     def description(self):
72         if self._is_type(AttendanceEvent):
73             return self.content_object.event.title
74 
75     def responsible_mail(self):
76         if self._is_type(AttendanceEvent):
77             event_type = self.content_object.event.event_type
78             if event_type == 1 or event_type == 4:  # Sosialt & Utflukt
79                 return settings.EMAIL_ARRKOM
80             elif event_type == 2:  # Bedpres
81                 return settings.EMAIL_BEDKOM
82             elif event_type == 3:  # Kurs
83                 return settings.EMAIL_FAGKOM
84             elif event_type == 5:  # Ekskursjon
85                 return settings.EMAIL_EKSKOM
86             else:
87                 return settings.DEFAULT_FROM_EMAIL
88         else:
89             return settings.DEFAULT_FROM_EMAIL
90 
91     def handle_payment(self, user):
92         if self._is_type(AttendanceEvent):
93             attendee = Attendee.objects.filter(event=self.content_object, user=user)
94 
95             # Delete payment delay objects for the user if there are any
96             delays = PaymentDelay.objects.filter(payment=self, user=user)
97             for delay in delays:
98                 delay.delete()
99 
100             # If the user is suspended because of a lack of payment the suspension is deactivated.
101             suspensions = Suspension.objects.filter(payment_id=self.id, user=user)
102             for suspension in suspensions:
103                 suspension.active = False
104                 suspension.save()
105 
106             if attendee:
107                 attendee[0].paid = True
108                 attendee[0].save()
109             else:
110                 Attendee.objects.create(event=self.content_object, user=user, paid=True)
111 
112     def handle_refund(self, host, payment_relation):
113         payment_relation.refunded = True
114         payment_relation.save()
115 
116         if self._is_type(AttendanceEvent):
117             self.content_object.notify_waiting_list(
118                 host=host, unattended_user=payment_relation.user)
119             Attendee.objects.get(event=self.content_object,
120                                  user=payment_relation.user).delete()
121 
122     def check_refund(self, payment_relation):
123         if self._is_type(AttendanceEvent):
124             attendance_event = self.content_object
125             if attendance_event.unattend_deadline < timezone.now():
126                 return False, _("Fristen for og melde seg av har utgått")
127             if len(Attendee.objects.filter(event=attendance_event, user=payment_relation.user)) == 0:
128                 return False, _("Du er ikke påmeldt dette arrangementet.")
129             if attendance_event.event.event_start < timezone.now():
130                 return False, _("Dette arrangementet har allerede startet.")
131 
132             return True, ''
133 
134         return False, 'Refund checks not implemented'
135 
136     def prices(self):
137         return self.paymentprice_set.all()
138 
139     def _is_type(self, model_type):
140         return ContentType.objects.get_for_model(model_type) == self.content_type
141 
142     def __str__(self):
143         return self.description()
144 
145     class Meta(object):
146         unique_together = ('content_type', 'object_id')
147 
148         verbose_name = _("betaling")
149         verbose_name_plural = _("betalinger")
150 
151 
152 class PaymentPrice(models.Model):
153     payment = models.ForeignKey(Payment)
154     price = models.IntegerField(_("pris"))
155     description = models.CharField(max_length=128, null=True, blank=True)
156 
157     def __str__(self):
158         return str(self.price)
159 
160     class Meta(object):
161         verbose_name = _("pris")
162         verbose_name_plural = _("priser")
163 
164 
165 class PaymentRelation(models.Model):
166     payment = models.ForeignKey(Payment)
167     payment_price = models.ForeignKey(PaymentPrice)
168     user = models.ForeignKey(User)
169     datetime = models.DateTimeField(auto_now=True)
170     refunded = models.BooleanField(default=False)
171 
172     unique_id = models.CharField(max_length=128, null=True, blank=True)
173     stripe_id = models.CharField(max_length=128)
174 
175     def save(self, *args, **kwargs):
176         if not self.unique_id:
177             self.unique_id = str(uuid.uuid4())
178         super(PaymentRelation, self).save(*args, **kwargs)
179 
180     def __str__(self):
181         return self.payment.description() + " - " + str(self.user)
182 
183     class Meta(object):
184         verbose_name = _("betalingsrelasjon")
185         verbose_name_plural = _("betalingsrelasjoner")
186 
187 
188 class PaymentDelay(models.Model):
189     payment = models.ForeignKey(Payment)
190     user = models.ForeignKey(User)
191     valid_to = models.DateTimeField()
192 
193     active = models.BooleanField(default=True)
194 
195     def __str__(self):
196         return self.payment.description() + " - " + str(self.user)
197 
198     class Meta(object):
199         unique_together = ('payment', 'user')
200 
201         verbose_name = _('betalingsutsettelse')
202         verbose_name_plural = _('betalingsutsettelser')
203 
204 
205 class PaymentTransaction(models.Model):
206     user = models.ForeignKey(User)
207     amount = models.IntegerField(null=True, blank=True)
208     used_stripe = models.BooleanField(default=False)
209 
210     datetime = models.DateTimeField(auto_now=True)
211 
212     def __str__(self):
213         return str(self.user) + " - " + str(self.amount) + "(" + str(self.datetime) + ")"
214 
215     def save(self, *args, **kwargs):
216         if not self.pk:
217             self.user.saldo = self.user.saldo + self.amount
218 
219             if self.user.saldo < 0:
220                 raise NotAcceptable("Insufficient funds")
221 
222             self.user.save()
223         super(PaymentTransaction, self).save(*args, **kwargs)
224 
225     class Meta:
226         ordering = ['-datetime']
227         verbose_name = _('transaksjon')
228         verbose_name_plural = _('transaksjoner')
229
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/apps/payment/models.py b/apps/payment/models.py
--- a/apps/payment/models.py
+++ b/apps/payment/models.py
@@ -136,6 +136,10 @@
     def prices(self):
         return self.paymentprice_set.all()
 
+    def price(self):
+        # TODO implement group based pricing
+        return self.paymentprice_set.all()[0]
+
     def _is_type(self, model_type):
         return ContentType.objects.get_for_model(model_type) == self.content_type

{"golden_diff": "diff --git a/apps/payment/models.py b/apps/payment/models.py\n--- a/apps/payment/models.py\n+++ b/apps/payment/models.py\n@@ -136,6 +136,10 @@\n     def prices(self):\n         return self.paymentprice_set.all()\n \n+    def price(self):\n+        # TODO implement group based pricing\n+        return self.paymentprice_set.all()[0]\n+\n     def _is_type(self, model_type):\n         return ContentType.objects.get_for_model(model_type) == self.content_type\n", "issue": "Show price on event before attending\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\nimport uuid\n\nfrom django.conf import settings\nfrom django.contrib.contenttypes.fields import GenericForeignKey\nfrom django.contrib.contenttypes.models import ContentType\nfrom django.db import models\nfrom django.utils import timezone\nfrom django.utils.translation import ugettext as _\nfrom rest_framework.exceptions import NotAcceptable\n\nfrom apps.events.models import AttendanceEvent, Attendee\nfrom apps.marks.models import Suspension\n\nUser = settings.AUTH_USER_MODEL\n\n\nclass Payment(models.Model):\n\n    TYPE_CHOICES = (\n        (1, _('Umiddelbar')),\n        (2, _('Frist')),\n        (3, _('Utsettelse')),\n    )\n\n    # creates tuples used as key choices.\n    STRIPE_KEY_CHOICES = zip(settings.STRIPE_PUBLIC_KEYS.keys(), settings.STRIPE_PUBLIC_KEYS.keys())\n\n    content_type = models.ForeignKey(ContentType)\n    object_id = models.PositiveIntegerField()\n    content_object = GenericForeignKey()\n    stripe_key = models.CharField(\n        _('stripe key'),\n        max_length=10,\n        choices=STRIPE_KEY_CHOICES,\n        default=\"arrkom\"\n    )\n\n    payment_type = models.SmallIntegerField(_('type'), choices=TYPE_CHOICES)\n\n    # Optional fields depending on payment type\n    deadline = models.DateTimeField(_(\"frist\"), blank=True, null=True)\n    active = models.BooleanField(default=True)\n    delay = models.SmallIntegerField(_('utsettelse'), blank=True, null=True, default=2)\n\n    # For logging and history\n    added_date = models.DateTimeField(_(\"opprettet dato\"), auto_now=True)\n    changed_date = models.DateTimeField(auto_now=True, editable=False)\n    last_changed_by = models.ForeignKey(User, editable=False, null=True)  # Blank and null is temperarly\n\n    def paid_users(self):\n        return [payment_relation.user for payment_relation in self.paymentrelation_set.filter(refunded=False)]\n\n    def payment_delays(self):\n        return self.paymentdelay_set.filter(active=True)\n\n    def payment_delay_users(self):\n        return [payment_delay.user for payment_delay in self.payment_delays()]\n\n    def create_payment_delay(self, user, deadline):\n        payment_delays = self.paymentdelay_set.filter(payment=self, user=user)\n\n        if payment_delays:\n            for payment_delay in payment_delays:\n                payment_delay.valid_to = deadline\n                payment_delay.save()\n        else:\n            PaymentDelay.objects.create(payment=self, user=user, valid_to=deadline)\n\n    def description(self):\n        if self._is_type(AttendanceEvent):\n            return self.content_object.event.title\n\n    def responsible_mail(self):\n        if self._is_type(AttendanceEvent):\n            event_type = self.content_object.event.event_type\n            if event_type == 1 or event_type == 4:  # Sosialt & Utflukt\n                return settings.EMAIL_ARRKOM\n            elif event_type == 2:  # Bedpres\n                return settings.EMAIL_BEDKOM\n            elif event_type == 3:  # Kurs\n                return settings.EMAIL_FAGKOM\n            elif event_type == 5:  # Ekskursjon\n                return settings.EMAIL_EKSKOM\n            else:\n                return settings.DEFAULT_FROM_EMAIL\n        else:\n            return settings.DEFAULT_FROM_EMAIL\n\n    def handle_payment(self, user):\n        if self._is_type(AttendanceEvent):\n            attendee = Attendee.objects.filter(event=self.content_object, user=user)\n\n            # Delete payment delay objects for the user if there are any\n            delays = PaymentDelay.objects.filter(payment=self, user=user)\n            for delay in delays:\n                delay.delete()\n\n            # If the user is suspended because of a lack of payment the suspension is deactivated.\n            suspensions = Suspension.objects.filter(payment_id=self.id, user=user)\n            for suspension in suspensions:\n                suspension.active = False\n                suspension.save()\n\n            if attendee:\n                attendee[0].paid = True\n                attendee[0].save()\n            else:\n                Attendee.objects.create(event=self.content_object, user=user, paid=True)\n\n    def handle_refund(self, host, payment_relation):\n        payment_relation.refunded = True\n        payment_relation.save()\n\n        if self._is_type(AttendanceEvent):\n            self.content_object.notify_waiting_list(\n                host=host, unattended_user=payment_relation.user)\n            Attendee.objects.get(event=self.content_object,\n                                 user=payment_relation.user).delete()\n\n    def check_refund(self, payment_relation):\n        if self._is_type(AttendanceEvent):\n            attendance_event = self.content_object\n            if attendance_event.unattend_deadline < timezone.now():\n                return False, _(\"Fristen for og melde seg av har utg\u00e5tt\")\n            if len(Attendee.objects.filter(event=attendance_event, user=payment_relation.user)) == 0:\n                return False, _(\"Du er ikke p\u00e5meldt dette arrangementet.\")\n            if attendance_event.event.event_start < timezone.now():\n                return False, _(\"Dette arrangementet har allerede startet.\")\n\n            return True, ''\n\n        return False, 'Refund checks not implemented'\n\n    def prices(self):\n        return self.paymentprice_set.all()\n\n    def _is_type(self, model_type):\n        return ContentType.objects.get_for_model(model_type) == self.content_type\n\n    def __str__(self):\n        return self.description()\n\n    class Meta(object):\n        unique_together = ('content_type', 'object_id')\n\n        verbose_name = _(\"betaling\")\n        verbose_name_plural = _(\"betalinger\")\n\n\nclass PaymentPrice(models.Model):\n    payment = models.ForeignKey(Payment)\n    price = models.IntegerField(_(\"pris\"))\n    description = models.CharField(max_length=128, null=True, blank=True)\n\n    def __str__(self):\n        return str(self.price)\n\n    class Meta(object):\n        verbose_name = _(\"pris\")\n        verbose_name_plural = _(\"priser\")\n\n\nclass PaymentRelation(models.Model):\n    payment = models.ForeignKey(Payment)\n    payment_price = models.ForeignKey(PaymentPrice)\n    user = models.ForeignKey(User)\n    datetime = models.DateTimeField(auto_now=True)\n    refunded = models.BooleanField(default=False)\n\n    unique_id = models.CharField(max_length=128, null=True, blank=True)\n    stripe_id = models.CharField(max_length=128)\n\n    def save(self, *args, **kwargs):\n        if not self.unique_id:\n            self.unique_id = str(uuid.uuid4())\n        super(PaymentRelation, self).save(*args, **kwargs)\n\n    def __str__(self):\n        return self.payment.description() + \" - \" + str(self.user)\n\n    class Meta(object):\n        verbose_name = _(\"betalingsrelasjon\")\n        verbose_name_plural = _(\"betalingsrelasjoner\")\n\n\nclass PaymentDelay(models.Model):\n    payment = models.ForeignKey(Payment)\n    user = models.ForeignKey(User)\n    valid_to = models.DateTimeField()\n\n    active = models.BooleanField(default=True)\n\n    def __str__(self):\n        return self.payment.description() + \" - \" + str(self.user)\n\n    class Meta(object):\n        unique_together = ('payment', 'user')\n\n        verbose_name = _('betalingsutsettelse')\n        verbose_name_plural = _('betalingsutsettelser')\n\n\nclass PaymentTransaction(models.Model):\n    user = models.ForeignKey(User)\n    amount = models.IntegerField(null=True, blank=True)\n    used_stripe = models.BooleanField(default=False)\n\n    datetime = models.DateTimeField(auto_now=True)\n\n    def __str__(self):\n        return str(self.user) + \" - \" + str(self.amount) + \"(\" + str(self.datetime) + \")\"\n\n    def save(self, *args, **kwargs):\n        if not self.pk:\n            self.user.saldo = self.user.saldo + self.amount\n\n            if self.user.saldo < 0:\n                raise NotAcceptable(\"Insufficient funds\")\n\n            self.user.save()\n        super(PaymentTransaction, self).save(*args, **kwargs)\n\n    class Meta:\n        ordering = ['-datetime']\n        verbose_name = _('transaksjon')\n        verbose_name_plural = _('transaksjoner')\n", "path": "apps/payment/models.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\nimport uuid\n\nfrom django.conf import settings\nfrom django.contrib.contenttypes.fields import GenericForeignKey\nfrom django.contrib.contenttypes.models import ContentType\nfrom django.db import models\nfrom django.utils import timezone\nfrom django.utils.translation import ugettext as _\nfrom rest_framework.exceptions import NotAcceptable\n\nfrom apps.events.models import AttendanceEvent, Attendee\nfrom apps.marks.models import Suspension\n\nUser = settings.AUTH_USER_MODEL\n\n\nclass Payment(models.Model):\n\n    TYPE_CHOICES = (\n        (1, _('Umiddelbar')),\n        (2, _('Frist')),\n        (3, _('Utsettelse')),\n    )\n\n    # creates tuples used as key choices.\n    STRIPE_KEY_CHOICES = zip(settings.STRIPE_PUBLIC_KEYS.keys(), settings.STRIPE_PUBLIC_KEYS.keys())\n\n    content_type = models.ForeignKey(ContentType)\n    object_id = models.PositiveIntegerField()\n    content_object = GenericForeignKey()\n    stripe_key = models.CharField(\n        _('stripe key'),\n        max_length=10,\n        choices=STRIPE_KEY_CHOICES,\n        default=\"arrkom\"\n    )\n\n    payment_type = models.SmallIntegerField(_('type'), choices=TYPE_CHOICES)\n\n    # Optional fields depending on payment type\n    deadline = models.DateTimeField(_(\"frist\"), blank=True, null=True)\n    active = models.BooleanField(default=True)\n    delay = models.SmallIntegerField(_('utsettelse'), blank=True, null=True, default=2)\n\n    # For logging and history\n    added_date = models.DateTimeField(_(\"opprettet dato\"), auto_now=True)\n    changed_date = models.DateTimeField(auto_now=True, editable=False)\n    last_changed_by = models.ForeignKey(User, editable=False, null=True)  # Blank and null is temperarly\n\n    def paid_users(self):\n        return [payment_relation.user for payment_relation in self.paymentrelation_set.filter(refunded=False)]\n\n    def payment_delays(self):\n        return self.paymentdelay_set.filter(active=True)\n\n    def payment_delay_users(self):\n        return [payment_delay.user for payment_delay in self.payment_delays()]\n\n    def create_payment_delay(self, user, deadline):\n        payment_delays = self.paymentdelay_set.filter(payment=self, user=user)\n\n        if payment_delays:\n            for payment_delay in payment_delays:\n                payment_delay.valid_to = deadline\n                payment_delay.save()\n        else:\n            PaymentDelay.objects.create(payment=self, user=user, valid_to=deadline)\n\n    def description(self):\n        if self._is_type(AttendanceEvent):\n            return self.content_object.event.title\n\n    def responsible_mail(self):\n        if self._is_type(AttendanceEvent):\n            event_type = self.content_object.event.event_type\n            if event_type == 1 or event_type == 4:  # Sosialt & Utflukt\n                return settings.EMAIL_ARRKOM\n            elif event_type == 2:  # Bedpres\n                return settings.EMAIL_BEDKOM\n            elif event_type == 3:  # Kurs\n                return settings.EMAIL_FAGKOM\n            elif event_type == 5:  # Ekskursjon\n                return settings.EMAIL_EKSKOM\n            else:\n                return settings.DEFAULT_FROM_EMAIL\n        else:\n            return settings.DEFAULT_FROM_EMAIL\n\n    def handle_payment(self, user):\n        if self._is_type(AttendanceEvent):\n            attendee = Attendee.objects.filter(event=self.content_object, user=user)\n\n            # Delete payment delay objects for the user if there are any\n            delays = PaymentDelay.objects.filter(payment=self, user=user)\n            for delay in delays:\n                delay.delete()\n\n            # If the user is suspended because of a lack of payment the suspension is deactivated.\n            suspensions = Suspension.objects.filter(payment_id=self.id, user=user)\n            for suspension in suspensions:\n                suspension.active = False\n                suspension.save()\n\n            if attendee:\n                attendee[0].paid = True\n                attendee[0].save()\n            else:\n                Attendee.objects.create(event=self.content_object, user=user, paid=True)\n\n    def handle_refund(self, host, payment_relation):\n        payment_relation.refunded = True\n        payment_relation.save()\n\n        if self._is_type(AttendanceEvent):\n            self.content_object.notify_waiting_list(\n                host=host, unattended_user=payment_relation.user)\n            Attendee.objects.get(event=self.content_object,\n                                 user=payment_relation.user).delete()\n\n    def check_refund(self, payment_relation):\n        if self._is_type(AttendanceEvent):\n            attendance_event = self.content_object\n            if attendance_event.unattend_deadline < timezone.now():\n                return False, _(\"Fristen for og melde seg av har utg\u00e5tt\")\n            if len(Attendee.objects.filter(event=attendance_event, user=payment_relation.user)) == 0:\n                return False, _(\"Du er ikke p\u00e5meldt dette arrangementet.\")\n            if attendance_event.event.event_start < timezone.now():\n                return False, _(\"Dette arrangementet har allerede startet.\")\n\n            return True, ''\n\n        return False, 'Refund checks not implemented'\n\n    def prices(self):\n        return self.paymentprice_set.all()\n\n    def price(self):\n        # TODO implement group based pricing\n        return self.paymentprice_set.all()[0]\n\n    def _is_type(self, model_type):\n        return ContentType.objects.get_for_model(model_type) == self.content_type\n\n    def __str__(self):\n        return self.description()\n\n    class Meta(object):\n        unique_together = ('content_type', 'object_id')\n\n        verbose_name = _(\"betaling\")\n        verbose_name_plural = _(\"betalinger\")\n\n\nclass PaymentPrice(models.Model):\n    payment = models.ForeignKey(Payment)\n    price = models.IntegerField(_(\"pris\"))\n    description = models.CharField(max_length=128, null=True, blank=True)\n\n    def __str__(self):\n        return str(self.price)\n\n    class Meta(object):\n        verbose_name = _(\"pris\")\n        verbose_name_plural = _(\"priser\")\n\n\nclass PaymentRelation(models.Model):\n    payment = models.ForeignKey(Payment)\n    payment_price = models.ForeignKey(PaymentPrice)\n    user = models.ForeignKey(User)\n    datetime = models.DateTimeField(auto_now=True)\n    refunded = models.BooleanField(default=False)\n\n    unique_id = models.CharField(max_length=128, null=True, blank=True)\n    stripe_id = models.CharField(max_length=128)\n\n    def save(self, *args, **kwargs):\n        if not self.unique_id:\n            self.unique_id = str(uuid.uuid4())\n        super(PaymentRelation, self).save(*args, **kwargs)\n\n    def __str__(self):\n        return self.payment.description() + \" - \" + str(self.user)\n\n    class Meta(object):\n        verbose_name = _(\"betalingsrelasjon\")\n        verbose_name_plural = _(\"betalingsrelasjoner\")\n\n\nclass PaymentDelay(models.Model):\n    payment = models.ForeignKey(Payment)\n    user = models.ForeignKey(User)\n    valid_to = models.DateTimeField()\n\n    active = models.BooleanField(default=True)\n\n    def __str__(self):\n        return self.payment.description() + \" - \" + str(self.user)\n\n    class Meta(object):\n        unique_together = ('payment', 'user')\n\n        verbose_name = _('betalingsutsettelse')\n        verbose_name_plural = _('betalingsutsettelser')\n\n\nclass PaymentTransaction(models.Model):\n    user = models.ForeignKey(User)\n    amount = models.IntegerField(null=True, blank=True)\n    used_stripe = models.BooleanField(default=False)\n\n    datetime = models.DateTimeField(auto_now=True)\n\n    def __str__(self):\n        return str(self.user) + \" - \" + str(self.amount) + \"(\" + str(self.datetime) + \")\"\n\n    def save(self, *args, **kwargs):\n        if not self.pk:\n            self.user.saldo = self.user.saldo + self.amount\n\n            if self.user.saldo < 0:\n                raise NotAcceptable(\"Insufficient funds\")\n\n            self.user.save()\n        super(PaymentTransaction, self).save(*args, **kwargs)\n\n    class Meta:\n        ordering = ['-datetime']\n        verbose_name = _('transaksjon')\n        verbose_name_plural = _('transaksjoner')\n", "path": "apps/payment/models.py"}]}