|
|
|
|
@ -84,6 +84,11 @@ class PaymentManger(PolymorphicManager): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Payment(PolymorphicModel): |
|
|
|
|
PW_PAID_STATUSES = [ |
|
|
|
|
Pingback.PINGBACK_TYPE_REGULAR, |
|
|
|
|
Pingback.PINGBACK_TYPE_GOODWILL, |
|
|
|
|
Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED, |
|
|
|
|
] |
|
|
|
|
PW_STATUS_CHOICES = ( |
|
|
|
|
(Pingback.PINGBACK_TYPE_REGULAR, 'regular',), |
|
|
|
|
(Pingback.PINGBACK_TYPE_GOODWILL, 'goodwill',), |
|
|
|
|
@ -125,6 +130,13 @@ class Payment(PolymorphicModel): |
|
|
|
|
def calc_amount(cls, payment=None, user=None, course=None, date_start=None, weekdays=None): |
|
|
|
|
date_start = date_start or now().date() |
|
|
|
|
date_end = Payment.add_months(date_start, 1) |
|
|
|
|
price = 0 |
|
|
|
|
discount = 0 |
|
|
|
|
referral_bonus = 0 |
|
|
|
|
referrer_bonus = 0 |
|
|
|
|
if hasattr(user, 'referral') and not user.referral.payment: |
|
|
|
|
referral_bonus = user.referral.bonus |
|
|
|
|
referrer_bonus = user.referral.referrer_bonus |
|
|
|
|
if isinstance(payment, CoursePayment): |
|
|
|
|
course = payment.course |
|
|
|
|
user = payment.user |
|
|
|
|
@ -132,14 +144,9 @@ class Payment(PolymorphicModel): |
|
|
|
|
user = payment.user |
|
|
|
|
weekdays = payment.weekdays |
|
|
|
|
date_start = payment.date_start |
|
|
|
|
price = 0 |
|
|
|
|
referral_bonus = 0 |
|
|
|
|
referrer_bonus = 0 |
|
|
|
|
if hasattr(user, 'referral') and not user.referral.payment: |
|
|
|
|
referral_bonus = user.referral.bonus |
|
|
|
|
referrer_bonus = user.referral.referrer_bonus |
|
|
|
|
discount = 0 |
|
|
|
|
if course: |
|
|
|
|
if payment and payment.is_paid(): |
|
|
|
|
price = payment.amount |
|
|
|
|
elif course: |
|
|
|
|
price = course.price |
|
|
|
|
else: |
|
|
|
|
if user: |
|
|
|
|
@ -191,9 +198,15 @@ class Payment(PolymorphicModel): |
|
|
|
|
'weekdays': weekdays, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
# TODO? change to property? |
|
|
|
|
def calc_commission(self): |
|
|
|
|
return self.amount * config.SERVICE_COMMISSION / 100 |
|
|
|
|
|
|
|
|
|
# TODO change to property |
|
|
|
|
def is_paid(self): |
|
|
|
|
return self.status in self.PW_PAID_STATUSES |
|
|
|
|
|
|
|
|
|
# TODO? delete ? change to property |
|
|
|
|
def is_deliverable(self): |
|
|
|
|
return self.status in [ |
|
|
|
|
Pingback.PINGBACK_TYPE_REGULAR, |
|
|
|
|
@ -201,9 +214,11 @@ class Payment(PolymorphicModel): |
|
|
|
|
Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED, |
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
# TODO change to property |
|
|
|
|
def is_under_review(self): |
|
|
|
|
return self.status == Pingback.PINGBACK_TYPE_RISK_UNDER_REVIEW |
|
|
|
|
|
|
|
|
|
# TODO change to property |
|
|
|
|
def is_cancelable(self): |
|
|
|
|
return self.status in [ |
|
|
|
|
Pingback.PINGBACK_TYPE_NEGATIVE, |
|
|
|
|
@ -214,9 +229,7 @@ class Payment(PolymorphicModel): |
|
|
|
|
paid = self.status in [Pingback.PINGBACK_TYPE_REGULAR, Pingback.PINGBACK_TYPE_GOODWILL, |
|
|
|
|
Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED,] |
|
|
|
|
amount_data = Payment.calc_amount(payment=self) |
|
|
|
|
print('amount_data', amount_data) |
|
|
|
|
if self.status is None and not self.bonus: |
|
|
|
|
print(123) |
|
|
|
|
self.amount = amount_data.get('amount') |
|
|
|
|
if isinstance(self, SchoolPayment): |
|
|
|
|
self.weekdays = amount_data.get('weekdays') |
|
|
|
|
|