LIL-267, LIL-271. Update payment models

remotes/origin/hasaccess
Ivlev Denis 8 years ago
parent cbc013f238
commit 01b163d05d
  1. 1
      apps/payment/admin.py
  2. 25
      apps/payment/migrations/0005_auto_20180221_1120.py
  3. 29
      apps/payment/migrations/0006_auto_20180221_1126.py
  4. 36
      apps/payment/models.py
  5. 18
      apps/school/migrations/0004_auto_20180221_1120.py

@ -26,6 +26,7 @@ class PaymentChildAdmin(PolymorphicChildModelAdmin):
base_fieldsets = (
(None, {'fields': ('user', 'amount', 'status', 'data',)}),
)
readonly_fields = ('amount', 'status', 'data',)
@admin.register(CoursePayment)

@ -0,0 +1,25 @@
# Generated by Django 2.0.2 on 2018-02-21 11:20
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('payment', '0004_auto_20180221_1022'),
]
operations = [
migrations.AlterField(
model_name='authorbalance',
name='author',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='Автор'),
),
migrations.AlterField(
model_name='authorbalance',
name='payment',
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='payment.Payment', verbose_name='Платёж'),
),
]

@ -0,0 +1,29 @@
# Generated by Django 2.0.2 on 2018-02-21 11:26
import django.contrib.postgres.fields.jsonb
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('payment', '0005_auto_20180221_1120'),
]
operations = [
migrations.AlterField(
model_name='payment',
name='amount',
field=models.DecimalField(decimal_places=2, default=0, editable=False, max_digits=8, verbose_name='Итого'),
),
migrations.AlterField(
model_name='payment',
name='data',
field=django.contrib.postgres.fields.jsonb.JSONField(default={}, editable=False, verbose_name='Данные платежа от провайдера'),
),
migrations.AlterField(
model_name='payment',
name='status',
field=models.PositiveSmallIntegerField(choices=[(0, 'regular'), (1, 'goodwill'), (2, 'negative'), (200, 'risk under review'), (201, 'risk reviewed accepted'), (202, 'risk reviewed declined'), (203, 'risk authorization voided'), (12, 'subscription cancelation'), (13, 'subscription expired'), (14, 'subscription payment failed')], editable=False, null=True, verbose_name='Статус платежа'),
),
]

@ -21,12 +21,12 @@ class AuthorBalance(models.Model):
(1, 'Accepted'),
(2, 'Declined'),
)
author = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='Автор')
author = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='Автор', null=True, blank=True)
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)
status = models.PositiveSmallIntegerField('Статус', choices=STATUS_CHOICES, default=0)
payment = models.ForeignKey('Payment', on_delete=models.CASCADE, null=True, blank=True, verbose_name='Платёж')
payment = models.OneToOneField('Payment', on_delete=models.CASCADE, null=True, blank=True, verbose_name='Платёж')
class Payment(PolymorphicModel):
@ -43,9 +43,9 @@ class Payment(PolymorphicModel):
(Pingback.PINGBACK_TYPE_SUBSCRIPTION_PAYMENT_FAILED, 'subscription payment failed',),
)
user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='Пользователь')
amount = models.DecimalField('Итого', max_digits=8, decimal_places=2, default=0)
status = models.PositiveSmallIntegerField('Статус платежа', choices=PW_STATUS_CHOICES)
data = JSONField('Данные платежа от провайдера', default={})
amount = models.DecimalField('Итого', max_digits=8, decimal_places=2, default=0, editable=False)
status = models.PositiveSmallIntegerField('Статус платежа', choices=PW_STATUS_CHOICES, null=True, editable=False)
data = JSONField('Данные платежа от провайдера', default={}, editable=False)
class Meta:
verbose_name = 'Платеж'
@ -59,6 +59,17 @@ class CoursePayment(Payment):
verbose_name = 'Платеж за курс'
verbose_name_plural = 'Платежи за курсы'
def save(self, *args, **kwargs):
self.amount = self.course.price
super().save(*args, **kwargs)
author_balance = getattr(self, 'authorbalance', None)
if not author_balance:
AuthorBalance.objects.create(
author=self.course.author,
amount=self.amount,
payment=self,
)
class SchoolPayment(Payment):
weekdays = ArrayField(models.IntegerField(), size=7, verbose_name='Дни недели')
@ -68,3 +79,18 @@ class SchoolPayment(Payment):
class Meta:
verbose_name = 'Платеж за школу'
verbose_name_plural = 'Платежи за школу'
def save(self, *args, **kwargs):
month_price_sum = SchoolSchedule.objects.filter(
weekday__in=self.weekdays,
).aggregate(
models.Sum('month_price'),
).month_price_sum
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,
)

@ -0,0 +1,18 @@
# Generated by Django 2.0.2 on 2018-02-21 11:20
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('school', '0003_auto_20180221_0901'),
]
operations = [
migrations.AlterField(
model_name='schoolschedule',
name='weekday',
field=models.PositiveSmallIntegerField(choices=[(1, 'понедельник'), (2, 'вторник'), (3, 'среда'), (4, 'четверг'), (5, 'пятница'), (6, 'суббота'), (7, 'воскресенье')], unique=True, verbose_name='День недели'),
),
]
Loading…
Cancel
Save