From a2685cde7625771c4a9bcf1228b70e5aa4ef6e9d Mon Sep 17 00:00:00 2001 From: Niklas Brachmann Date: Mon, 9 Sep 2013 20:40:25 +0200 Subject: [PATCH] Renamed 'deleted' flag for products to 'active' and added checks for it; also removed unnescessary whitespace --- cash/admin.py | 9 +++++---- cash/api.py | 3 +++ cash/models.py | 6 +++--- cash/views.py | 4 ++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/cash/admin.py b/cash/admin.py index 13ea26d..0abfc3f 100644 --- a/cash/admin.py +++ b/cash/admin.py @@ -25,7 +25,7 @@ class AccountAdmin(admin.ModelAdmin): PAYOUT_SUBJECT = "Auszahlung" DEPOSIT_SUBJECT = "Einzahlung" DESC = "Autorisiert von %s %s" - + amount = form.cleaned_data['credit_change'] print amount @@ -44,9 +44,10 @@ class ProductBarcodeInline(admin.TabularInline): extra = 1 class ProductAdmin(admin.ModelAdmin): - list_display = ('name', 'category', 'price') - list_filter = ['category'] - inlines= [ProductBarcodeInline] + list_display = ('name', 'category', 'price', 'active') + list_filter = ['category', 'active'] + ordering = ('-active', 'name') + inlines = [ProductBarcodeInline] class ProductCategoryAdmin(admin.ModelAdmin): list_display = ('name', 'comment') diff --git a/cash/api.py b/cash/api.py index 5775cc7..6802ef1 100644 --- a/cash/api.py +++ b/cash/api.py @@ -169,6 +169,9 @@ def cashapi(request): except Product.DoesNotExist: raise ApiError(ERR_ITEM_NOT_FOUND) + if not item.active: + raise ApiError(ERR_ITEM_NOT_FOUND) + retval['id'] = item.id retval['name'] = item.name retval['ean'] = str(item.productbarcode_set.all()[0]) diff --git a/cash/models.py b/cash/models.py index 437bd53..0d3647e 100644 --- a/cash/models.py +++ b/cash/models.py @@ -35,8 +35,6 @@ class Account(models.Model): amount=amount, description=desc) transaction.save() - - def buy_products(self, products): # TODO place it somewhere else MAX_DEBIT = -35 @@ -49,6 +47,8 @@ class Account(models.Model): if self.credit - total_value >= MAX_DEBIT: desc = '' for product in products.keys(): + if not product.active: + raise ValueError('Trying to buy a disabled product.') amount = products[product] logentry = SalesLogEntry(account=self, product=product, @@ -76,7 +76,7 @@ class ProductCategory(models.Model): class Product(models.Model): name = models.CharField(max_length=32, unique=True) price = models.DecimalField(max_digits=5, decimal_places=2) - deleted = models.BooleanField() + active = models.BooleanField(default = True) category = models.ForeignKey(ProductCategory, blank=True, null=True) def __unicode__(self): diff --git a/cash/views.py b/cash/views.py index ab2debf..1f6160a 100644 --- a/cash/views.py +++ b/cash/views.py @@ -38,10 +38,10 @@ def transactions(request, detailed, page): def products(request, category_id=None): if category_id is None: category = None - products = Product.objects.all() + products = Product.objects.filter(active=True) else: category = get_object_or_404(ProductCategory, id=category_id) - products = Product.objects.filter(category=category) + products = Product.objects.filter(active=True).filter(category=category) categories = ProductCategory.objects.all()