Browse Source

Renamed 'deleted' flag for products to 'active' and added checks for it; also removed unnescessary whitespace

master
Niklas Brachmann 11 years ago
parent
commit
a2685cde76
  1. 9
      cash/admin.py
  2. 3
      cash/api.py
  3. 6
      cash/models.py
  4. 4
      cash/views.py

9
cash/admin.py

@ -25,7 +25,7 @@ class AccountAdmin(admin.ModelAdmin):
PAYOUT_SUBJECT = "Auszahlung" PAYOUT_SUBJECT = "Auszahlung"
DEPOSIT_SUBJECT = "Einzahlung" DEPOSIT_SUBJECT = "Einzahlung"
DESC = "Autorisiert von %s %s" DESC = "Autorisiert von %s %s"
amount = form.cleaned_data['credit_change'] amount = form.cleaned_data['credit_change']
print amount print amount
@ -44,9 +44,10 @@ class ProductBarcodeInline(admin.TabularInline):
extra = 1 extra = 1
class ProductAdmin(admin.ModelAdmin): class ProductAdmin(admin.ModelAdmin):
list_display = ('name', 'category', 'price') list_display = ('name', 'category', 'price', 'active')
list_filter = ['category'] list_filter = ['category', 'active']
inlines= [ProductBarcodeInline] ordering = ('-active', 'name')
inlines = [ProductBarcodeInline]
class ProductCategoryAdmin(admin.ModelAdmin): class ProductCategoryAdmin(admin.ModelAdmin):
list_display = ('name', 'comment') list_display = ('name', 'comment')

3
cash/api.py

@ -169,6 +169,9 @@ def cashapi(request):
except Product.DoesNotExist: except Product.DoesNotExist:
raise ApiError(ERR_ITEM_NOT_FOUND) raise ApiError(ERR_ITEM_NOT_FOUND)
if not item.active:
raise ApiError(ERR_ITEM_NOT_FOUND)
retval['id'] = item.id retval['id'] = item.id
retval['name'] = item.name retval['name'] = item.name
retval['ean'] = str(item.productbarcode_set.all()[0]) retval['ean'] = str(item.productbarcode_set.all()[0])

6
cash/models.py

@ -35,8 +35,6 @@ class Account(models.Model):
amount=amount, description=desc) amount=amount, description=desc)
transaction.save() transaction.save()
def buy_products(self, products): def buy_products(self, products):
# TODO place it somewhere else # TODO place it somewhere else
MAX_DEBIT = -35 MAX_DEBIT = -35
@ -49,6 +47,8 @@ class Account(models.Model):
if self.credit - total_value >= MAX_DEBIT: if self.credit - total_value >= MAX_DEBIT:
desc = '' desc = ''
for product in products.keys(): for product in products.keys():
if not product.active:
raise ValueError('Trying to buy a disabled product.')
amount = products[product] amount = products[product]
logentry = SalesLogEntry(account=self, product=product, logentry = SalesLogEntry(account=self, product=product,
@ -76,7 +76,7 @@ class ProductCategory(models.Model):
class Product(models.Model): class Product(models.Model):
name = models.CharField(max_length=32, unique=True) name = models.CharField(max_length=32, unique=True)
price = models.DecimalField(max_digits=5, decimal_places=2) 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) category = models.ForeignKey(ProductCategory, blank=True, null=True)
def __unicode__(self): def __unicode__(self):

4
cash/views.py

@ -38,10 +38,10 @@ def transactions(request, detailed, page):
def products(request, category_id=None): def products(request, category_id=None):
if category_id is None: if category_id is None:
category = None category = None
products = Product.objects.all() products = Product.objects.filter(active=True)
else: else:
category = get_object_or_404(ProductCategory, id=category_id) 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() categories = ProductCategory.objects.all()

Loading…
Cancel
Save