|
|
|
|
@ -2,6 +2,7 @@ from django.db import models |
|
|
|
|
from django.contrib.auth import get_user_model |
|
|
|
|
from django.contrib.postgres.fields import ArrayField, JSONField |
|
|
|
|
|
|
|
|
|
from constance import config |
|
|
|
|
from paymentwall import Pingback |
|
|
|
|
from polymorphic.models import PolymorphicModel |
|
|
|
|
|
|
|
|
|
@ -21,7 +22,8 @@ class AuthorBalance(models.Model): |
|
|
|
|
(1, 'Accepted'), |
|
|
|
|
(2, 'Declined'), |
|
|
|
|
) |
|
|
|
|
author = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='Автор', null=True, blank=True, related_name='balances') |
|
|
|
|
author = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='Автор', |
|
|
|
|
null=True, blank=True, related_name='balances') |
|
|
|
|
type = models.PositiveSmallIntegerField('Тип', choices=TYPE_CHOICES, default=0) |
|
|
|
|
amount = models.DecimalField('Итого', max_digits=8, decimal_places=2, default=0) |
|
|
|
|
commission = models.DecimalField('Комиссия', max_digits=8, decimal_places=2, default=0) |
|
|
|
|
@ -55,6 +57,9 @@ class Payment(PolymorphicModel): |
|
|
|
|
verbose_name = 'Платеж' |
|
|
|
|
verbose_name_plural = 'Платежи' |
|
|
|
|
|
|
|
|
|
def calc_commission(self): |
|
|
|
|
return self.amount * config.SERVICE_COMMISSION / 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CoursePayment(Payment): |
|
|
|
|
course = models.ForeignKey(Course, on_delete=models.CASCADE, verbose_name='Курс') |
|
|
|
|
@ -72,9 +77,11 @@ class CoursePayment(Payment): |
|
|
|
|
author=self.course.author, |
|
|
|
|
amount=self.amount, |
|
|
|
|
payment=self, |
|
|
|
|
commission=self.calc_commission(), |
|
|
|
|
) |
|
|
|
|
else: |
|
|
|
|
author_balance.amount = self.amount |
|
|
|
|
author_balance.commission = self.calc_commission() |
|
|
|
|
author_balance.save() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -96,11 +103,3 @@ class SchoolPayment(Payment): |
|
|
|
|
self.amount = month_price_sum |
|
|
|
|
super().save(*args, **kwargs) |
|
|
|
|
author_balance = getattr(self, 'authorbalance', None) |
|
|
|
|
if not author_balance: |
|
|
|
|
AuthorBalance.objects.create( |
|
|
|
|
amount=month_price_sum, |
|
|
|
|
payment=self, |
|
|
|
|
) |
|
|
|
|
else: |
|
|
|
|
author_balance.amount = self.amount |
|
|
|
|
author_balance.save() |
|
|
|
|
|