mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-11-02 08:34:32 +01:00
Quark's tests now run, but they're still weak
This commit is contained in:
@@ -445,36 +445,29 @@ class Order(models.Model):
|
||||
self.number = 1
|
||||
else:
|
||||
self.number = last_order.number + 1
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
elif self.served:
|
||||
if FoodTransaction.objects.filter(order=self).exists():
|
||||
transaction = FoodTransaction.objects.get(order=self)
|
||||
transaction.valid = True
|
||||
transaction.save()
|
||||
else:
|
||||
transaction = FoodTransaction(
|
||||
source=self.user.note,
|
||||
destination=self.activity.organizer.note,
|
||||
amount=self.amount,
|
||||
quantity=1,
|
||||
valid=True,
|
||||
order=self,
|
||||
)
|
||||
transaction.save()
|
||||
transaction = FoodTransaction(
|
||||
order=self,
|
||||
source=self.user.note,
|
||||
destination=self.activity.organizer.note,
|
||||
amount=self.amount,
|
||||
quantity=1,
|
||||
)
|
||||
transaction.save()
|
||||
else:
|
||||
if FoodTransaction.objects.filter(order=self).exists():
|
||||
transaction = FoodTransaction.objects.get(order=self)
|
||||
transaction.valid = False
|
||||
transaction.save()
|
||||
|
||||
return super().save(*args, **kwargs)
|
||||
old_object = Order.objects.get(pk=self.pk)
|
||||
if not old_object.served and self.served:
|
||||
self.served_at = timezone.now()
|
||||
self.transaction.save()
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
class FoodTransaction(Transaction):
|
||||
"""
|
||||
Special type of :model:`note.Transaction` associated to a :model:`food.Order`.
|
||||
"""
|
||||
order = models.ForeignKey(
|
||||
order = models.OneToOneField(
|
||||
Order,
|
||||
on_delete=models.PROTECT,
|
||||
related_name='transaction',
|
||||
@@ -484,3 +477,7 @@ class FoodTransaction(Transaction):
|
||||
class Meta:
|
||||
verbose_name = _("food transaction")
|
||||
verbose_name_plural = _("food transactions")
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.valid = self.order.served
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
Reference in New Issue
Block a user