mirror of
https://github.com/nanoy42/coope
synced 2025-01-25 17:44:21 +00:00
Fix categories
This commit is contained in:
parent
6792c0e099
commit
6e00a4658b
3 changed files with 23 additions and 9 deletions
|
@ -31,8 +31,21 @@ class Product(models.Model):
|
||||||
"""
|
"""
|
||||||
Stores a product.
|
Stores a product.
|
||||||
"""
|
"""
|
||||||
|
DRAFT_NONE = 0
|
||||||
|
DRAFT_PINTE = 1
|
||||||
|
DRAFT_DEMI = 2
|
||||||
|
DRAFT_GALOPIN = 3
|
||||||
|
|
||||||
|
DRAFT_TYPES = (
|
||||||
|
(DRAFT_NONE, "Pas une bière pression"),
|
||||||
|
(DRAFT_PINTE, "Pinte"),
|
||||||
|
(DRAFT_DEMI, "Demi"),
|
||||||
|
(DRAFT_GALOPIN, "Galopin"),
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = "Produit"
|
verbose_name = "Produit"
|
||||||
|
|
||||||
name = models.CharField(max_length=40, verbose_name="Nom", unique=True)
|
name = models.CharField(max_length=40, verbose_name="Nom", unique=True)
|
||||||
"""
|
"""
|
||||||
The name of the product.
|
The name of the product.
|
||||||
|
@ -81,6 +94,7 @@ class Product(models.Model):
|
||||||
"""
|
"""
|
||||||
On the graphs on :func:`users.views.profile` view, the number of total consumptions is divised by the showingMultiplier
|
On the graphs on :func:`users.views.profile` view, the number of total consumptions is divised by the showingMultiplier
|
||||||
"""
|
"""
|
||||||
|
draft_category = models.IntegerField(choices=DRAFT_TYPES, default=DRAFT_NONE, verbose_name="Type de pression")
|
||||||
history = HistoricalRecords()
|
history = HistoricalRecords()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -110,7 +124,7 @@ class Product(models.Model):
|
||||||
|
|
||||||
def isPinte(id):
|
def isPinte(id):
|
||||||
product = Product.objects.get(id=id)
|
product = Product.objects.get(id=id)
|
||||||
if product.category != Product.P_PRESSION:
|
if product.draft_category != Product.DRAFT_PINTE:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
('%(product)s n\'est pas une pinte'),
|
('%(product)s n\'est pas une pinte'),
|
||||||
params={'product': product},
|
params={'product': product},
|
||||||
|
@ -119,7 +133,7 @@ def isPinte(id):
|
||||||
|
|
||||||
def isDemi(id):
|
def isDemi(id):
|
||||||
product = Product.objects.get(id=id)
|
product = Product.objects.get(id=id)
|
||||||
if product.category != Product.D_PRESSION:
|
if product.draft_category != Product.DRAFT_DEMI:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
('%(product)s n\'est pas un demi'),
|
('%(product)s n\'est pas un demi'),
|
||||||
params={'product': product},
|
params={'product': product},
|
||||||
|
@ -127,7 +141,7 @@ def isDemi(id):
|
||||||
|
|
||||||
def isGalopin(id):
|
def isGalopin(id):
|
||||||
product = Product.objects.get(id=id)
|
product = Product.objects.get(id=id)
|
||||||
if product.category != Product.G_PRESSION:
|
if product.draft_category != Product.DRAFT_GALOPIN:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
('%(product)s n\'est pas un galopin'),
|
('%(product)s n\'est pas un galopin'),
|
||||||
params={'product': product},
|
params={'product': product},
|
||||||
|
|
|
@ -152,11 +152,11 @@
|
||||||
{% if forloop.counter|divisibleby:4 %}
|
{% if forloop.counter|divisibleby:4 %}
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if not category.active_products|divisibleby:4 %}
|
{% if not category.active_products|divisibleby:4 %}
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% if menus %}
|
{% if menus %}
|
||||||
<tr style="text-align:center; font-weight:bold;"><td colspan="4">Menus</td></tr>
|
<tr style="text-align:center; font-weight:bold;"><td colspan="4">Menus</td></tr>
|
||||||
|
|
|
@ -130,7 +130,7 @@ def order(request):
|
||||||
for o in order:
|
for o in order:
|
||||||
product = get_object_or_404(Product, pk=o["pk"])
|
product = get_object_or_404(Product, pk=o["pk"])
|
||||||
quantity = int(o["quantity"])
|
quantity = int(o["quantity"])
|
||||||
if(product.category == Product.P_PRESSION):
|
if(product.draft_category == Product.DRAFT_PINTE):
|
||||||
keg = get_object_or_404(Keg, pinte=product)
|
keg = get_object_or_404(Keg, pinte=product)
|
||||||
if(not keg.is_active):
|
if(not keg.is_active):
|
||||||
raise Exception("Fût non actif")
|
raise Exception("Fût non actif")
|
||||||
|
@ -138,7 +138,7 @@ def order(request):
|
||||||
kegHistory.quantitySold += Decimal(quantity * 0.5)
|
kegHistory.quantitySold += Decimal(quantity * 0.5)
|
||||||
kegHistory.amountSold += Decimal(quantity * product.amount)
|
kegHistory.amountSold += Decimal(quantity * product.amount)
|
||||||
kegHistory.save()
|
kegHistory.save()
|
||||||
elif(product.category == Product.D_PRESSION):
|
elif(product.draft_category == Product.DRAFT_DEMI):
|
||||||
keg = get_object_or_404(Keg, demi=product)
|
keg = get_object_or_404(Keg, demi=product)
|
||||||
if(not keg.is_active):
|
if(not keg.is_active):
|
||||||
raise Exception("Fût non actif")
|
raise Exception("Fût non actif")
|
||||||
|
@ -146,7 +146,7 @@ def order(request):
|
||||||
kegHistory.quantitySold += Decimal(quantity * 0.25)
|
kegHistory.quantitySold += Decimal(quantity * 0.25)
|
||||||
kegHistory.amountSold += Decimal(quantity * product.amount)
|
kegHistory.amountSold += Decimal(quantity * product.amount)
|
||||||
kegHistory.save()
|
kegHistory.save()
|
||||||
elif(product.category == Product.G_PRESSION):
|
elif(product.draft_category == Product.DRAFT_GALOPIN):
|
||||||
keg = get_object_or_404(Keg, galopin=product)
|
keg = get_object_or_404(Keg, galopin=product)
|
||||||
if(not keg.is_active):
|
if(not keg.is_active):
|
||||||
raise Exception("Fût non actif")
|
raise Exception("Fût non actif")
|
||||||
|
@ -392,7 +392,7 @@ def getProduct(request, pk):
|
||||||
The primary key of the :class:`gestion.models.Product` to get infos.
|
The primary key of the :class:`gestion.models.Product` to get infos.
|
||||||
"""
|
"""
|
||||||
product = Product.objects.get(pk=pk)
|
product = Product.objects.get(pk=pk)
|
||||||
if product.category == Product.P_PRESSION:
|
if product.category == Product.DRAFT_PINTE:
|
||||||
nb_pintes = 1
|
nb_pintes = 1
|
||||||
else:
|
else:
|
||||||
nb_pintes = 0
|
nb_pintes = 0
|
||||||
|
@ -691,7 +691,7 @@ def get_menu(request, pk):
|
||||||
menu = get_object_or_404(Menu, pk=pk)
|
menu = get_object_or_404(Menu, pk=pk)
|
||||||
nb_pintes = 0
|
nb_pintes = 0
|
||||||
for article in menu.articles:
|
for article in menu.articles:
|
||||||
if article.category == Product.P_PRESSION:
|
if article.category == Product.DRAFT_PINTE:
|
||||||
nb_pintes +=1
|
nb_pintes +=1
|
||||||
data = json.dumps({"pk": menu.pk, "barcode" : menu.barcode, "name": menu.name, "amount" : menu.amount, "needQuantityButton": False, "nb_pintes": nb_pintes})
|
data = json.dumps({"pk": menu.pk, "barcode" : menu.barcode, "name": menu.name, "amount" : menu.amount, "needQuantityButton": False, "nb_pintes": nb_pintes})
|
||||||
return HttpResponse(data, content_type='application/json')
|
return HttpResponse(data, content_type='application/json')
|
||||||
|
|
Loading…
Add table
Reference in a new issue