diff --git a/gestion/models.py b/gestion/models.py index d00a2f1..9d70830 100644 --- a/gestion/models.py +++ b/gestion/models.py @@ -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}, diff --git a/gestion/templates/gestion/manage.html b/gestion/templates/gestion/manage.html index 1319347..e0c4984 100644 --- a/gestion/templates/gestion/manage.html +++ b/gestion/templates/gestion/manage.html @@ -152,11 +152,11 @@ {% if forloop.counter|divisibleby:4 %} {% endif %} - {% endif %} {% endfor %} {% if not category.active_products|divisibleby:4 %} {% endif %} + {% endif %} {% endfor %} {% if menus %} Menus diff --git a/gestion/views.py b/gestion/views.py index 93e42d1..fe9d35f 100644 --- a/gestion/views.py +++ b/gestion/views.py @@ -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')