mirror of
https://github.com/nanoy42/coope
synced 2024-11-25 22:22:27 +00:00
Merge branch 'optimise_rank' into dev
This commit is contained in:
commit
88561613fb
6 changed files with 62 additions and 24 deletions
|
@ -38,6 +38,7 @@ INSTALLED_APPS = [
|
||||||
'dal_select2',
|
'dal_select2',
|
||||||
'simple_history',
|
'simple_history',
|
||||||
'django_tex',
|
'django_tex',
|
||||||
|
'debug_toolbar'
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
@ -50,6 +51,7 @@ MIDDLEWARE = [
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
'simple_history.middleware.HistoryRequestMiddleware',
|
'simple_history.middleware.HistoryRequestMiddleware',
|
||||||
'django.contrib.admindocs.middleware.XViewMiddleware',
|
'django.contrib.admindocs.middleware.XViewMiddleware',
|
||||||
|
'debug_toolbar.middleware.DebugToolbarMiddleware',
|
||||||
]
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'coopeV3.urls'
|
ROOT_URLCONF = 'coopeV3.urls'
|
||||||
|
@ -127,3 +129,4 @@ LOGIN_URL = '/users/login'
|
||||||
MEDIA_ROOT = os.path.join(BASE_DIR, 'mediafiles')
|
MEDIA_ROOT = os.path.join(BASE_DIR, 'mediafiles')
|
||||||
MEDIA_URL = '/media/'
|
MEDIA_URL = '/media/'
|
||||||
|
|
||||||
|
INTERNAL_IPS = ["127.0.0.1"]
|
|
@ -30,3 +30,10 @@ urlpatterns = [
|
||||||
path('gestion/', include('gestion.urls')),
|
path('gestion/', include('gestion.urls')),
|
||||||
path('preferences/', include('preferences.urls')),
|
path('preferences/', include('preferences.urls')),
|
||||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||||
|
|
||||||
|
|
||||||
|
if settings.DEBUG:
|
||||||
|
import debug_toolbar
|
||||||
|
urlpatterns = [
|
||||||
|
path('__debug__/', include(debug_toolbar.urls)),
|
||||||
|
] + urlpatterns
|
||||||
|
|
|
@ -60,10 +60,10 @@
|
||||||
{% for customer in bestDrinkers %}
|
{% for customer in bestDrinkers %}
|
||||||
<tr>
|
<tr>
|
||||||
<th>{{ forloop.counter }}</th>
|
<th>{{ forloop.counter }}</th>
|
||||||
<th><a href="{% url 'users:profile' customer.0.pk %}">{{ customer.0.username }}</a></th>
|
<th><a href="{% url 'users:profile' customer.pk %}">{{ customer.username }}</a></th>
|
||||||
<th>{{ customer.1 }}</th>
|
<th>{{ customer.profile.alcohol }}</th>
|
||||||
</tr>
|
</tr>
|
||||||
{%endfor%}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -163,6 +163,7 @@ def order(request):
|
||||||
consumption.save()
|
consumption.save()
|
||||||
ch = ConsumptionHistory(customer=user, quantity=quantity, paymentMethod=paymentMethod, product=product, amount=Decimal(quantity*product.amount), coopeman=request.user)
|
ch = ConsumptionHistory(customer=user, quantity=quantity, paymentMethod=paymentMethod, product=product, amount=Decimal(quantity*product.amount), coopeman=request.user)
|
||||||
ch.save()
|
ch.save()
|
||||||
|
user.profile.alcohol += Decimal(quantity * float(product.deg) * product.volume * 0.79 /10 /1000)
|
||||||
if(paymentMethod.affect_balance):
|
if(paymentMethod.affect_balance):
|
||||||
if(user.profile.balance >= Decimal(product.amount*quantity)):
|
if(user.profile.balance >= Decimal(product.amount*quantity)):
|
||||||
user.profile.debit += Decimal(product.amount*quantity)
|
user.profile.debit += Decimal(product.amount*quantity)
|
||||||
|
@ -187,11 +188,10 @@ def order(request):
|
||||||
if(article.stockHold > 0):
|
if(article.stockHold > 0):
|
||||||
article.stockHold -= 1
|
article.stockHold -= 1
|
||||||
article.save()
|
article.save()
|
||||||
|
user.profile.alcohol += Decimal(quantity * float(product.deg) * product.volume * 0.79 /10 /1000)
|
||||||
user.save()
|
user.save()
|
||||||
return HttpResponse("La commande a bien été effectuée")
|
return HttpResponse("La commande a bien été effectuée")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
|
||||||
print("test")
|
|
||||||
return HttpResponse(error_message)
|
return HttpResponse(error_message)
|
||||||
|
|
||||||
@active_required
|
@active_required
|
||||||
|
@ -274,7 +274,8 @@ def cancel_consumption(request, pk):
|
||||||
user = consumption.customer
|
user = consumption.customer
|
||||||
if consumption.paymentMethod.affect_balance:
|
if consumption.paymentMethod.affect_balance:
|
||||||
user.profile.debit -= consumption.amount
|
user.profile.debit -= consumption.amount
|
||||||
user.save()
|
user.profile.alcohol -= Decimal(consumption.quantity * float(consumption.product.deg) * consumption.product.volume * 0.79 /10 /1000)
|
||||||
|
user.save()
|
||||||
consumptionT = Consumption.objects.get(customer=user, product=consumption.product)
|
consumptionT = Consumption.objects.get(customer=user, product=consumption.product)
|
||||||
consumptionT.quantity -= consumption.quantity
|
consumptionT.quantity -= consumption.quantity
|
||||||
consumptionT.save()
|
consumptionT.save()
|
||||||
|
@ -301,6 +302,8 @@ def cancel_menu(request, pk):
|
||||||
consumptionT = Consumption.objects.get(customer=user, product=product)
|
consumptionT = Consumption.objects.get(customer=user, product=product)
|
||||||
consumptionT -= menu_history.quantity
|
consumptionT -= menu_history.quantity
|
||||||
consumptionT.save()
|
consumptionT.save()
|
||||||
|
user.profile.alcohol -= Decimal(menu_history.quantity * float(menu_history.product.deg) * menu_history.product.volume * 0.79 /10 /1000)
|
||||||
|
user.save()
|
||||||
menu_history.delete()
|
menu_history.delete()
|
||||||
messages.success(request, "La consommation du menu a bien été annulée")
|
messages.success(request, "La consommation du menu a bien été annulée")
|
||||||
return redirect(reverse('users:profile', kwargs={'pk': user.pk}))
|
return redirect(reverse('users:profile', kwargs={'pk': user.pk}))
|
||||||
|
@ -715,12 +718,7 @@ def ranking(request):
|
||||||
Displays the ranking page.
|
Displays the ranking page.
|
||||||
"""
|
"""
|
||||||
bestBuyers = User.objects.order_by('-profile__debit')[:25]
|
bestBuyers = User.objects.order_by('-profile__debit')[:25]
|
||||||
customers = User.objects.all()
|
bestDrinkers = User.objects.order_by('-profile__alcohol')[:25]
|
||||||
list = []
|
|
||||||
for customer in customers:
|
|
||||||
alcohol = customer.profile.alcohol
|
|
||||||
list.append([customer, alcohol])
|
|
||||||
bestDrinkers = sorted(list, key=lambda x: x[1], reverse=True)[:25]
|
|
||||||
form = SearchProductForm(request.POST or None)
|
form = SearchProductForm(request.POST or None)
|
||||||
if(form.is_valid()):
|
if(form.is_valid()):
|
||||||
product_ranking = form.cleaned_data['product'].ranking
|
product_ranking = form.cleaned_data['product'].ranking
|
||||||
|
|
38
users/migrations/0006_auto_20190611_0105.py
Normal file
38
users/migrations/0006_auto_20190611_0105.py
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
# Generated by Django 2.1 on 2019-06-10 23:05
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
def update(apps, schema_editor):
|
||||||
|
db_alias = schema_editor.connection.alias
|
||||||
|
users = apps.get_model('auth', 'User').objects.using(db_alias).all()
|
||||||
|
for user in users:
|
||||||
|
consumptions = apps.get_model('gestion', 'ConsumptionHistory').objects.using(db_alias).filter(customer=user).select_related('product')
|
||||||
|
alcohol = 0
|
||||||
|
for consumption in consumptions:
|
||||||
|
product = consumption.product
|
||||||
|
alcohol += consumption.quantity * float(product.deg) * product.volume * 0.79 /10 /1000
|
||||||
|
user.profile.alcohol = alcohol
|
||||||
|
user.profile.save()
|
||||||
|
|
||||||
|
def reverse_update(apps, schema_editor):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('users', '0005_auto_20190227_0859'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='historicalprofile',
|
||||||
|
name='alcohol',
|
||||||
|
field=models.DecimalField(decimal_places=2, default=0, max_digits=5, null=True),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='profile',
|
||||||
|
name='alcohol',
|
||||||
|
field=models.DecimalField(decimal_places=2, default=0, max_digits=5, null=True),
|
||||||
|
),
|
||||||
|
migrations.RunPython(update, reverse_update)
|
||||||
|
]
|
|
@ -120,6 +120,10 @@ class Profile(models.Model):
|
||||||
"""
|
"""
|
||||||
Date of end of cotisation for the client
|
Date of end of cotisation for the client
|
||||||
"""
|
"""
|
||||||
|
alcohol = models.DecimalField(max_digits=5, decimal_places=2, default=0, null=True)
|
||||||
|
"""
|
||||||
|
Ingerated alcohol
|
||||||
|
"""
|
||||||
history = HistoricalRecords()
|
history = HistoricalRecords()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -152,18 +156,6 @@ class Profile(models.Model):
|
||||||
"""
|
"""
|
||||||
return Profile.objects.filter(debit__gte=self.debit).count()
|
return Profile.objects.filter(debit__gte=self.debit).count()
|
||||||
|
|
||||||
@property
|
|
||||||
def alcohol(self):
|
|
||||||
"""
|
|
||||||
Computes ingerated alcohol.
|
|
||||||
"""
|
|
||||||
consumptions = ConsumptionHistory.objects.filter(customer=self.user).select_related('product')
|
|
||||||
alcohol = 0
|
|
||||||
for consumption in consumptions:
|
|
||||||
product = consumption.product
|
|
||||||
alcohol += consumption.quantity * float(product.deg) * product.volume * 0.79 /10 /1000
|
|
||||||
return alcohol
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def nb_pintes(self):
|
def nb_pintes(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in a new issue