|
|
|
|
@ -1,11 +1,11 @@ |
|
|
|
|
import arrow |
|
|
|
|
import short_url |
|
|
|
|
from django.db.models import Func, F |
|
|
|
|
|
|
|
|
|
from paymentwall import Pingback |
|
|
|
|
from polymorphic.models import PolymorphicModel |
|
|
|
|
from polymorphic.managers import PolymorphicManager |
|
|
|
|
|
|
|
|
|
from django.db.models import Func, F |
|
|
|
|
from django.db import models |
|
|
|
|
from django.contrib.auth import get_user_model |
|
|
|
|
from django.contrib.postgres.fields import ArrayField, JSONField |
|
|
|
|
@ -120,6 +120,10 @@ class Payment(PolymorphicModel): |
|
|
|
|
|
|
|
|
|
@classmethod |
|
|
|
|
def add_months(cls, sourcedate, months=1): |
|
|
|
|
# FIXME после мая 2019 убрать? |
|
|
|
|
# Если хотят купить школу в мае, то оплатить ее можно только до 31 мая, потом школа закроется |
|
|
|
|
if sourcedate.month == 5: |
|
|
|
|
return sourcedate.replace(day=31) |
|
|
|
|
result = arrow.get(sourcedate, settings.TIME_ZONE).shift(months=months) |
|
|
|
|
if months == 1: |
|
|
|
|
if (sourcedate.month == 2 and sourcedate.day >= 28) or (sourcedate.day == 31 and result.day <= 30) \ |
|
|
|
|
@ -179,9 +183,18 @@ class Payment(PolymorphicModel): |
|
|
|
|
price += ss.month_price // all_weekdays_count.get(ss.weekday, 0) * weekdays_count.get( |
|
|
|
|
ss.weekday, 0) |
|
|
|
|
else: |
|
|
|
|
price = school_schedules.aggregate( |
|
|
|
|
models.Sum('month_price'), |
|
|
|
|
).get('month_price__sum', 0) |
|
|
|
|
# FIXME после мая 2019 убрать? |
|
|
|
|
# Если хотят купить школу в мае, то оплатить ее можно только до 31 мая, потом школа закроется |
|
|
|
|
if date_start.month == 5: |
|
|
|
|
weekdays_count = weekdays_in_date_range(date_start, date_end) |
|
|
|
|
all_weekdays_count = weekdays_in_date_range(date_start.replace(day=1), date_end) |
|
|
|
|
for ss in school_schedules: |
|
|
|
|
price += ss.month_price // all_weekdays_count.get(ss.weekday, 0) * weekdays_count.get( |
|
|
|
|
ss.weekday, 0) |
|
|
|
|
else: |
|
|
|
|
price = school_schedules.aggregate( |
|
|
|
|
models.Sum('month_price'), |
|
|
|
|
).get('month_price__sum', 0) |
|
|
|
|
if not (payment and payment.id) and price >= config.SERVICE_DISCOUNT_MIN_AMOUNT: |
|
|
|
|
discount = config.SERVICE_DISCOUNT |
|
|
|
|
amount = price - discount |
|
|
|
|
|