mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
Add atomic transaction in counters
This commit is contained in:
parent
1f3e186e27
commit
525d7e6709
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
{% block infos %}
|
{% block infos %}
|
||||||
<h3>{% trans %}User account{% endtrans %}</h3>
|
<h3>{% trans %}User account{% endtrans %}</h3>
|
||||||
|
<p>{% trans %}Amount: {% endtrans %}{{ customer.amount }} €</p>
|
||||||
<p>{{ customer.refillings.all() }}</p>
|
<p>{{ customer.refillings.all() }}</p>
|
||||||
<p>{{ customer.buyings.all() }}</p>
|
<p>{{ customer.buyings.all() }}</p>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -10,6 +10,7 @@ from django.utils import timezone
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.db import DataError, transaction
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@ -218,6 +219,7 @@ 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():
|
||||||
if self.is_barman_price():
|
if self.is_barman_price():
|
||||||
seller = self.customer.user
|
seller = self.customer.user
|
||||||
else:
|
else:
|
||||||
@ -230,6 +232,8 @@ class CounterClick(DetailView):
|
|||||||
uprice = p.special_selling_price
|
uprice = p.special_selling_price
|
||||||
else:
|
else:
|
||||||
uprice = p.selling_price
|
uprice = p.selling_price
|
||||||
|
if uprice * infos['qty'] > self.customer.amount:
|
||||||
|
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=seller, customer=self.customer)
|
||||||
|
Loading…
Reference in New Issue
Block a user