def test_order_total_multi_item(self): order = Order(self.member, self.room) item = OrderItem(self.product, order, 2) order.items.add(item) self.assertEqual(order.total(), 20)
def test_order_total_single_item(self): order = Order(self.member, self.room) item = OrderItem(self.product, order, 1) order.items.add(item) self.assertEqual(order.total(), 10)
def test_order_execute_multi_transaction(self, fulfill): order = Order(self.member, self.room) item = OrderItem(self.product, order, 2) order.items.add(item) order.execute() fulfill.assert_called_once_with(PayTransaction(20))
def test_order_execute_no_money(self, fulfill, can_fulfill): can_fulfill.return_value = False order = Order(self.member, self.room) item = OrderItem(self.product, order, 2) order.items.add(item) with self.assertRaises(StregForbudError): order.execute() fulfill.was_not_called()
def test_order_execute_multi_some_remaining(self, fulfill): self.product.sale_set.create(price=100, member=self.member) self.product.start_date = datetime.date(year=2017, month=1, day=1) self.product.quantity = 2 order = Order(self.member, self.room) item = OrderItem(self.product, order, 2) order.items.add(item) with self.assertRaises(NoMoreInventoryError): order.execute() fulfill.was_not_called()
def test_order_execute_no_money(self, can_fulfill): can_fulfill.return_value = False balance_before = self.member.balance order = Order(self.member, self.room) item = OrderItem(self.product, order, 2) order.items.add(item) with self.assertRaises(StregForbudError): order.execute() balance_after = self.member.balance self.assertEqual(balance_before, balance_after)
def menu_sale(request, room_id, member_id, product_id=None): room = Room.objects.get(pk=room_id) news = __get_news() member = Member.objects.get(pk=member_id, active=True) product = None try: product = Product.objects.get(Q(pk=product_id), Q(active=True), Q(rooms__id=room_id) | Q(rooms=None), Q(deactivate_date__gte=datetime.datetime.now()) | Q(deactivate_date__isnull=True)) order = Order.from_products( member=member, room=room, products=(product, ) ) order.execute() except Product.DoesNotExist: pass except StregForbudError: return render(request, 'stregsystem/error_stregforbud.html', locals()) except NoMoreInventoryError: # @INCOMPLETE this should render with a different template return render(request, 'stregsystem/error_stregforbud.html', locals()) # Refresh member, to get new amount member = Member.objects.get(pk=member_id, active=True) return usermenu(request, room, member, product, from_sale=True)
def quicksale(request, room, member, bought_ids): news = __get_news() product_list = __get_productlist(room.id) # Retrieve products and construct transaction products = [] try: for i in bought_ids: product = Product.objects.get( Q(pk=i), Q(active=True), Q(deactivate_date__gte=datetime.datetime.now()) | Q(deactivate_date__isnull=True), Q(rooms__id=room.id) | Q(rooms=None)) products.append(product) except Product.DoesNotExist: return usermenu(request, room, member, None) order = Order.from_products(member=member, products=products, room=room) try: order.execute() except StregForbudError: return render(request, 'stregsystem/error_stregforbud.html', locals()) except NoMoreInventoryError: # @INCOMPLETE this should render with a different template return render(request, 'stregsystem/error_stregforbud.html', locals()) promille = member.calculate_alcohol_promille() is_ballmer_peaking, bp_minutes, bp_seconds = ballmer_peak(promille) cost = order.total return render(request, 'stregsystem/index_sale.html', locals())
def test_order_fromproducts(self): products = [ self.product, self.product, ] order = Order.from_products(self.member, self.room, products) self.assertEqual(list(Counter(products).items()), [(item.product, item.count) for item in order.items])
def menu_sale(request, room_id, member_id, product_id=None): room = Room.objects.get(pk=room_id) news = __get_news() member = Member.objects.get(pk=member_id, active=True) product = None if request.method == 'POST': purchase = PurchaseForm(request.POST) if not purchase.is_valid(): return HttpResponseBadRequest( "Cannot complete sale, get help at /dev/null or at mailto:[treo|fit]@fklub.dk" ) try: product = Product.objects.get( Q(pk=purchase.cleaned_data['product_id']), Q(active=True), Q(rooms__id=room_id) | Q(rooms=None), Q(deactivate_date__gte=timezone.now()) | Q(deactivate_date__isnull=True)) order = Order.from_products(member=member, room=room, products=(product, )) order.execute() except Product.DoesNotExist: pass except StregForbudError: return render(request, 'stregsystem/error_stregforbud.html', locals()) except NoMoreInventoryError: # @INCOMPLETE this should render with a different template return render(request, 'stregsystem/error_stregforbud.html', locals()) # Refresh member, to get new amount member = Member.objects.get(pk=member_id, active=True) return usermenu(request, room, member, product, from_sale=True)