Merge branch 'feature/LIL-713' into 'master'

Feature/lil 713

See merge request lilcity/backend!225
remotes/origin/editis_13-01-19
cfwme 7 years ago
commit f5378c41c4
  1. 34
      apps/payment/management/commands/give_bonuses.py
  2. 23
      apps/payment/migrations/0029_auto_20181211_1731.py
  3. 2
      apps/payment/models.py
  4. 4
      apps/user/models.py
  5. 12
      apps/user/templates/user/bonus-history.html
  6. 5
      apps/user/views.py

@ -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),
),
]

@ -308,6 +308,8 @@ class UserBonus(models.Model):
payment = models.ForeignKey(Payment, on_delete=models.SET_NULL, null=True)
referral = models.ForeignKey('user.Referral', on_delete=models.SET_NULL, null=True)
created_at = models.DateTimeField(auto_now_add=True)
is_service = models.BooleanField(default=False)
action_name = models.CharField(max_length=10, blank=True, default='')
class Meta:
ordering = ('created_at',)

@ -1,5 +1,6 @@
from json import dumps
from django.db.models import Q
from django.utils.functional import cached_property
from rest_framework.authtoken.models import Token
from phonenumber_field.modelfields import PhoneNumberField
@ -123,8 +124,7 @@ class User(AbstractUser):
def bonus(self):
from apps.payment.models import Payment
return int(self.bonuses.filter(
payment__isnull=False,
payment__status__in=Payment.PW_PAID_STATUSES,
Q(payment__isnull=False, payment__status__in=Payment.PW_PAID_STATUSES) | Q(is_service=True),
).aggregate(models.Sum('amount')).get('amount__sum') or 0)

@ -53,14 +53,18 @@
<div class="transactions__cell transactions__product">Подарочный сертификат</div>
{% else %}
<div class="transactions__cell transactions__product">
{% if request.user_agent.is_mobile %}
Школа. {% if payment.date_start and payment.date_end %}{{ payment.date_start|date:"j b" }} - {{ payment.date_end|date:"j b" }}{% endif %}
{% if payment %}
{% if request.user_agent.is_mobile %}
Школа. {% if payment.date_start and payment.date_end %}{{ payment.date_start|date:"j b" }} - {{ payment.date_end|date:"j b" }}{% endif %}
{% else %}
Школа. {% if payment.date_start and payment.date_end %}{{ payment.date_start }} - {{ payment.date_end }}{% endif %}
{% endif %}
{% else %}
Школа. {% if payment.date_start and payment.date_end %}{{ payment.date_start }} - {{ payment.date_end }}{% endif %}
{% if bonus.action_name %}Зачисление по акции{% endif %}
{% endif %}
</div>
{% endif %}
<div class="transactions__cell transactions__amount">{{payment.amount }}</div>
<div class="transactions__cell transactions__amount">{% if payment %}{{payment.amount }}{% endif %}</div>
<div class="transactions__cell transactions__user">
{% if bonus.referral %}{{ bonus.referral.referral.get_full_name }}{% endif %}
</div>

@ -14,7 +14,7 @@ from django.views.generic import DetailView, UpdateView, TemplateView, FormView
from django.contrib import messages
from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import login_required
from django.db.models import F, Func, Sum, Min, Max
from django.db.models import F, Func, Sum, Min, Max, Q
from django.urls import reverse_lazy
from django.utils.decorators import method_decorator
from django.utils.timezone import now
@ -303,8 +303,7 @@ class BonusHistoryView(TemplateView):
config = Config.load()
context = self.get_context_data(**kwargs)
context['bonuses'] = request.user.bonuses.filter(
payment__isnull=False,
payment__status__in=Payment.PW_PAID_STATUSES,
Q(payment__isnull=False, payment__status__in=Payment.PW_PAID_STATUSES) | Q(is_service=True),
)
context['referrer_url'] = 'https://%s%s?referrer=%s' % (
settings.MAIN_HOST, reverse('index'), short_url.encode_url(request.user.id)

Loading…
Cancel
Save