|
|
|
@ -10,9 +10,9 @@ from sales.models import ItemSale
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
def get_sale(request, bid_id):
|
|
|
|
|
bid = ItemBid.objects.get(id=bid_id)
|
|
|
|
|
sale = ItemSale.objects.get(bid=bid)
|
|
|
|
|
def get_sale(request, sale_id):
|
|
|
|
|
sale = ItemSale.objects.get(id=sale_id)
|
|
|
|
|
bid = ItemBid.objects.get(id=sale.bid.id)
|
|
|
|
|
qr_uri = 'monero:{}?tx_amount={}&tx_description="xmrauctions_sale_{}"'.format(
|
|
|
|
|
sale.escrow_address, sale.expected_payment_xmr, sale.id
|
|
|
|
|
)
|
|
|
|
@ -22,6 +22,11 @@ def get_sale(request, bid_id):
|
|
|
|
|
messages.error(request, "You can't view a sale you are not involved in.")
|
|
|
|
|
return HttpResponseRedirect(reverse('home'))
|
|
|
|
|
|
|
|
|
|
# Do not proceed if sale is cancelled
|
|
|
|
|
if sale.sale_cancelled:
|
|
|
|
|
messages.error(request, 'That sale has been cancelled and is no longer available.')
|
|
|
|
|
return HttpResponseRedirect(reverse('get_item', args=[sale.item.id]))
|
|
|
|
|
|
|
|
|
|
_address_qr = BytesIO()
|
|
|
|
|
address_qr = qrcode_make(qr_uri).save(_address_qr)
|
|
|
|
|
|
|
|
|
@ -35,6 +40,38 @@ def get_sale(request, bid_id):
|
|
|
|
|
|
|
|
|
|
return render(request, 'sales/get_sale.html', context)
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
def cancel_sale(request, sale_id):
|
|
|
|
|
sale = ItemSale.objects.filter(id=sale_id).first()
|
|
|
|
|
bid = ItemBid.objects.get(id=sale.bid.id)
|
|
|
|
|
|
|
|
|
|
if sale is None:
|
|
|
|
|
messages.error(request, "That sale doesn't exist.")
|
|
|
|
|
return HttpResponseRedirect(reverse('home'))
|
|
|
|
|
|
|
|
|
|
# Do not proceed unless current user is a buyer or seller
|
|
|
|
|
if request.user != sale.bid.bidder and request.user != sale.item.owner:
|
|
|
|
|
messages.error(request, "You can't view a sale you are not involved in.")
|
|
|
|
|
return HttpResponseRedirect(reverse('home'))
|
|
|
|
|
|
|
|
|
|
if sale.payment_received:
|
|
|
|
|
messages.error(request, "You can't cancel a sale which has already received funds.")
|
|
|
|
|
return HttpResponseRedirect(reverse('get_sale', args=[sale.bid.id]))
|
|
|
|
|
|
|
|
|
|
# Item becomes available
|
|
|
|
|
sale.item.available = True
|
|
|
|
|
sale.item.save()
|
|
|
|
|
|
|
|
|
|
# Bid becomes not accepted
|
|
|
|
|
sale.bid.accepted = False
|
|
|
|
|
sale.bid.save()
|
|
|
|
|
|
|
|
|
|
# Sale gets cancelled
|
|
|
|
|
sale.sale_cancelled = True
|
|
|
|
|
sale.save()
|
|
|
|
|
return HttpResponseRedirect(reverse('get_item', args=[sale.item.id]))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
def confirm_shipment(request, sale_id):
|
|
|
|
|
sale = ItemSale.objects.get(id=sale_id)
|
|
|
|
|