parent
0e35330cb3
commit
d0b8fa1dd0
3 changed files with 60 additions and 2 deletions
@ -0,0 +1,52 @@ |
|||||||
|
# Generated by Django 2.0.7 on 2019-07-02 12:33 |
||||||
|
|
||||||
|
from django.db import migrations |
||||||
|
from paymentwall import Pingback |
||||||
|
|
||||||
|
|
||||||
|
def add_bonuses(apps, schema_editor): |
||||||
|
def paid_one_more(user): |
||||||
|
payments_cnt = SchoolPayment.objects.filter(status__in=PW_PAID_STATUSES, user=user, |
||||||
|
add_days=False).count() |
||||||
|
if payments_cnt > 1: |
||||||
|
return True |
||||||
|
payments_cnt += CoursePayment.objects.filter(status__in=PW_PAID_STATUSES, user=user).count() |
||||||
|
if payments_cnt > 1: |
||||||
|
return True |
||||||
|
payments_cnt += DrawingCampPayment.objects.filter(status__in=PW_PAID_STATUSES, user=user).count() |
||||||
|
return payments_cnt > 1 |
||||||
|
|
||||||
|
User = apps.get_model('user', 'User') |
||||||
|
UserBonus = apps.get_model('payment', 'UserBonus') |
||||||
|
Payment = apps.get_model('payment', 'Payment') |
||||||
|
SchoolPayment = apps.get_model('payment', 'SchoolPayment') |
||||||
|
CoursePayment = apps.get_model('payment', 'CoursePayment') |
||||||
|
DrawingCampPayment = apps.get_model('payment', 'DrawingCampPayment') |
||||||
|
ACTION_PAID_ONE_MORE = 'paid_one_more' |
||||||
|
AMOUNT_PAID_ONE_MORE = 100 |
||||||
|
PW_PAID_STATUSES = [ |
||||||
|
Pingback.PINGBACK_TYPE_REGULAR, |
||||||
|
Pingback.PINGBACK_TYPE_GOODWILL, |
||||||
|
Pingback.PINGBACK_TYPE_RISK_REVIEWED_ACCEPTED, |
||||||
|
] |
||||||
|
users = set(Payment.objects.filter(status__in=PW_PAID_STATUSES).values_list('user_id', flat=True)) |
||||||
|
|
||||||
|
exclude_users = set(UserBonus.objects.filter(is_service=True, action_name=ACTION_PAID_ONE_MORE, |
||||||
|
user_id__in=users).values_list('user_id', flat=True)) |
||||||
|
|
||||||
|
for user in User.objects.filter(id__in=users - exclude_users): |
||||||
|
if paid_one_more(user): |
||||||
|
print('email', user.email) |
||||||
|
UserBonus.objects.create(user=user, amount=AMOUNT_PAID_ONE_MORE, is_service=True, |
||||||
|
action_name=ACTION_PAID_ONE_MORE) |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('payment', '0036_drawingcamppayment'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.RunPython(add_bonuses), |
||||||
|
] |
||||||
Loading…
Reference in new issue