Commit 01c39919 authored by Skia's avatar Skia

Add cash register summaries

parent 9927310f
Pipeline #142 failed with stage
in 2 minutes and 17 seconds
......@@ -10,4 +10,5 @@ admin.site.register(Counter)
admin.site.register(Refilling)
admin.site.register(Selling)
admin.site.register(Permanency)
admin.site.register(CashRegisterSummary)
......@@ -287,7 +287,39 @@ class Permanency(models.Model):
verbose_name = _("permanency")
def __str__(self):
return "%s in %s from %s to %s" % (self.user, self.counter,
self.start.strftime("%Y-%m-%d %H:%M:%S"), self.end.strftime("%Y-%m-%d %H:%M:%S"))
return "%s in %s from %s" % (self.user, self.counter,
self.start.strftime("%Y-%m-%d %H:%M:%S"))
class CashRegisterSummary(models.Model):
user = models.ForeignKey(User, related_name="cash_summaries", verbose_name=_("user"))
counter = models.ForeignKey(Counter, related_name="cash_summaries", verbose_name=_("counter"))
date = models.DateTimeField(_('date'))
comment = models.TextField(_('comment'), null=True, blank=True)
emptied = models.BooleanField(_('emptied'), default=False)
class Meta:
verbose_name = _("cash register summary")
def __str__(self):
return "At %s by %s - Total: %s €" % (self.counter, self.user, self.get_total())
def get_total(self):
t = 0
for it in self.items.all():
t += it.quantity * it.value
return t
def save(self, *args, **kwargs):
if not self.id:
self.date = timezone.now()
return super(CashRegisterSummary, self).save(*args, **kwargs)
class CashRegisterSummaryItem(models.Model):
cash_summary = models.ForeignKey(CashRegisterSummary, related_name="items", verbose_name=_("cash summary"))
value = CurrencyField(_("value"))
quantity = models.IntegerField(_('quantity'), default=0)
check = models.BooleanField(_('check'), default=False)
class Meta:
verbose_name = _("cash register summary item")
{% extends "core/base.jinja" %}
{% block title %}
{% trans obj=object %}Edit {{ obj }}{% endtrans %}
{% endblock %}
{% block content %}
<h2>{% trans %}Make a cash register summary{% endtrans %}</h2>
<form action="" method="post" id="cash_summary_form">
{% csrf_token %}
{% for field in form %}
<p>
{% if field.name[:5] == "check" and field.name[8:] == "value" %}
{% set name = field.name[:7] + "_quantity" %}
{{ field.errors }}<label for="{{ field.name }}">{{ field.label }}</label> {{ field }}
{{ form[name].errors }}<label for="{{ form[name].name }}">{{ form[name].label }}</label> {{ form[name] }}
{% elif field.name[:5] != "check" %}
{{ field.errors }}<label for="{{ field.name }}">{{ field.label }}</label> {{ field }}
{% endif %}
</p>
{% endfor %}
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
</form>
{% endblock %}
......@@ -2,16 +2,16 @@
{% from "core/macros.jinja" import user_mini_profile %}
{% macro add_product(id, content) %}
<form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}" class="form_button">
{% macro add_product(id, content, class="") %}
<form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}" class="{{ class }}">
{% csrf_token %}
<input type="hidden" name="action" value="add_product">
<button type="submit" name="product_id" value="{{ id }}"> {{ content|safe }} </button>
</form>
{% endmacro %}
{% macro del_product(id, content) %}
<form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}" class="form_button">
{% macro del_product(id, content, class="") %}
<form method="post" action="{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}" class="{{ class }}">
{% csrf_token %}
<input type="hidden" name="action" value="del_product">
<button type="submit" name="product_id" value="{{ id }}"> {{ content }} </button>
......@@ -53,7 +53,7 @@
{% for id,infos in request.session['basket']|dictsort %}
{% set product = counter.products.filter(id=id).first() %}
{% set s = infos['qty'] * infos['price'] / 100 %}
<li>{{ del_product(id, '-') }} {{ infos['qty'] + infos['bonus_qty'] }} {{ add_product(id, '+') }}
<li>{{ del_product(id, '-', "inline") }} {{ infos['qty'] + infos['bonus_qty'] }} {{ add_product(id, '+', "inline") }}
{{ product.name }}: {{ "%0.2f"|format(s) }}
{% if infos['bonus_qty'] %}
P
......@@ -105,7 +105,7 @@
{% set file = static('core/img/na.gif') %}
{% endif %}
{% set prod = '<strong>%s</strong><hr><img src="%s" /><span>%s €<br>%s</span>' % (p.name, file, p.selling_price, p.code) %}
{{ add_product(p.id, prod) }}
{{ add_product(p.id, prod, "form_button") }}
{%- endfor %}
</div>
{%- endif -%}
......
{% extends "core/base.jinja" %}
{% block title %}
{% trans obj=object %}Edit {{ obj }}{% endtrans %}
{% endblock %}
{% block content %}
<h2>{% trans obj=object %}Edit {{ obj }}{% endtrans %}</h2>
<form action="" method="post">
{% csrf_token %}
<p>{{ form.sellers.errors }}<label for="{{ form.sellers.name }}">{{ form.sellers.label }}</label> {{ form.sellers }}</p>
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
<p>{{ form.products.errors }}<label for="{{ form.products.name }}">{{ form.products.label }}</label> {{ form.products }}</p>
<p><input type="submit" value="{% trans %}Save{% endtrans %}" /></p>
</form>
{% endblock %}
......@@ -39,13 +39,14 @@
{% endif %}
</div>
{% if counter.type == 'BAR' %}
{% if barmen %}
<p><a href="{{ url('counter:cash_summary', counter_id=counter.id) }}">{% trans %}Make a cash register summary{% endtrans %}</a></p>
{% endif %}
<div>
<h3>{% trans %}Barman: {% endtrans %}</h3>
<ul>
{% for b in barmen %}
<li>{{ barman_logout_link(b) }}</li>
<p>{{ barman_logout_link(b) }}</p>
{% endfor %}
</ul>
<form method="post" action="{{ url('counter:login', counter_id=counter.id) }}">
{% csrf_token %}
{{ login_form.as_p() }}
......
......@@ -5,6 +5,7 @@ from counter.views import *
urlpatterns = [
url(r'^(?P<counter_id>[0-9]+)$', CounterMain.as_view(), name='details'),
url(r'^(?P<counter_id>[0-9]+)/click/(?P<user_id>[0-9]+)$', CounterClick.as_view(), name='click'),
url(r'^(?P<counter_id>[0-9]+)/cash_summary$', CounterCashSummaryView.as_view(), name='cash_summary'),
url(r'^(?P<counter_id>[0-9]+)/login$', CounterLogin.as_view(), name='login'),
url(r'^(?P<counter_id>[0-9]+)/logout$', CounterLogout.as_view(), name='logout'),
url(r'^admin/(?P<counter_id>[0-9]+)$', CounterEditView.as_view(), name='admin'),
......
......@@ -529,3 +529,96 @@ class SellingDeleteView(CanEditPropMixin, DeleteView):
def get_success_url(self):
return reverse_lazy('core:user_account', kwargs={'user_id': self.object.customer.user.id})
# Cash register summaries
class CashRegisterSummaryForm(forms.Form):
"""
Provide the cash summary form
"""
ten_cents = forms.IntegerField(label=_("10 cents"), required=False)
twenty_cents = forms.IntegerField(label=_("20 cents"), required=False)
fifty_cents = forms.IntegerField(label=_("50 cents"), required=False)
one_euro = forms.IntegerField(label=_("1 euro"), required=False)
two_euros = forms.IntegerField(label=_("2 euros"), required=False)
five_euros = forms.IntegerField(label=_("5 euros"), required=False)
ten_euros = forms.IntegerField(label=_("10 euros"), required=False)
twenty_euros = forms.IntegerField(label=_("20 euros"), required=False)
fifty_euros = forms.IntegerField(label=_("50 euros"), required=False)
hundred_euros = forms.IntegerField(label=_("100 euros"), required=False)
check_1_value = forms.DecimalField(label=_("Check amount"), required=False)
check_1_quantity = forms.IntegerField(label=_("Check quantity"), required=False)
check_2_value = forms.DecimalField(label=_("Check amount"), required=False)
check_2_quantity = forms.IntegerField(label=_("Check quantity"), required=False)
check_3_value = forms.DecimalField(label=_("Check amount"), required=False)
check_3_quantity = forms.IntegerField(label=_("Check quantity"), required=False)
check_4_value = forms.DecimalField(label=_("Check amount"), required=False)
check_4_quantity = forms.IntegerField(label=_("Check quantity"), required=False)
check_5_value = forms.DecimalField(label=_("Check amount"), required=False)
check_5_quantity = forms.IntegerField(label=_("Check quantity"), required=False)
comment = forms.CharField(label=_("Comment"), required=False)
emptied = forms.BooleanField(label=_("Emptied"), required=False)
def save(self, counter):
cd = self.cleaned_data
summary = CashRegisterSummary(
counter=counter,
user=counter.get_random_barman(),
comment=cd['comment'],
emptied=cd['emptied'],
)
summary.save()
# Cash
if cd['ten_cents']: CashRegisterSummaryItem(cash_summary=summary, value=0.1, quantity=cd['ten_cents']).save()
if cd['twenty_cents']: CashRegisterSummaryItem(cash_summary=summary, value=0.2, quantity=cd['twenty_cents']).save()
if cd['fifty_cents']: CashRegisterSummaryItem(cash_summary=summary, value=0.5, quantity=cd['fifty_cents']).save()
if cd['one_euro']: CashRegisterSummaryItem(cash_summary=summary, value=1, quantity=cd['one_euro']).save()
if cd['two_euros']: CashRegisterSummaryItem(cash_summary=summary, value=2, quantity=cd['two_euros']).save()
if cd['five_euros']: CashRegisterSummaryItem(cash_summary=summary, value=5, quantity=cd['five_euros']).save()
if cd['ten_euros']: CashRegisterSummaryItem(cash_summary=summary, value=10, quantity=cd['ten_euros']).save()
if cd['twenty_euros']: CashRegisterSummaryItem(cash_summary=summary, value=20, quantity=cd['twenty_euros']).save()
if cd['fifty_euros']: CashRegisterSummaryItem(cash_summary=summary, value=50, quantity=cd['fifty_euros']).save()
if cd['hundred_euros']: CashRegisterSummaryItem(cash_summary=summary, value=100, quantity=cd['hundred_euros']).save()
# Checks
if cd['check_1_quantity']: CashRegisterSummaryItem(cash_summary=summary, value=cd['check_1_value'], quantity=cd['check_1_quantity']).save()
if cd['check_2_quantity']: CashRegisterSummaryItem(cash_summary=summary, value=cd['check_2_value'], quantity=cd['check_2_quantity']).save()
if cd['check_3_quantity']: CashRegisterSummaryItem(cash_summary=summary, value=cd['check_3_value'], quantity=cd['check_3_quantity']).save()
if cd['check_4_quantity']: CashRegisterSummaryItem(cash_summary=summary, value=cd['check_4_value'], quantity=cd['check_4_quantity']).save()
if cd['check_5_quantity']: CashRegisterSummaryItem(cash_summary=summary, value=cd['check_5_value'], quantity=cd['check_5_quantity']).save()
if summary.items.count() < 1:
summary.delete()
class CounterCashSummaryView(CanViewMixin, DetailView):
"""
Provide the cash summary form
"""
model = Counter
pk_url_kwarg = "counter_id"
template_name = 'counter/cash_register_summary.jinja'
def get(self, request, *args, **kwargs):
self.object = self.get_object()
if len(self.object.get_barmen_list()) < 1:
return HttpResponseRedirect(reverse_lazy('counter:details', args=self.args,
kwargs={'counter_id': self.object.id}))
self.form = CashRegisterSummaryForm()
return super(CounterCashSummaryView, self).get(request, *args, **kwargs)
def post(self, request, *args, **kwargs):
self.object = self.get_object()
if len(self.object.get_barmen_list()) < 1:
return HttpResponseRedirect(reverse_lazy('counter:details', args=self.args,
kwargs={'counter_id': self.object.id}))
self.form = CashRegisterSummaryForm(request.POST)
if self.form.is_valid():
self.form.save(self.object)
return HttpResponseRedirect(self.get_success_url())
return super(CounterCashSummaryView, self).get(request, *args, **kwargs)
def get_success_url(self):
return reverse_lazy('counter:details', kwargs={'counter_id': self.object.id})
def get_context_data(self, **kwargs):
""" Add form to the context """
kwargs = super(CounterCashSummaryView, self).get_context_data(**kwargs)
kwargs['form'] = self.form
return kwargs
This diff is collapsed.
......@@ -636,6 +636,7 @@ def migrate_counter():
user=user,
counter=counter,
start=r['logged_time'].replace(tzinfo=timezone('Europe/Paris')),
activity=r['logged_time'].replace(tzinfo=timezone('Europe/Paris')),
end=r['closed_time'].replace(tzinfo=timezone('Europe/Paris')),
)
new.save()
......
  • Salut, est-ce que je peux rajouter une confirmation avant l'envoi du relevé de caisse ? Le BdF en aurait besoin pour éviter d'avoir 12 relevés envoyés par erreur parce qu'il y a des ... gens sans doute très gentils qui appuient sur Entrée sans faire exprès pendant la saisie... :P

  • Quel étrange endroit pour poser cette question, mais oui, tu peux, je voulais déjà le faire depuis un moment, mais j'ai jamais pris le temps, donc fonce! :)

Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment