mirror of
https://github.com/nanoy42/coope
synced 2024-11-22 19:33:11 +00:00
Implement price computing
This commit is contained in:
parent
94715e4f99
commit
55e5efa38a
5 changed files with 32 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
||||||
import math
|
import math
|
||||||
|
|
||||||
def compute_price(price, a, b, c, alpha):
|
def compute_price(price, a, b, c, alpha):
|
||||||
if price < a:
|
if price < alpha:
|
||||||
return price * (a + b * math.exp(-c/(price-alpha)**2))
|
return float(price) * (1 + float(a) + float(b) * math.exp(-c/(price-alpha)**2))
|
||||||
else:
|
else:
|
||||||
return price * a
|
return price * (1 + a)
|
||||||
|
|
|
@ -5,7 +5,7 @@ from django.contrib.auth.models import User
|
||||||
from dal import autocomplete
|
from dal import autocomplete
|
||||||
|
|
||||||
from .models import Reload, Refund, Product, Keg, Menu, Category
|
from .models import Reload, Refund, Product, Keg, Menu, Category
|
||||||
from preferences.models import PaymentMethod
|
from preferences.models import PaymentMethod, PriceProfile
|
||||||
|
|
||||||
class ReloadForm(forms.ModelForm):
|
class ReloadForm(forms.ModelForm):
|
||||||
"""
|
"""
|
||||||
|
@ -137,3 +137,10 @@ class GenerateInvoiceForm(forms.Form):
|
||||||
client_address_fisrt_line = forms.CharField(label="Première ligne d'adresse")
|
client_address_fisrt_line = forms.CharField(label="Première ligne d'adresse")
|
||||||
client_address_second_line = forms.CharField(label="Deuxième 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")
|
|
@ -55,4 +55,5 @@ urlpatterns = [
|
||||||
path('stats', views.stats, name="stats"),
|
path('stats', views.stats, name="stats"),
|
||||||
path('divide', views.divide, name="divide"),
|
path('divide', views.divide, name="divide"),
|
||||||
path('gen_invoice', views.gen_invoice, name="gen_invoice"),
|
path('gen_invoice', views.gen_invoice, name="gen_invoice"),
|
||||||
|
path('compute-price', views.compute_price_view, name="compute-price"),
|
||||||
]
|
]
|
|
@ -14,13 +14,15 @@ from datetime import datetime, timedelta
|
||||||
|
|
||||||
from django_tex.views import render_to_pdf
|
from django_tex.views import render_to_pdf
|
||||||
from coopeV3.acl import active_required, acl_or, admin_required
|
from coopeV3.acl import active_required, acl_or, admin_required
|
||||||
|
from coopeV3.utils import compute_price
|
||||||
|
|
||||||
import simplejson as json
|
import simplejson as json
|
||||||
from dal import autocomplete
|
from dal import autocomplete
|
||||||
from decimal import *
|
from decimal import *
|
||||||
import os
|
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 .models import Product, Menu, Keg, ConsumptionHistory, KegHistory, Consumption, MenuHistory, Pinte, Reload, Refund, Category
|
||||||
from users.models import School
|
from users.models import School
|
||||||
from preferences.models import PaymentMethod, GeneralPreferences, Cotisation, DivideHistory
|
from preferences.models import PaymentMethod, GeneralPreferences, Cotisation, DivideHistory
|
||||||
|
@ -1065,3 +1067,15 @@ def stats(request):
|
||||||
"payment_methods": payment_methods,
|
"payment_methods": payment_methods,
|
||||||
"cotisations": cotisations,
|
"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})
|
|
@ -61,6 +61,9 @@
|
||||||
<span class="tabulation2">
|
<span class="tabulation2">
|
||||||
<i class="fa fa-search-dollar"></i> <a href="{% url 'preferences:priceProfilesIndex' %}">Profils de prix</a>
|
<i class="fa fa-search-dollar"></i> <a href="{% url 'preferences:priceProfilesIndex' %}">Profils de prix</a>
|
||||||
</span>
|
</span>
|
||||||
|
<span class="tabulation2">
|
||||||
|
<i class="fa fa-search-dollar"></i> <a href="{% url 'gestion:compute-price' %}">Calcul de prix</a>
|
||||||
|
</span>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<span class="tabulation2">
|
<span class="tabulation2">
|
||||||
<i class="fa fa-bed"></i> <a href="{% url 'users:logout' %}">Deconnexion</a>
|
<i class="fa fa-bed"></i> <a href="{% url 'users:logout' %}">Deconnexion</a>
|
||||||
|
|
Loading…
Reference in a new issue