1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2025-11-20 21:38:28 +01:00

Some permissions

This commit is contained in:
Ehouarn
2025-11-20 16:02:38 +01:00
parent 6a77cfd4dd
commit 12b2e7869a
4 changed files with 217 additions and 4 deletions

View File

@@ -396,6 +396,12 @@ class Supplement(models.Model):
return _("Supplement {food} for {dish}").format(
food=str(self.food), dish=str(self.dish))
def save(self, *args, **kwargs):
# Check the owner of the food
if self.food.owner != self.dish.main.owner:
raise ValidationError(_('You cannot select food that belongs to the same club than the main food.'))
return super().save(*args, **kwargs)
class Order(models.Model):
"""
@@ -471,6 +477,8 @@ class Order(models.Model):
user=str(self.user))
def save(self, *args, **kwargs):
if self.activity != self.dish.activity:
raise ValidationError(_('Activities must be the same.'))
created = self.pk is None
if created:
last_order = Order.objects.filter(activity=self.activity).last()
@@ -486,6 +494,7 @@ class Order(models.Model):
destination=self.activity.organizer.note,
amount=self.amount,
quantity=1,
reason=str(self.dish),
)
transaction.save()
else: