parent
6cc64636be
commit
aff22391a1
6 changed files with 71 additions and 9 deletions
@ -0,0 +1,34 @@ |
|||||||
|
from decimal import Decimal |
||||||
|
from django.core.management.base import BaseCommand |
||||||
|
from django.db.models import F |
||||||
|
|
||||||
|
from apps.payment.models import Payment, AuthorBalance, UserBonus |
||||||
|
from apps.user.models import User |
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand): |
||||||
|
help = 'Fix payment and author balance amount based on payment.data.effective_price_amount' |
||||||
|
|
||||||
|
def add_arguments(self, parser): |
||||||
|
parser.add_argument( |
||||||
|
'action_name', type=str, |
||||||
|
help='Name of action', |
||||||
|
) |
||||||
|
parser.add_argument( |
||||||
|
'amount', type=int, |
||||||
|
help='Bonuses amount', |
||||||
|
) |
||||||
|
|
||||||
|
def handle(self, *args, **options): |
||||||
|
action_name = options.get('action_name') |
||||||
|
amount = options.get('amount') |
||||||
|
|
||||||
|
excluded_users = UserBonus.objects.filter(is_service=True, action_name=action_name).values_list('user_id', flat=True) |
||||||
|
for user in User.objects.filter(role=User.USER_ROLE, is_active=True).exclude( |
||||||
|
id__in=excluded_users).values_list('id', flat=True): |
||||||
|
UserBonus.objects.create(user_id=user, amount=amount, is_service=True, action_name=action_name) |
||||||
|
print('%d bonuses was sent to user %d in action %s' % (amount, user, action_name)) |
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,23 @@ |
|||||||
|
# Generated by Django 2.0.7 on 2018-12-11 17:31 |
||||||
|
|
||||||
|
from django.db import migrations, models |
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration): |
||||||
|
|
||||||
|
dependencies = [ |
||||||
|
('payment', '0028_add_gift_certificates'), |
||||||
|
] |
||||||
|
|
||||||
|
operations = [ |
||||||
|
migrations.AddField( |
||||||
|
model_name='userbonus', |
||||||
|
name='action_name', |
||||||
|
field=models.CharField(blank=True, default='', max_length=10), |
||||||
|
), |
||||||
|
migrations.AddField( |
||||||
|
model_name='userbonus', |
||||||
|
name='is_service', |
||||||
|
field=models.BooleanField(default=False), |
||||||
|
), |
||||||
|
] |
||||||
Loading…
Reference in new issue