Example #1
0
 def test_dont_get_two_free(self):
     purchases = [
         models.Purchase(bucket_id=1, good_id=4, good_count=2),
         models.Purchase(bucket_id=1, good_id=5, good_count=2),
     ]
     total = views.calculate_total(purchases, self.goods, self.specials)
     self.assertEqual(total, 120 * 2 + 90)
Example #2
0
 def test_ordinary_prices(self):
     purchases = [
         models.Purchase(bucket_id=1, good_id=1, good_count=2),
         models.Purchase(bucket_id=1, good_id=2, good_count=1),
         models.Purchase(bucket_id=1, good_id=3, good_count=1568),
     ]
     total = views.calculate_total(purchases, self.goods, self.specials)
     expected = int(2 * 50 + 1 * 30 + 1568 * 199 / 1000.0)
     self.assertEqual(total, expected)
Example #3
0
    def post(self, request, *args, **kwargs):
        goods = models.Good.objects.all()
        bucket = models.Bucket.objects.order_by('-updated')[0]
        purchases = models.Purchase.objects.filter(bucket_id=bucket.id)
        if 'add' in request.POST:
            # add the last purchase to the bucket
            good_id = int(request.POST['good'])
            good = goods.get(id=good_id)
            quantity = request.POST['quantity'] or '1'
            quantity = int(float(quantity) * good.pricing_unit)
            goods_in_bucket = [p.good_id for p in purchases]
            if good_id in goods_in_bucket:
                purchase = purchases.get(good_id=good_id)
                purchase.good_count += quantity
                purchase.save()
            else:
                new_purchase = models.Purchase(bucket_id=bucket.id,
                                               good_id=good_id,
                                               good_count=quantity)
                new_purchase.save()
        elif 'clear' in request.POST:
            # remove all purchases from current bucket
            purchases.delete()
        elif 'end' in request.POST:
            # deactivate current bucket, new one will be created
            bucket.active = False
            bucket.save()

        return shortcuts.redirect('index', *args, **kwargs)
Example #4
0
 def test_multiprice(self):
     purchases = [models.Purchase(bucket_id=1, good_id=1, good_count=3)]
     total = views.calculate_total(purchases, self.goods, self.specials)
     self.assertEqual(total, 130)