mirror of
https://github.com/nanoy42/coope
synced 2024-12-23 23:43:47 +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.
|
||||
"""
|
||||
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:
|
||||
verbose_name = "Produit"
|
||||
|
||||
name = models.CharField(max_length=40, verbose_name="Nom", unique=True)
|
||||
"""
|
||||
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
|
||||
"""
|
||||
draft_category = models.IntegerField(choices=DRAFT_TYPES, default=DRAFT_NONE, verbose_name="Type de pression")
|
||||
history = HistoricalRecords()
|
||||
|
||||
def __str__(self):
|
||||
|
@ -110,7 +124,7 @@ class Product(models.Model):
|
|||
|
||||
def isPinte(id):
|
||||
product = Product.objects.get(id=id)
|
||||
if product.category != Product.P_PRESSION:
|
||||
if product.draft_category != Product.DRAFT_PINTE:
|
||||
raise ValidationError(
|
||||
('%(product)s n\'est pas une pinte'),
|
||||
params={'product': product},
|
||||
|
@ -119,7 +133,7 @@ def isPinte(id):
|
|||
|
||||
def isDemi(id):
|
||||
product = Product.objects.get(id=id)
|
||||
if product.category != Product.D_PRESSION:
|
||||
if product.draft_category != Product.DRAFT_DEMI:
|
||||
raise ValidationError(
|
||||
('%(product)s n\'est pas un demi'),
|
||||
params={'product': product},
|
||||
|
@ -127,7 +141,7 @@ def isDemi(id):
|
|||
|
||||
def isGalopin(id):
|
||||
product = Product.objects.get(id=id)
|
||||
if product.category != Product.G_PRESSION:
|
||||
if product.draft_category != Product.DRAFT_GALOPIN:
|
||||
raise ValidationError(
|
||||
('%(product)s n\'est pas un galopin'),
|
||||
params={'product': product},
|
||||
|
|
|
@ -152,11 +152,11 @@
|
|||
{% if forloop.counter|divisibleby:4 %}
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if not category.active_products|divisibleby:4 %}
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% if menus %}
|
||||
<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:
|
||||
product = get_object_or_404(Product, pk=o["pk"])
|
||||
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)
|
||||
if(not keg.is_active):
|
||||
raise Exception("Fût non actif")
|
||||
|
@ -138,7 +138,7 @@ def order(request):
|
|||
kegHistory.quantitySold += Decimal(quantity * 0.5)
|
||||
kegHistory.amountSold += Decimal(quantity * product.amount)
|
||||
kegHistory.save()
|
||||
elif(product.category == Product.D_PRESSION):
|
||||
elif(product.draft_category == Product.DRAFT_DEMI):
|
||||
keg = get_object_or_404(Keg, demi=product)
|
||||
if(not keg.is_active):
|
||||
raise Exception("Fût non actif")
|
||||
|
@ -146,7 +146,7 @@ def order(request):
|
|||
kegHistory.quantitySold += Decimal(quantity * 0.25)
|
||||
kegHistory.amountSold += Decimal(quantity * product.amount)
|
||||
kegHistory.save()
|
||||
elif(product.category == Product.G_PRESSION):
|
||||
elif(product.draft_category == Product.DRAFT_GALOPIN):
|
||||
keg = get_object_or_404(Keg, galopin=product)
|
||||
if(not keg.is_active):
|
||||
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.
|
||||
"""
|
||||
product = Product.objects.get(pk=pk)
|
||||
if product.category == Product.P_PRESSION:
|
||||
if product.category == Product.DRAFT_PINTE:
|
||||
nb_pintes = 1
|
||||
else:
|
||||
nb_pintes = 0
|
||||
|
@ -691,7 +691,7 @@ def get_menu(request, pk):
|
|||
menu = get_object_or_404(Menu, pk=pk)
|
||||
nb_pintes = 0
|
||||
for article in menu.articles:
|
||||
if article.category == Product.P_PRESSION:
|
||||
if article.category == Product.DRAFT_PINTE:
|
||||
nb_pintes +=1
|
||||
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')
|
||||
|
|
Loading…
Reference in a new issue