mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 11:59:23 +00:00
Translate datepicker and add age limit to products
This commit is contained in:
24
counter/migrations/0015_auto_20160820_0158.py
Normal file
24
counter/migrations/0015_auto_20160820_0158.py
Normal file
@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('counter', '0014_auto_20160819_1650'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='product',
|
||||
name='limit_age',
|
||||
field=models.IntegerField(default=0, verbose_name='limit age'),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='product',
|
||||
name='tray',
|
||||
field=models.BooleanField(default=False, verbose_name='tray price'),
|
||||
),
|
||||
]
|
@ -83,6 +83,8 @@ class Product(models.Model):
|
||||
special_selling_price = CurrencyField(_('special selling price'))
|
||||
icon = models.ImageField(upload_to='products', null=True, blank=True)
|
||||
club = models.ForeignKey(Club, related_name="products")
|
||||
limit_age = models.IntegerField(_('limit age'), default=0)
|
||||
tray = models.BooleanField(_('tray price'), default=False)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('product')
|
||||
|
@ -43,6 +43,9 @@
|
||||
{% endif %}
|
||||
<div>
|
||||
<h5>{% trans %}Selling{% endtrans %}</h5>
|
||||
{% if request.session['too_young'] %}
|
||||
<p><strong>{% trans %}Too young for that product{% endtrans %}</strong></p>
|
||||
{% endif %}
|
||||
{% if request.session['not_enough'] %}
|
||||
<p><strong>{% trans %}Not enough money{% endtrans %}</strong></p>
|
||||
{% endif %}
|
||||
|
@ -8,6 +8,10 @@
|
||||
</form>
|
||||
{% endmacro %}
|
||||
|
||||
{% block title %}
|
||||
{% trans counter_name=counter %}{{ counter_name }} counter{% endtrans %}
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h3>{% trans counter_name=counter %}{{ counter_name }} counter{% endtrans %}</h3>
|
||||
|
||||
|
@ -117,6 +117,7 @@ class CounterClick(DetailView):
|
||||
request.session['basket'] = {}
|
||||
request.session['basket_total'] = 0
|
||||
request.session['not_enough'] = False
|
||||
request.session['too_young'] = False
|
||||
self.refill_form = None
|
||||
ret = super(CounterClick, self).get(request, *args, **kwargs)
|
||||
if ((self.object.type != "BAR" and not request.user.is_authenticated()) or
|
||||
@ -138,6 +139,7 @@ class CounterClick(DetailView):
|
||||
request.session['basket'] = {}
|
||||
request.session['basket_total'] = 0
|
||||
request.session['not_enough'] = False
|
||||
request.session['too_young'] = False
|
||||
if self.object.type != "BAR":
|
||||
self.operator = request.user
|
||||
elif self.is_barman_price():
|
||||
@ -166,8 +168,11 @@ class CounterClick(DetailView):
|
||||
else:
|
||||
return False
|
||||
|
||||
def get_product(self, pid):
|
||||
return Product.objects.filter(pk=int(pid)).first()
|
||||
|
||||
def get_price(self, pid):
|
||||
p = Product.objects.filter(pk=pid).first()
|
||||
p = self.get_product(pid)
|
||||
if self.is_barman_price():
|
||||
price = p.special_selling_price
|
||||
else:
|
||||
@ -181,7 +186,11 @@ class CounterClick(DetailView):
|
||||
return total / 100
|
||||
|
||||
def add_product(self, request, q = 1, p=None):
|
||||
""" Add a product to the basket """
|
||||
"""
|
||||
Add a product to the basket
|
||||
q is the quantity passed as integer
|
||||
p is the product id, passed as an integer
|
||||
"""
|
||||
pid = p or request.POST['product_id']
|
||||
pid = str(pid)
|
||||
price = self.get_price(pid)
|
||||
@ -189,11 +198,15 @@ class CounterClick(DetailView):
|
||||
if self.customer.amount < (total + q*float(price)):
|
||||
request.session['not_enough'] = True
|
||||
return False
|
||||
if self.customer.user.get_age() < self.get_product(pid).limit_age:
|
||||
request.session['too_young'] = True
|
||||
return False
|
||||
if pid in request.session['basket']:
|
||||
request.session['basket'][pid]['qty'] += q
|
||||
else:
|
||||
request.session['basket'][pid] = {'qty': q, 'price': int(price*100)}
|
||||
request.session['not_enough'] = False # Reset not_enough to save the session
|
||||
request.session['too_young'] = False
|
||||
request.session.modified = True
|
||||
return True
|
||||
|
||||
@ -421,7 +434,7 @@ class ProductEditForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Product
|
||||
fields = ['name', 'description', 'product_type', 'code', 'purchase_price',
|
||||
'selling_price', 'special_selling_price', 'icon', 'club']
|
||||
'selling_price', 'special_selling_price', 'icon', 'club', 'limit_age', 'tray']
|
||||
counters = make_ajax_field(Product, 'counters', 'counters', show_help_text=False, label='Counters', help_text="Guy",
|
||||
required=False) # TODO FIXME
|
||||
|
||||
|
Reference in New Issue
Block a user