Creating bidding list view

Preparing for inquiry payment
This commit is contained in:
Kumi 2021-04-18 12:02:17 +02:00
parent 3cf2587e9d
commit d65e0499ac
10 changed files with 102 additions and 63 deletions

View file

@ -23,6 +23,7 @@ class Inquiry(models.Model):
children = models.IntegerField() children = models.IntegerField()
comment = models.TextField(null=True, blank=True) comment = models.TextField(null=True, blank=True)
active = models.BooleanField(default=False) active = models.BooleanField(default=False)
gateway = models.CharField(max_length=128, null=True, blank=True)
@property @property
def is_paid(self): def is_paid(self):
@ -31,9 +32,6 @@ class Inquiry(models.Model):
return self.invoice.is_paid return self.invoice.is_paid
def get_hotels(self):
pass
@property @property
def accepted(self): def accepted(self):
qset = Offer.objects.filter(inquiry=self, accepted=True) qset = Offer.objects.filter(inquiry=self, accepted=True)

View file

@ -3,13 +3,13 @@ from django.shortcuts import redirect, get_object_or_404
from django.contrib import messages from django.contrib import messages
from django.urls import reverse from django.urls import reverse
from django.contrib.gis.geos import Point from django.contrib.gis.geos import Point
from django.db.models import F
from django.contrib.gis.db.models.functions import Distance from django.contrib.gis.db.models.functions import Distance
from public.mixins import InConstructionMixin from public.mixins import InConstructionMixin
from partners.mixins import PartnerProfileRequiredMixin from partners.mixins import PartnerProfileRequiredMixin
from localauth.helpers import name_to_coords from localauth.helpers import name_to_coords
from partners.models import Establishment from partners.models import Establishment
from payment.models import BillingAddress, Invoice, InvoiceItem, InvoicePayment
from .models import Inquiry, Offer from .models import Inquiry, Offer
from .forms import InquiryProcessForm from .forms import InquiryProcessForm
@ -23,7 +23,7 @@ class InquiryCreateView(CreateView):
def form_valid(self, form): def form_valid(self, form):
form.instance.destination_coords = self.clean_destination_coords() form.instance.destination_coords = self.clean_destination_coords()
form.instance.destination_radius = 0 form.instance.destination_radius = 5000
return super().form_valid(form) return super().form_valid(form)
def form_invalid(self, form, *args, **kwargs): def form_invalid(self, form, *args, **kwargs):
@ -58,8 +58,23 @@ class InquiryProcessView(InConstructionMixin, UpdateView):
return initial return initial
def form_valid(self, form):
profile = self.request.user.clientprofile
profile.first_name = form.cleaned_data["first_name"]
profile.last_name = form.cleaned_data["last_name"]
profile.street = form.cleaned_data["street"]
profile.city = form.cleaned_data["city"]
profile.zip = form.cleaned_data["zip"]
profile.state = form.cleaned_data["state"]
profile.country = form.cleaned_data["country"]
profile.save()
def get_success_url(self):
return reverse("auction:inquiry_payment", args=(self.object.uuid,))
class InquiryPaymentView(InConstructionMixin, View): class InquiryPaymentView(InConstructionMixin, View):
pass def get(self, request, *args, **kwargs):
inquiry = Inquiry.objects.get(uuid=kwargs["uuid"])
class OfferSelectionView(InConstructionMixin, DetailView): class OfferSelectionView(InConstructionMixin, DetailView):
model = Inquiry model = Inquiry
@ -103,5 +118,4 @@ class BiddingListView(InConstructionMixin, PartnerProfileRequiredMixin, ListView
def get_queryset(self): def get_queryset(self):
establishment = self.get_establishment() establishment = self.get_establishment()
inquiries = Inquiry.objects.annotate(distance=Distance("destination_coords", establishment.coords)) return Inquiry.objects.annotate(distance=Distance("destination_coords", establishment.coords))#.filter(active=True)
return inquiries.filter(active=True) #, distance__lte=F("destination_radius"))

View file

@ -3,6 +3,7 @@ from urlaubsauktion.admin import joker_admin as admin
from .models import InvoicePayment, Invoice, InvoiceItem from .models import InvoicePayment, Invoice, InvoiceItem
from .paypal.models import PaypalInvoicePayment from .paypal.models import PaypalInvoicePayment
from .sepa.models import SepaInvoicePayment from .sepa.models import SepaInvoicePayment
from .demo.models import DemoInvoicePayment
# Register your models here. # Register your models here.
@ -11,4 +12,5 @@ admin.register(Invoice)
admin.register(InvoiceItem) admin.register(InvoiceItem)
admin.register(PaypalInvoicePayment) admin.register(PaypalInvoicePayment)
admin.register(SepaInvoicePayment) admin.register(SepaInvoicePayment)
admin.register(DemoInvoicePayment)

View file

@ -1,64 +1,15 @@
from payment.models import InvoicePayment, Invoice from payment.models import InvoicePayment, Invoice
from .api import PaypalAPI
from paypalcheckoutsdk.orders import OrdersCreateRequest
from paypalhttp import HttpError
from django.db import models from django.db import models
from django.urls import reverse_lazy from django.urls import reverse_lazy
from dbsettings.functions import getValue import uuid
import logging class DemoInvoicePayment(InvoicePayment):
logger = logging.getLogger(__name__)
class PaypalOrder(models.Model):
invoice = models.ForeignKey(Invoice, models.CASCADE)
order_id = models.CharField(max_length=64)
class PaypalInvoicePayment(InvoicePayment):
@property @property
def gateway(self): def gateway(self):
return "Paypal" return "Paypal"
@staticmethod @staticmethod
def initiate(invoice): def initiate(invoice):
request = OrdersCreateRequest() self.objects.create(invoice=invoice, amount=invoice.amount, gateway_id=uuid.uuid4())
request.prefer('return=representation')
request.request_body (
{
"intent": "CAPTURE",
"purchase_units": [
{
"amount": {
"currency_code": invoice.currency,
"value": float(invoice.price_gross)
}
}
],
"application_context": {
"return_url": getValue("application.base_url") + reverse_lazy("this_sucks"),
"cancel_url": getValue("application.base_url"),
"brand_name": getValue("application.name", "JourneyJoker"),
"landing_page": "BILLING",
"user_action": "CONTINUE"
},
}
)
try:
client = PaypalAPI().client
response = client.execute(request)
PaypalOrder.objects.create(subscription=subscription, order_id=response.result.id)
for link in response.result.links:
if link.rel == "approve":
return link.href
except IOError as ioe:
logger.error(ioe)
if isinstance(ioe, HttpError):
logger.error(ioe.status_code)

View file

@ -1,6 +1,6 @@
from django.urls import path from django.urls import path
app_name = "paypal" app_name = "demo"
urlpatterns = [ urlpatterns = [
] ]

View file

@ -0,0 +1,6 @@
from django.conf import settings
def demo(request):
return {
"DEBUG": settings.DEBUG,
}

View file

@ -0,0 +1,3 @@
$(document).ready( function () {
$('#biddingtable').DataTable();
} );

View file

@ -0,0 +1,50 @@
{% extends "frontend/base.html" %}
{% load i18n %}
{% load bootstrap4 %}
{% load static %}
{% block "styles" %}
<link rel="stylesheet" type="text/css" href="{% static "vendor/css/jquery.dataTables.min.css" %}">
{% endblock %}
{% block "content" %}
<!--===== INNERPAGE-WRAPPER ====-->
<section class="innerpage-wrapper">
<div id="payment-success" class="section-padding">
<div class="container text-center">
<div class="row d-flex justify-content-center">
<div class="col-md-12 col-lg-12 col-lg-offset-2">
<h2>{% trans "Verfügbare Anfragen" %}</h2>
<table id="biddingtable">
<thead>
<td>ID</td>
<td>Reiseziel (Distanz)</td>
<td>Anreisedatum</td>
<td>Aufenthaltsdauer</td>
<td>Personen</td>
<td>Gebotener Betrag</td>
<td></td>
</thead>
{% for inquiry in object_list %}{% if inquiry.destination_radius == 0 or inquiry.distance.m < inquiry.destination_radius %}
<tr>
<td>{{ inquiry.id }}</td>
<td>{{ inquiry.destination_name }} ({{ inquiry.distance.km | floatformat:1 }}km)</td>
<td>{{ inquiry.arrival }}</td>
<td>{% if inquiry.min_nights == 0 %}Egal!{% elif inquiry.min_nights == 1 %}Kurztrip (2-3 Nächte){% else %}Min. 3 Nächte{% endif %}</td>
<td>{{ inquiry.adults }} + {{ inquiry.children }}</td>
<td>€ {{ inquiry.budget }}</td>
<td><button class="btn btn-orange">Angebot erstellen!</button></td>
</tr>
{% endif %}{% endfor %}
</table>
</div><!-- end columns -->
</div><!-- end row -->
</div><!-- end container -->
</div><!-- end coming-soon-text -->
</section><!-- end innerpage-wrapper -->
{% endblock %}
{% block "scripts" %}
<script type="text/javascript" charset="utf8" src="{% static "vendor/js/jquery.dataTables.min.js" %}"></script>
<script type="text/javascript" src="{% static "auction/js/biddingtable.js" %}"></script>
{% endblock %}

View file

@ -243,6 +243,9 @@
<li class="nav-item active"><a class="nav-link" href="#tab-credit-card" data-toggle="tab">{% trans "Kreditkarte" %}</a></li> <li class="nav-item active"><a class="nav-link" href="#tab-credit-card" data-toggle="tab">{% trans "Kreditkarte" %}</a></li>
<li class="nav-item"><a class="nav-link" href="#tab-paypal" data-toggle="tab">{% trans "PayPal" %}</a></li> <li class="nav-item"><a class="nav-link" href="#tab-paypal" data-toggle="tab">{% trans "PayPal" %}</a></li>
<li class="nav-item"><a class="nav-link" href="#tab-sepa" data-toggle="tab">{% trans "Überweisung" %}</a></li> <li class="nav-item"><a class="nav-link" href="#tab-sepa" data-toggle="tab">{% trans "Überweisung" %}</a></li>
{% if DEBUG %}
<li class="nav-item"><a class="nav-link" href="#tab-demo" data-toggle="tab">Demo-Zahlung</a></li>
{% endif %}
</ul> </ul>
<div class="tab-content"> <div class="tab-content">
@ -273,12 +276,23 @@
<div class="clearfix"></div> <div class="clearfix"></div>
</div><!-- end tab-paypal --> </div><!-- end tab-paypal -->
{% if DEBUG %}
<div id="tab-demo" class="tab-pane">
<img src="{% static "frontend/images/paypal.png" %}" class="img-fluid" alt="demo" />
<div class="paypal-text">
<p>Bezahlung mit Luft und Liebe.</p>
</div><!-- end paypal-text -->
<div class="clearfix"></div>
</div><!-- end tab-paypal -->
{% endif %}
</div><!-- end tab-content --> </div><!-- end tab-content -->
</div><!-- end payment-tabs --> </div><!-- end payment-tabs -->
<div class="checkbox"> <div class="checkbox">
<label><input type="checkbox" {% if request.user.is_authenticated %}required{% else %}disabled{% endif %} id="id_terms" name="terms"> {% trans "Ich erkläre mich einverstanden mit den" %} <a href="#">{% trans "Allgemeinen Geschäftsbedingungen" %}</a>.</label> <label><input type="checkbox" {% if request.user.is_authenticated %}required{% else %}disabled{% endif %} id="id_terms" name="terms"> {% trans "Ich erkläre mich einverstanden mit den" %} <a href="#">{% trans "Allgemeinen Geschäftsbedingungen" %}</a> {% trans "und der" %} <a href="#">{% trans "Datenschutzerklärung" %}</a>.</label>
</div><!-- end checkbox --> </div><!-- end checkbox -->
<div class="col-md-12 text-center" id="result_msg"></div> <div class="col-md-12 text-center" id="result_msg"></div>
<input type="hidden" id="id_payment" name="payment"> <input type="hidden" id="id_payment" name="payment">

View file

@ -50,6 +50,7 @@ TEMPLATES = [
'django.template.context_processors.request', 'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth', 'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages', 'django.contrib.messages.context_processors.messages',
'public.context_processors.demo',
], ],
}, },
}, },