Release 22 #45
2 changed files with 5 additions and 4 deletions
|
@ -40,6 +40,7 @@ class Drink(models.Model):
|
||||||
do_not_count = models.BooleanField(default=False)
|
do_not_count = models.BooleanField(default=False)
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, *args, **kwargs):
|
||||||
|
# we flag the field as deleted.
|
||||||
self.deleted = True
|
self.deleted = True
|
||||||
super().save()
|
super().save()
|
||||||
|
|
||||||
|
@ -107,10 +108,9 @@ class Order(models.Model):
|
||||||
price_sum = models.DecimalField(max_digits=6, decimal_places=2, default=0, editable=False)
|
price_sum = models.DecimalField(max_digits=6, decimal_places=2, default=0, editable=False)
|
||||||
content_litres = models.DecimalField(max_digits=6, decimal_places=3, default=0, editable=False)
|
content_litres = models.DecimalField(max_digits=6, decimal_places=3, default=0, editable=False)
|
||||||
|
|
||||||
# TODO: Add more comments on how and why the save & delete functions are implemented
|
|
||||||
# address this in a refactoring issue.
|
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
# saving this may affect other fields
|
||||||
|
# so we reimplement the save function
|
||||||
drink = Drink.objects.get(pk=self.drink.pk)
|
drink = Drink.objects.get(pk=self.drink.pk)
|
||||||
if self._state.adding and drink.available > 0:
|
if self._state.adding and drink.available > 0:
|
||||||
if not drink.do_not_count:
|
if not drink.do_not_count:
|
||||||
|
@ -126,6 +126,7 @@ class Order(models.Model):
|
||||||
raise ValidationError("This entry can't be changed.")
|
raise ValidationError("This entry can't be changed.")
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, *args, **kwargs):
|
||||||
|
# when deleting, we affect other fields as well.
|
||||||
self.user.balance += self.price_sum
|
self.user.balance += self.price_sum
|
||||||
self.user.save()
|
self.user.save()
|
||||||
drink = Drink.objects.get(pk=self.drink.pk)
|
drink = Drink.objects.get(pk=self.drink.pk)
|
||||||
|
|
|
@ -14,7 +14,7 @@ from time import sleep
|
||||||
from yaml import safe_load
|
from yaml import safe_load
|
||||||
|
|
||||||
|
|
||||||
banner = """ ___ _ _
|
banner = r""" ___ _ _
|
||||||
| \ _ _ (_) _ _ | |__ ___ ___
|
| \ _ _ (_) _ _ | |__ ___ ___
|
||||||
| |) || '_|| || ' \ | / /(_-< |___|
|
| |) || '_|| || ' \ | / /(_-< |___|
|
||||||
|___/ |_| |_||_||_||_\_\/__/
|
|___/ |_| |_||_||_||_\_\/__/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue