Esempio n. 1
0
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)
Esempio n. 2
0
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())
Esempio n. 3
0
 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])
Esempio n. 4
0
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)