This commit is contained in:
Hugo LEVY-FALK 2018-12-14 20:25:20 +01:00
parent 14883ab6e9
commit 9598fe2299
3 changed files with 123 additions and 55 deletions

View file

@ -4,6 +4,7 @@
<h2>{{ account.firstname}} {{ account.lastname }}</h2> <h2>{{ account.firstname}} {{ account.lastname }}</h2>
<a class="button" href="{% url 'reset' account.pk %}">Remettre le solde à 0</a> <a class="button" href="{% url 'reset' account.pk %}">Remettre le solde à 0</a>
<a class="button" href="{% url 'refill' account.pk %}">Recharger le compte</a> <a class="button" href="{% url 'refill' account.pk %}">Recharger le compte</a>
<a class="button" href="{% url 'pay' account.pk %}">Imprimer</a>
<br/> <br/>
<br/> <br/>
<h3>Ventes</h3> <h3>Ventes</h3>

View file

@ -12,12 +12,12 @@
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" /> <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<link rel="stylesheet" href="{% static 'css/main.css' %}" /> <link rel="stylesheet" href="{% static 'css/main.css' %}" />
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css" integrity="sha384-gfdkjb5BdAXd+lj+gudLWI+BXq4IuLW5IT+brZEZsLFm++aCMlF1V92rMkPaX4PP" crossorigin="anonymous"> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css" integrity="sha384-gfdkjb5BdAXd+lj+gudLWI+BXq4IuLW5IT+brZEZsLFm++aCMlF1V92rMkPaX4PP" crossorigin="anonymous">
<style> <style>
td, th { td, th {
border: 1px solid #ddd; border: 1px solid #ddd;
padding: 8px; padding: 8px;
} }
-
tr:nth-child(even){background-color: #f2f2f2;} tr:nth-child(even){background-color: #f2f2f2;}
tr:hover {background-color: #ddd;} tr:hover {background-color: #ddd;}
@ -29,7 +29,27 @@ th {
background-color: #b1ddab; background-color: #b1ddab;
color: white; color: white;
} }
</style>
.messages li {
list-style-type: none;
padding: 10px;
border-radius: 10px;
}
.messages .success {
background-color: #b1ddab;
color: white;
}
.messages .warning {
background-color: #f7db7e;
}
.messages .error {
background-color: #f7947e;
color: white;
}
</style>
</head> </head>
<body class="homepage is-preload"> <body class="homepage is-preload">
<div id="page-wrapper"> <div id="page-wrapper">
@ -55,6 +75,17 @@ th {
<!-- Main --> <!-- Main -->
<section id="main"> <section id="main">
<div class="container"> <div class="container">
<div class="col-12">
{% if messages %}
<ul class="messages">
{% for message in messages %}
<li{% if message.tags %} class="{{ message.tags }}"{% endif %}>
{{ message }}
</li>
{% endfor %}
</ul>
{% endif %}
</div>
<div class="row gtr-200"> <div class="row gtr-200">
<div class="col-2"></div> <div class="col-2"></div>
<div class="col-8"> <div class="col-8">

View file

@ -5,6 +5,7 @@ from django.shortcuts import (
) )
from django.urls import reverse from django.urls import reverse
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib import messages
from .models import Account, Sale, Article from .models import Account, Sale, Article
from .forms import SaleForm, ChooseArticleForm, AccountForm, SearchForm, ArticleForm from .forms import SaleForm, ChooseArticleForm, AccountForm, SearchForm, ArticleForm
@ -22,6 +23,14 @@ def refill_balance(request, pk):
account.calc_balance() account.calc_balance()
bal = account.balance bal = account.balance
account.save() account.save()
messages.success(
request,
"Le solde de {} {} a été rechargé de {}".format(
account.firstname,
account.lastname,
sale.price
)
)
return redirect(reverse('account', args=[account.pk,])) return redirect(reverse('account', args=[account.pk,]))
return render( return render(
@ -42,10 +51,17 @@ def pay(request, pk):
if form.is_valid(): if form.is_valid():
sale = form.to_sale() sale = form.to_sale()
if float(sale.price + account.balance) >= 0:
sale.account = account sale.account = account
sale.save() sale.save()
account.calc_balance() account.calc_balance()
account.save() account.save()
messages.success(
request,
"Paiement de {}€ réalisé avec succès.".format(sale.price)
)
else:
messages.error(request, "Solde trop bas pour l'opération")
return redirect(reverse('account', args=[account.pk,])) return redirect(reverse('account', args=[account.pk,]))
return render( return render(
@ -72,8 +88,16 @@ def reset_balance(request, pk):
sale.save() sale.save()
account.calc_balance() account.calc_balance()
account.save() account.save()
messages.success(
request,
"Remise à zéro du solde réussie."
)
return redirect(reverse('account', args=[account.pk,])) return redirect(reverse('account', args=[account.pk,]))
elif account.balance is 0: elif float(account.balance) == 0:
messages.warning(
request,
"Le solde est déjà nul."
)
return redirect(reverse('account', args=[account.pk,])) return redirect(reverse('account', args=[account.pk,]))
return render( return render(
@ -92,6 +116,10 @@ def create_account(request):
if form.is_valid(): if form.is_valid():
account = form.save() account = form.save()
messages.success(
request,
"Le compte a été créé."
)
return redirect(reverse('account', args=[account.pk,])) return redirect(reverse('account', args=[account.pk,]))
return render( return render(
@ -139,6 +167,10 @@ def article(request, pk):
form = ArticleForm(request.POST or None, instance=article) form = ArticleForm(request.POST or None, instance=article)
if form.is_valid(): if form.is_valid():
form.save() form.save()
messages.success(
request,
"L'article a été modifié."
)
return redirect(reverse('list-articles')) return redirect(reverse('list-articles'))
return render( return render(
request, request,
@ -155,6 +187,10 @@ def new_article(request):
form = ArticleForm(request.POST or None) form = ArticleForm(request.POST or None)
if form.is_valid(): if form.is_valid():
form.save() form.save()
messages.success(
request,
"L'article a été créé."
)
return redirect(reverse('list-articles')) return redirect(reverse('list-articles'))
return render( return render(
request, request,