Пример #1
0
def edit_available_items(request):
    """Edits all available items"""
    # IF any items show up that are delivered or allocated, something went wrong -
    # items should only be allocated or delivered if they have a requester
    mems = ClubMember.objects.all()
    available_pitems = PurchaseItem.get_available_items()
    return render(request, 'inventory/edit_available_items.html', {
                  'pitems': available_pitems, 'members': mems})
Пример #2
0
def list_switch_items(request, pitem_id):
    """Method to display a list of available purchase items with which the current item can
       be switched. This is useful when a member has selected something with the wrong attribute,
       e.g. size."""
    original = get_object_or_404(PurchaseItem, pk=pitem_id)
    available_pitems = PurchaseItem.get_available_items()
    return render(request, 'inventory/switch_items.html', {
                  'original': original, 'pitems': available_pitems})
Пример #3
0
def save_available_item_changes(request):
    """Saves any changes made to available items"""
    available_pitems = PurchaseItem.get_available_items()
    for pitem in available_pitems:
        updated = False
        try:
            ident = 'pitem-mem-%s' % pitem.pk
            selected_member_id = None
            if ident in request.POST:
                selected_member_id = int(request.POST['pitem-mem-%s' % pitem.pk])

            if (pitem.get_requester() is None and selected_member_id != 0) or \
               (pitem.get_requester() is not None and selected_member_id != pitem.requester.pk):
                if selected_member_id == 0:
                    pitem.requested_item.requester = None
                    pitem.requested_item.save()
                else:
                    pitem.requested_item.requester = ClubMember.objects.get(pk=request.POST['pitem-mem-%s' % pitem.pk])
                    pitem.requested_item.save()
                updated = True
                messages.success(request, "Updated %s (%s) to be requested by %s" % (pitem, pitem.pk, pitem.get_requester()))

        except (KeyError, ClubMember.DoesNotExist):
            messages.error(request, "Error attempting to update requester for %s (%s)" % (pitem, pitem.pk))
        # Update finalised
        try:
            # This is hacky, but for now, we'll assume it's the best way
            ident = 'pitem-finalised-%s' % pitem.pk
            finalised = ident in request.POST
            if pitem.payment_fulfilled != finalised:
                pitem.payment_fulfilled = finalised
                messages.success(request, "Updated %s (%s) finalised" % (pitem, pitem.pk))
                updated = True
        except (KeyError, ClubMember.DoesNotExist):
            messages.error(request, "Error attempting to update finalised for %s (%s)" % (pitem, pitem.pk))

        # Update amount received
        try:
            ident = 'pitem-amt-rcvd-%s' % pitem.pk
            if ident in request.POST:
                amount_received = Decimal(request.POST[ident])
                if amount_received != pitem.amount_received:
                    pitem.amount_received = amount_received
                    updated = True
                    messages.success(request, "Updated %s (%s) to amount %s" % (pitem, pitem.pk, pitem.amount_received))
        except (KeyError, ClubMember.DoesNotExist):
            messages.error(request, "Error attempting to update amount received for %s (%s)" % (pitem, pitem.pk))

        if updated:
            pitem.save()

    return HttpResponseRedirect(reverse('inventory:edit_available_items'))
Пример #4
0
def available_items(request):
    """Method to obtain a table of available Purchase Items"""
    # IF any items show up that are delivered or allocated, something went wrong -
    # items should only be allocated or delivered if they have a requester
    available_pitems = PurchaseItem.get_available_items()
    groups = PurchaseItem.generate_grouped_purchase_items(available_pitems)
    total_cost = 0
    total_count = 0
    for g in groups:
        total_count += g.count
        total_cost += g.c_purchase_cost
    return render(request, 'inventory/available_items.html',
                  {'groups': groups, 'cost': total_cost, 'count': total_count})