|
|
|
|
@ -144,7 +144,10 @@ class SchoolPayment(Payment): |
|
|
|
|
verbose_name_plural = 'Платежи за школу' |
|
|
|
|
|
|
|
|
|
def __str__(self): |
|
|
|
|
days = ', '.join([dict(SchoolSchedule.WEEKDAY_CHOICES).get(weekday, '') for weekday in sorted(self.weekdays)]) |
|
|
|
|
days = ', '.join([ |
|
|
|
|
dict(SchoolSchedule.WEEKDAY_CHOICES).get(weekday, '') |
|
|
|
|
for weekday in sorted(self.weekdays) |
|
|
|
|
]) |
|
|
|
|
return days |
|
|
|
|
|
|
|
|
|
def save(self, *args, **kwargs): |
|
|
|
|
@ -152,9 +155,11 @@ class SchoolPayment(Payment): |
|
|
|
|
weekday__in=self.weekdays, |
|
|
|
|
).aggregate( |
|
|
|
|
models.Sum('month_price'), |
|
|
|
|
models.Sum('day_discount'), |
|
|
|
|
) |
|
|
|
|
month_price_sum = aggregate.get('month_price__sum', 0) |
|
|
|
|
day_discount_sum = aggregate.get('day_discount__sum', 0) if len(self.weekdays) == 7 else 0 |
|
|
|
|
self.amount = month_price_sum - day_discount_sum |
|
|
|
|
if month_price_sum >= config.SERVICE_DISCOUNT_MIN_AMOUNT: |
|
|
|
|
discount = config.SERVICE_DISCOUNT |
|
|
|
|
else: |
|
|
|
|
discount = 0 |
|
|
|
|
self.amount = month_price_sum - discount |
|
|
|
|
super().save(*args, **kwargs) |
|
|
|
|
|