Fix some counter stuff

This commit is contained in:
Skia 2016-07-22 13:34:34 +02:00
parent 256651f580
commit 0ecb78a101
8 changed files with 79 additions and 71 deletions

View File

@ -95,6 +95,8 @@ class Counter(models.Model):
return self.name return self.name
def get_absolute_url(self): def get_absolute_url(self):
if self.type == "EBOUTIC":
return reverse('eboutic:main')
return reverse('counter:details', kwargs={'counter_id': self.id}) return reverse('counter:details', kwargs={'counter_id': self.id})
def can_be_edited_by(self, user): def can_be_edited_by(self, user):

View File

@ -10,8 +10,13 @@
<h3>{% trans %}Counter admin list{% endtrans %}</h3> <h3>{% trans %}Counter admin list{% endtrans %}</h3>
<ul> <ul>
{% for c in counter_list %} {% for c in counter_list %}
{% if c.type == "EBOUTIC" %}
<li><a href="{{ url('eboutic:main') }}">{{ c }}</a> -
<a href="{{ url('counter:admin', counter_id=c.id) }}">{% trans %}Edit{% endtrans %}</a></li>
{% else %}
<li><a href="{{ url('counter:details', counter_id=c.id) }}">{{ c }}</a> - <li><a href="{{ url('counter:details', counter_id=c.id) }}">{{ c }}</a> -
<a href="{{ url('counter:admin', counter_id=c.id) }}">{% trans %}Edit{% endtrans %}</a></li> <a href="{{ url('counter:admin', counter_id=c.id) }}">{% trans %}Edit{% endtrans %}</a></li>
{% endif %}
{% endfor %} {% endfor %}
</ul> </ul>
{% else %} {% else %}

View File

@ -9,11 +9,7 @@
{% endmacro %} {% endmacro %}
{% block content %} {% block content %}
<h3>{% trans %}Counter{% endtrans %}</h3> <h3>{% trans counter_name=counter %}{{ counter_name }} counter{% endtrans %}</h3>
<h4>{{ counter }}</h4>
<p><strong>{% trans %}Club: {% endtrans %}</strong> {{ counter.club }}</p>
<p><strong>{% trans %}Products: {% endtrans %}</strong> {{ counter.products.all() }}</p>
<div> <div>
<h3>{% trans %}Sellings{% endtrans %}</h3> <h3>{% trans %}Sellings{% endtrans %}</h3>

View File

@ -124,12 +124,20 @@ class CounterClick(DetailView):
self.object = self.get_object() self.object = self.get_object()
self.customer = Customer.objects.filter(user__id=self.kwargs['user_id']).first() self.customer = Customer.objects.filter(user__id=self.kwargs['user_id']).first()
self.refill_form = None self.refill_form = None
if len(Counter.get_barmen_list(self.object.id)) < 1: # Check that at least one barman is logged in if ((self.object.type != "BAR" and not request.user.is_authenticated()) or
(self.object.type == "BAR" and
len(Counter.get_barmen_list(self.object.id)) < 1)): # Check that at least one barman is logged in
return self.cancel(request) return self.cancel(request)
if 'basket' not in request.session.keys(): if 'basket' not in request.session.keys():
request.session['basket'] = {} request.session['basket'] = {}
request.session['basket_total'] = 0 request.session['basket_total'] = 0
request.session['not_enough'] = False request.session['not_enough'] = False
if self.object.type != "BAR":
self.operator = request.user
elif self.is_barman_price():
self.operator = self.customer.user
else:
self.operator = Counter.get_random_barman(self.object.id)
if 'add_product' in request.POST['action']: if 'add_product' in request.POST['action']:
self.add_product(request) self.add_product(request)
@ -147,7 +155,7 @@ class CounterClick(DetailView):
return self.render_to_response(context) return self.render_to_response(context)
def is_barman_price(self): def is_barman_price(self):
if self.customer.user.id in [s.id for s in Counter.get_barmen_list(self.object.id)]: if self.object.type == "BAR" and self.customer.user.id in [s.id for s in Counter.get_barmen_list(self.object.id)]:
return True return True
else: else:
return False return False
@ -210,7 +218,7 @@ class CounterClick(DetailView):
nb = 1 nb = 1
else: else:
nb = int(nb) nb = int(nb)
p = Product.objects.filter(code=code).first() p = self.object.products.filter(code=code).first()
if p is not None: if p is not None:
while nb > 0 and not self.add_product(request, nb, p.id): while nb > 0 and not self.add_product(request, nb, p.id):
nb -= 1 nb -= 1
@ -220,10 +228,6 @@ class CounterClick(DetailView):
def finish(self, request): def finish(self, request):
""" Finish the click session, and validate the basket """ """ Finish the click session, and validate the basket """
with transaction.atomic(): with transaction.atomic():
if self.is_barman_price():
seller = self.customer.user
else:
seller = Counter.get_random_barman(self.object.id)
request.session['last_basket'] = [] request.session['last_basket'] = []
for pid,infos in request.session['basket'].items(): for pid,infos in request.session['basket'].items():
# This duplicates code for DB optimization (prevent to load many times the same object) # This duplicates code for DB optimization (prevent to load many times the same object)
@ -236,7 +240,7 @@ class CounterClick(DetailView):
raise DataError(_("You have not enough money to buy all the basket")) raise DataError(_("You have not enough money to buy all the basket"))
request.session['last_basket'].append("%d x %s" % (infos['qty'], p.name)) request.session['last_basket'].append("%d x %s" % (infos['qty'], p.name))
s = Selling(product=p, counter=self.object, unit_price=uprice, s = Selling(product=p, counter=self.object, unit_price=uprice,
quantity=infos['qty'], seller=seller, customer=self.customer) quantity=infos['qty'], seller=self.operator, customer=self.customer)
s.save() s.save()
request.session['last_customer'] = self.customer.user.get_display_name() request.session['last_customer'] = self.customer.user.get_display_name()
request.session['last_total'] = "%0.2f" % self.sum_basket(request) request.session['last_total'] = "%0.2f" % self.sum_basket(request)
@ -256,14 +260,10 @@ class CounterClick(DetailView):
def refill(self, request): def refill(self, request):
"""Refill the customer's account""" """Refill the customer's account"""
if self.is_barman_price():
operator = self.customer.user
else:
operator = Counter.get_random_barman(self.object.id)
form = RefillForm(request.POST) form = RefillForm(request.POST)
if form.is_valid(): if form.is_valid():
form.instance.counter = self.object form.instance.counter = self.object
form.instance.operator = operator form.instance.operator = self.operator
form.instance.customer = self.customer form.instance.customer = self.customer
form.instance.save() form.instance.save()
else: else:

View File

@ -5,10 +5,6 @@ from accounting.models import CurrencyField
from counter.models import Counter, Product from counter.models import Counter, Product
from core.models import User from core.models import User
class Eboutic(Counter):
class Meta:
proxy = True
class Basket(models.Model): class Basket(models.Model):
""" """
Basket is built when the user validate its session basket and asks for payment Basket is built when the user validate its session basket and asks for payment

View File

@ -1,15 +1,14 @@
from django.shortcuts import render from django.shortcuts import render
from django.core.urlresolvers import reverse_lazy from django.core.urlresolvers import reverse_lazy
from eboutic.models import Eboutic
from django.views.generic import TemplateView, View from django.views.generic import TemplateView, View
from django.http import HttpResponse, HttpResponseRedirect from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render from django.shortcuts import render
from django.db import transaction, DataError from django.db import transaction, DataError
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from counter.models import Product, Customer from counter.models import Product, Customer, Counter
from eboutic.models import Basket, Invoice, Eboutic, BasketItem, InvoiceItem from eboutic.models import Basket, Invoice, BasketItem, InvoiceItem
# Create your views here. # Create your views here.
class EbouticMain(TemplateView): class EbouticMain(TemplateView):
@ -69,7 +68,7 @@ class EbouticMain(TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
kwargs = super(EbouticMain, self).get_context_data(**kwargs) kwargs = super(EbouticMain, self).get_context_data(**kwargs)
kwargs['basket_total'] = EbouticMain.sum_basket(self.request) kwargs['basket_total'] = EbouticMain.sum_basket(self.request)
kwargs['eboutic'] = Eboutic.objects.filter(type="EBOUTIC").first() kwargs['eboutic'] = Counter.objects.filter(type="EBOUTIC").first()
return kwargs return kwargs
class EbouticCommand(TemplateView): class EbouticCommand(TemplateView):

Binary file not shown.

View File

@ -6,7 +6,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-07-22 01:47+0200\n" "POT-Creation-Date: 2016-07-22 13:32+0200\n"
"PO-Revision-Date: 2016-07-18\n" "PO-Revision-Date: 2016-07-18\n"
"Last-Translator: Skia <skia@libskia.so>\n" "Last-Translator: Skia <skia@libskia.so>\n"
"Language-Team: AE info <ae.info@utbm.fr>\n" "Language-Team: AE info <ae.info@utbm.fr>\n"
@ -30,11 +30,11 @@ msgstr "IBAN"
msgid "account number" msgid "account number"
msgstr "numero de compte" msgstr "numero de compte"
#: accounting/models.py:92 club/models.py:109 counter/models.py:214 #: accounting/models.py:92 club/models.py:109 counter/models.py:216
msgid "start date" msgid "start date"
msgstr "date de début" msgstr "date de début"
#: accounting/models.py:93 club/models.py:110 counter/models.py:215 #: accounting/models.py:93 club/models.py:110 counter/models.py:217
msgid "end date" msgid "end date"
msgstr "date de fin" msgstr "date de fin"
@ -43,7 +43,7 @@ msgid "is closed"
msgstr "est fermé" msgstr "est fermé"
#: accounting/models.py:97 accounting/models.py:136 counter/models.py:21 #: accounting/models.py:97 accounting/models.py:136 counter/models.py:21
#: counter/models.py:162 #: counter/models.py:164
msgid "amount" msgid "amount"
msgstr "montant" msgstr "montant"
@ -55,8 +55,8 @@ msgstr "montant effectif"
msgid "number" msgid "number"
msgstr "numéro" msgstr "numéro"
#: accounting/models.py:137 core/models.py:462 counter/models.py:165 #: accounting/models.py:137 core/models.py:462 counter/models.py:167
#: counter/models.py:193 eboutic/models.py:17 eboutic/models.py:30 #: counter/models.py:195 eboutic/models.py:13 eboutic/models.py:26
msgid "date" msgid "date"
msgstr "date" msgstr "date"
@ -68,7 +68,7 @@ msgstr "intitulé"
msgid "remark" msgid "remark"
msgstr "remarque" msgstr "remarque"
#: accounting/models.py:140 counter/models.py:166 eboutic/models.py:32 #: accounting/models.py:140 counter/models.py:168 eboutic/models.py:28
#: subscription/models.py:34 #: subscription/models.py:34
msgid "payment method" msgid "payment method"
msgstr "méthode de paiement" msgstr "méthode de paiement"
@ -144,10 +144,11 @@ msgstr "Nouveau compte club"
#: accounting/templates/accounting/bank_account_list.jinja:15 #: accounting/templates/accounting/bank_account_list.jinja:15
#: accounting/templates/accounting/club_account_details.jinja:44 #: accounting/templates/accounting/club_account_details.jinja:44
#: accounting/templates/accounting/journal_details.jinja:51 #: accounting/templates/accounting/journal_details.jinja:51
#: club/templates/club/club_detail.jinja:7 core/templates/core/page.jinja:30 #: club/templates/club/club_detail.jinja:7 core/templates/core/page.jinja:31
#: core/templates/core/user_base.jinja:8 #: core/templates/core/user_base.jinja:8
#: core/templates/core/user_tools.jinja:30 #: core/templates/core/user_tools.jinja:30
#: counter/templates/counter/counter_list.jinja:14 #: counter/templates/counter/counter_list.jinja:15
#: counter/templates/counter/counter_list.jinja:18
msgid "Edit" msgid "Edit"
msgstr "Éditer" msgstr "Éditer"
@ -227,7 +228,7 @@ msgid "No"
msgstr "Non" msgstr "Non"
#: accounting/templates/accounting/club_account_details.jinja:43 #: accounting/templates/accounting/club_account_details.jinja:43
#: core/templates/core/page.jinja:27 #: core/templates/core/page.jinja:28
msgid "View" msgid "View"
msgstr "Voir" msgstr "Voir"
@ -304,7 +305,7 @@ msgstr "Adresse"
msgid "You can not make loops in clubs" msgid "You can not make loops in clubs"
msgstr "Vous ne pouvez pas faire de boucles dans les clubs" msgstr "Vous ne pouvez pas faire de boucles dans les clubs"
#: club/models.py:107 eboutic/models.py:16 eboutic/models.py:29 #: club/models.py:107 eboutic/models.py:12 eboutic/models.py:25
msgid "user" msgid "user"
msgstr "nom d'utilisateur" msgstr "nom d'utilisateur"
@ -342,7 +343,7 @@ msgstr "Club"
msgid "Back to list" msgid "Back to list"
msgstr "Retour à la liste" msgstr "Retour à la liste"
#: club/templates/club/club_detail.jinja:10 core/templates/core/page.jinja:33 #: club/templates/club/club_detail.jinja:10 core/templates/core/page.jinja:34
msgid "Prop" msgid "Prop"
msgstr "Propriétés" msgstr "Propriétés"
@ -545,14 +546,18 @@ msgid "Users"
msgstr "Utilisateurs" msgstr "Utilisateurs"
#: core/templates/core/base.jinja:30 #: core/templates/core/base.jinja:30
msgid "Wiki"
msgstr ""
#: core/templates/core/base.jinja:31
msgid "Pages" msgid "Pages"
msgstr "Pages" msgstr "Pages"
#: core/templates/core/base.jinja:31 #: core/templates/core/base.jinja:32
msgid "Clubs" msgid "Clubs"
msgstr "Clubs" msgstr "Clubs"
#: core/templates/core/base.jinja:44 #: core/templates/core/base.jinja:45
msgid "Site made by good people" msgid "Site made by good people"
msgstr "Site réalisé par des gens biens" msgstr "Site réalisé par des gens biens"
@ -624,7 +629,7 @@ msgid "Please login to see this page."
msgstr "Merci de vous identifier pour voir cette page." msgstr "Merci de vous identifier pour voir cette page."
#: core/templates/core/login.jinja:31 #: core/templates/core/login.jinja:31
#: counter/templates/counter/counter_main.jinja:52 #: counter/templates/counter/counter_main.jinja:48
msgid "login" msgid "login"
msgstr "login" msgstr "login"
@ -645,15 +650,15 @@ msgstr "Créer une page"
msgid "Not found" msgid "Not found"
msgstr "Non trouvé" msgstr "Non trouvé"
#: core/templates/core/page.jinja:28 #: core/templates/core/page.jinja:29
msgid "History" msgid "History"
msgstr "Historique" msgstr "Historique"
#: core/templates/core/page.jinja:43 #: core/templates/core/page.jinja:45
msgid "Page does not exist" msgid "Page does not exist"
msgstr "La page n'existe pas." msgstr "La page n'existe pas."
#: core/templates/core/page.jinja:45 #: core/templates/core/page.jinja:47
msgid "Create it?" msgid "Create it?"
msgstr "La créer ?" msgstr "La créer ?"
@ -669,6 +674,7 @@ msgid "Page history"
msgstr "Historique de la page" msgstr "Historique de la page"
#: core/templates/core/page_hist.jinja:5 #: core/templates/core/page_hist.jinja:5
#, python-format
msgid "You're seeing the history of page \"%(page_name)s\"" msgid "You're seeing the history of page \"%(page_name)s\""
msgstr "Vous consultez l'historique de la page \"%(page_name)s\"" msgstr "Vous consultez l'historique de la page \"%(page_name)s\""
@ -911,25 +917,23 @@ msgstr "Bureau"
msgid "Eboutic" msgid "Eboutic"
msgstr "Eboutic" msgstr "Eboutic"
#: counter/models.py:168 #: counter/models.py:170
msgid "bank" msgid "bank"
msgstr "banque" msgstr "banque"
#: counter/models.py:189 eboutic/models.py:55 #: counter/models.py:191 eboutic/models.py:51
msgid "unit price" msgid "unit price"
msgstr "prix unitaire" msgstr "prix unitaire"
#: counter/models.py:190 eboutic/models.py:56 #: counter/models.py:192 eboutic/models.py:52
msgid "quantity" msgid "quantity"
msgstr "quantité" msgstr "quantité"
#: counter/templates/counter/counter_click.jinja:20 #: counter/templates/counter/counter_click.jinja:20
#: counter/templates/counter/counter_main.jinja:12
msgid "Counter" msgid "Counter"
msgstr "Comptoir" msgstr "Comptoir"
#: counter/templates/counter/counter_click.jinja:22 #: counter/templates/counter/counter_click.jinja:22
#: counter/templates/counter/counter_main.jinja:14
msgid "Club: " msgid "Club: "
msgstr "Club : " msgstr "Club : "
@ -961,7 +965,7 @@ msgid "Basket: "
msgstr "Panier : " msgstr "Panier : "
#: counter/templates/counter/counter_click.jinja:58 #: counter/templates/counter/counter_click.jinja:58
#: counter/templates/counter/counter_main.jinja:28 #: counter/templates/counter/counter_main.jinja:24
#: eboutic/templates/eboutic/eboutic_main.jinja:31 #: eboutic/templates/eboutic/eboutic_main.jinja:31
msgid "Total: " msgid "Total: "
msgstr "Total : " msgstr "Total : "
@ -971,7 +975,6 @@ msgid "Finish"
msgstr "Terminer" msgstr "Terminer"
#: counter/templates/counter/counter_click.jinja:69 #: counter/templates/counter/counter_click.jinja:69
#: counter/templates/counter/counter_main.jinja:15
#: eboutic/templates/eboutic/eboutic_main.jinja:39 #: eboutic/templates/eboutic/eboutic_main.jinja:39
msgid "Products: " msgid "Products: "
msgstr "Produits : " msgstr "Produits : "
@ -989,39 +992,43 @@ msgstr "Liste des comptoirs"
msgid "New counter" msgid "New counter"
msgstr "Nouveau comptoir" msgstr "Nouveau comptoir"
#: counter/templates/counter/counter_list.jinja:18 #: counter/templates/counter/counter_list.jinja:23
msgid "There is no counters in this website." msgid "There is no counters in this website."
msgstr "Il n'y a pas de comptoirs dans ce site web." msgstr "Il n'y a pas de comptoirs dans ce site web."
#: counter/templates/counter/counter_main.jinja:19 #: counter/templates/counter/counter_main.jinja:12
msgid "%(counter_name)s counter"
msgstr "Comptoir %(counter_name)s"
#: counter/templates/counter/counter_main.jinja:15
msgid "Sellings" msgid "Sellings"
msgstr "Ventes" msgstr "Ventes"
#: counter/templates/counter/counter_main.jinja:21 #: counter/templates/counter/counter_main.jinja:17
msgid "Last selling: " msgid "Last selling: "
msgstr "Dernière vente : " msgstr "Dernière vente : "
#: counter/templates/counter/counter_main.jinja:22 #: counter/templates/counter/counter_main.jinja:18
msgid "Client: " msgid "Client: "
msgstr "Client : " msgstr "Client : "
#: counter/templates/counter/counter_main.jinja:22 #: counter/templates/counter/counter_main.jinja:18
msgid "New amount: " msgid "New amount: "
msgstr "Nouveau montant : " msgstr "Nouveau montant : "
#: counter/templates/counter/counter_main.jinja:31 #: counter/templates/counter/counter_main.jinja:27
msgid "Enter client code:" msgid "Enter client code:"
msgstr "Entrez un code client : " msgstr "Entrez un code client : "
#: counter/templates/counter/counter_main.jinja:35 #: counter/templates/counter/counter_main.jinja:31
msgid "validate" msgid "validate"
msgstr "valider" msgstr "valider"
#: counter/templates/counter/counter_main.jinja:38 #: counter/templates/counter/counter_main.jinja:34
msgid "Please, login" msgid "Please, login"
msgstr "Merci de vous identifier" msgstr "Merci de vous identifier"
#: counter/templates/counter/counter_main.jinja:43 #: counter/templates/counter/counter_main.jinja:39
msgid "Barman: " msgid "Barman: "
msgstr "Barman : " msgstr "Barman : "
@ -1034,43 +1041,43 @@ msgstr "Compte de %(user_name)s"
msgid "User account" msgid "User account"
msgstr "Compte utilisateur" msgstr "Compte utilisateur"
#: counter/views.py:200 #: counter/views.py:208
msgid "END" msgid "END"
msgstr "FIN" msgstr "FIN"
#: counter/views.py:202 #: counter/views.py:210
msgid "CAN" msgid "CAN"
msgstr "ANN" msgstr "ANN"
#: counter/views.py:236 #: counter/views.py:240
msgid "You have not enough money to buy all the basket" msgid "You have not enough money to buy all the basket"
msgstr "Vous n'avez pas assez d'argent pour acheter le panier" msgstr "Vous n'avez pas assez d'argent pour acheter le panier"
#: eboutic/models.py:31 sith/settings.py:231 sith/settings_sample.py:231 #: eboutic/models.py:27 sith/settings.py:231 sith/settings_sample.py:231
msgid "Credit card" msgid "Credit card"
msgstr "Carte banquaire" msgstr "Carte banquaire"
#: eboutic/models.py:31 #: eboutic/models.py:27
msgid "Sith account" msgid "Sith account"
msgstr "Compte utilisateur" msgstr "Compte utilisateur"
#: eboutic/models.py:33 #: eboutic/models.py:29
msgid "validated" msgid "validated"
msgstr "validé" msgstr "validé"
#: eboutic/models.py:44 #: eboutic/models.py:40
msgid "Invoice already validated" msgid "Invoice already validated"
msgstr "Facture déjà validée" msgstr "Facture déjà validée"
#: eboutic/models.py:54 #: eboutic/models.py:50
msgid "product name" msgid "product name"
msgstr "nom du produit" msgstr "nom du produit"
#: eboutic/models.py:65 #: eboutic/models.py:61
msgid "basket" msgid "basket"
msgstr "panier" msgstr "panier"
#: eboutic/models.py:68 #: eboutic/models.py:64
msgid "invoice" msgid "invoice"
msgstr "facture" msgstr "facture"
@ -1094,7 +1101,7 @@ msgstr "Le paiement a échoué"
msgid "Payment successful" msgid "Payment successful"
msgstr "Le paiement a été effectué" msgstr "Le paiement a été effectué"
#: eboutic/views.py:117 #: eboutic/views.py:116
msgid "You have not enough money to buy the basket" msgid "You have not enough money to buy the basket"
msgstr "Vous n'avez pas assez d'argent pour acheter le panier" msgstr "Vous n'avez pas assez d'argent pour acheter le panier"
@ -1203,6 +1210,9 @@ msgid "You must either choose an existing user or create a new one properly"
msgstr "" msgstr ""
"Vous devez soit choisir un utilisateur existant, ou en créer un proprement." "Vous devez soit choisir un utilisateur existant, ou en créer un proprement."
#~ msgid "%(c)s counter"
#~ msgstr "Comptoir %(c)s"
#~ msgid "Page" #~ msgid "Page"
#~ msgstr "Page" #~ msgstr "Page"