From ec0a931b60e7e4c5689c429e61c2f0d4dca098f9 Mon Sep 17 00:00:00 2001 From: Ivlev Denis Date: Fri, 4 May 2018 18:30:47 +0300 Subject: [PATCH] Update "add day" ammount calc --- apps/payment/models.py | 13 ++++++++++++- apps/payment/views.py | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/payment/models.py b/apps/payment/models.py index a55ce8c5..10146971 100644 --- a/apps/payment/models.py +++ b/apps/payment/models.py @@ -167,8 +167,19 @@ class SchoolPayment(Payment): models.Sum('month_price'), ) if self.add_days: + _school_payment = SchoolPayment.objects.filter( + add_days=False, + date_start__lte=self.date_start, + date_end__gte=self.date_end, + status__in=[ + Pingback.PINGBACK_TYPE_REGULAR, + Pingback.PINGBACK_TYPE_GOODWILL, + Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED, + ], + ).last() weekday_count = weekday_in_date_range(self.date_start, self.date_end, self.weekdays[0]) - month_price_sum = aggregate.get('month_price__sum', 0) * weekday_count / 30 + all_weekday_count = weekday_in_date_range(_school_payment.date_start, _school_payment.date_end, self.weekdays[0]) + month_price_sum = aggregate.get('month_price__sum', 0) * weekday_count // all_weekday_count else: month_price_sum = aggregate.get('month_price__sum', 0) if month_price_sum > config.SERVICE_DISCOUNT_MIN_AMOUNT: diff --git a/apps/payment/views.py b/apps/payment/views.py index 7aa7feff..608d94d3 100644 --- a/apps/payment/views.py +++ b/apps/payment/views.py @@ -107,7 +107,7 @@ class SchoolBuyView(TemplateView): user=request.user, weekdays=weekdays, date_start=now().date(), - date_end=now().date(), + date_end=_school_payment.date_end, add_days=True, ) if school_payment.amount <= 0: