3
0
Fork 0
mirror of https://github.com/nanoy42/coope synced 2024-05-08 02:02:23 +00:00

Implement price computing

This commit is contained in:
Yoann Pétri 2019-06-23 15:31:55 +02:00
parent 94715e4f99
commit 55e5efa38a
5 changed files with 32 additions and 7 deletions

View file

@ -1,7 +1,7 @@
import math
def compute_price(price, a, b, c, alpha):
if price < a:
return price * (a + b * math.exp(-c/(price-alpha)**2))
if price < alpha:
return float(price) * (1 + float(a) + float(b) * math.exp(-c/(price-alpha)**2))
else:
return price * a
return price * (1 + a)

View file

@ -5,7 +5,7 @@ from django.contrib.auth.models import User
from dal import autocomplete
from .models import Reload, Refund, Product, Keg, Menu, Category
from preferences.models import PaymentMethod
from preferences.models import PaymentMethod, PriceProfile
class ReloadForm(forms.ModelForm):
"""
@ -136,4 +136,11 @@ class GenerateInvoiceForm(forms.Form):
client_name = forms.CharField(label="Nom du client")
client_address_fisrt_line = forms.CharField(label="Première ligne d'adresse")
client_address_second_line = forms.CharField(label="Deuxième ligne d'adresse")
products = forms.CharField(widget=forms.Textarea, label="Produits", help_text="Au format nom;prix;quantité avec saut de ligne")
products = forms.CharField(widget=forms.Textarea, label="Produits", help_text="Au format nom;prix;quantité avec saut de ligne")
class ComputePriceForm(forms.Form):
"""
A form to compute price
"""
price_profile = forms.ModelChoiceField(queryset=PriceProfile.objects.all(), label="Profil de prix")
price = forms.DecimalField(max_digits=10, decimal_places=5, label="Prix")

View file

@ -55,4 +55,5 @@ urlpatterns = [
path('stats', views.stats, name="stats"),
path('divide', views.divide, name="divide"),
path('gen_invoice', views.gen_invoice, name="gen_invoice"),
path('compute-price', views.compute_price_view, name="compute-price"),
]

View file

@ -14,13 +14,15 @@ from datetime import datetime, timedelta
from django_tex.views import render_to_pdf
from coopeV3.acl import active_required, acl_or, admin_required
from coopeV3.utils import compute_price
import simplejson as json
from dal import autocomplete
from decimal import *
import os
from math import floor, ceil
from .forms import ReloadForm, RefundForm, ProductForm, KegForm, MenuForm, GestionForm, SearchMenuForm, SearchProductForm, SelectPositiveKegForm, SelectActiveKegForm, PinteForm, GenerateReleveForm, CategoryForm, SearchCategoryForm, GenerateInvoiceForm
from .forms import ReloadForm, RefundForm, ProductForm, KegForm, MenuForm, GestionForm, SearchMenuForm, SearchProductForm, SelectPositiveKegForm, SelectActiveKegForm, PinteForm, GenerateReleveForm, CategoryForm, SearchCategoryForm, GenerateInvoiceForm, ComputePriceForm
from .models import Product, Menu, Keg, ConsumptionHistory, KegHistory, Consumption, MenuHistory, Pinte, Reload, Refund, Category
from users.models import School
from preferences.models import PaymentMethod, GeneralPreferences, Cotisation, DivideHistory
@ -1064,4 +1066,16 @@ def stats(request):
"menus": menus,
"payment_methods": payment_methods,
"cotisations": cotisations,
})
})
########## Compute price ##########
def compute_price_view(request):
form = ComputePriceForm(request.POST or None)
if form.is_valid():
price_profile = form.cleaned_data["price_profile"]
price = compute_price(form.cleaned_data["price"], price_profile.a, price_profile.b, price_profile.c, price_profile.alpha)
form_p = "Le prix est " + str(ceil(100*price)/100) + " € (arrondi au centième) ou " + str(ceil(10*price)/10) + " € (arrondi au dixième)."
else:
form_p = ""
return render(request, "form.html", {"form": form, "form_title": "Calcul d'un prix", "form_button": "Calculer", "form_icon": "search_dollar", "form_p": form_p})

View file

@ -61,6 +61,9 @@
<span class="tabulation2">
<i class="fa fa-search-dollar"></i> <a href="{% url 'preferences:priceProfilesIndex' %}">Profils de prix</a>
</span>
<span class="tabulation2">
<i class="fa fa-search-dollar"></i> <a href="{% url 'gestion:compute-price' %}">Calcul de prix</a>
</span>
{% endif %}
<span class="tabulation2">
<i class="fa fa-bed"></i> <a href="{% url 'users:logout' %}">Deconnexion</a>