Creating bidding list view
Preparing for inquiry payment
This commit is contained in:
parent
3cf2587e9d
commit
d65e0499ac
10 changed files with 102 additions and 63 deletions
|
@ -23,6 +23,7 @@ class Inquiry(models.Model):
|
|||
children = models.IntegerField()
|
||||
comment = models.TextField(null=True, blank=True)
|
||||
active = models.BooleanField(default=False)
|
||||
gateway = models.CharField(max_length=128, null=True, blank=True)
|
||||
|
||||
@property
|
||||
def is_paid(self):
|
||||
|
@ -31,9 +32,6 @@ class Inquiry(models.Model):
|
|||
|
||||
return self.invoice.is_paid
|
||||
|
||||
def get_hotels(self):
|
||||
pass
|
||||
|
||||
@property
|
||||
def accepted(self):
|
||||
qset = Offer.objects.filter(inquiry=self, accepted=True)
|
||||
|
|
|
@ -3,13 +3,13 @@ from django.shortcuts import redirect, get_object_or_404
|
|||
from django.contrib import messages
|
||||
from django.urls import reverse
|
||||
from django.contrib.gis.geos import Point
|
||||
from django.db.models import F
|
||||
from django.contrib.gis.db.models.functions import Distance
|
||||
|
||||
from public.mixins import InConstructionMixin
|
||||
from partners.mixins import PartnerProfileRequiredMixin
|
||||
from localauth.helpers import name_to_coords
|
||||
from partners.models import Establishment
|
||||
from payment.models import BillingAddress, Invoice, InvoiceItem, InvoicePayment
|
||||
|
||||
from .models import Inquiry, Offer
|
||||
from .forms import InquiryProcessForm
|
||||
|
@ -23,7 +23,7 @@ class InquiryCreateView(CreateView):
|
|||
|
||||
def form_valid(self, form):
|
||||
form.instance.destination_coords = self.clean_destination_coords()
|
||||
form.instance.destination_radius = 0
|
||||
form.instance.destination_radius = 5000
|
||||
return super().form_valid(form)
|
||||
|
||||
def form_invalid(self, form, *args, **kwargs):
|
||||
|
@ -58,8 +58,23 @@ class InquiryProcessView(InConstructionMixin, UpdateView):
|
|||
|
||||
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):
|
||||
pass
|
||||
def get(self, request, *args, **kwargs):
|
||||
inquiry = Inquiry.objects.get(uuid=kwargs["uuid"])
|
||||
|
||||
class OfferSelectionView(InConstructionMixin, DetailView):
|
||||
model = Inquiry
|
||||
|
@ -103,5 +118,4 @@ class BiddingListView(InConstructionMixin, PartnerProfileRequiredMixin, ListView
|
|||
|
||||
def get_queryset(self):
|
||||
establishment = self.get_establishment()
|
||||
inquiries = Inquiry.objects.annotate(distance=Distance("destination_coords", establishment.coords))
|
||||
return inquiries.filter(active=True) #, distance__lte=F("destination_radius"))
|
||||
return Inquiry.objects.annotate(distance=Distance("destination_coords", establishment.coords))#.filter(active=True)
|
|
@ -3,6 +3,7 @@ from urlaubsauktion.admin import joker_admin as admin
|
|||
from .models import InvoicePayment, Invoice, InvoiceItem
|
||||
from .paypal.models import PaypalInvoicePayment
|
||||
from .sepa.models import SepaInvoicePayment
|
||||
from .demo.models import DemoInvoicePayment
|
||||
|
||||
# Register your models here.
|
||||
|
||||
|
@ -11,4 +12,5 @@ admin.register(Invoice)
|
|||
admin.register(InvoiceItem)
|
||||
|
||||
admin.register(PaypalInvoicePayment)
|
||||
admin.register(SepaInvoicePayment)
|
||||
admin.register(SepaInvoicePayment)
|
||||
admin.register(DemoInvoicePayment)
|
|
@ -1,64 +1,15 @@
|
|||
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.urls import reverse_lazy
|
||||
|
||||
from dbsettings.functions import getValue
|
||||
import uuid
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class PaypalOrder(models.Model):
|
||||
invoice = models.ForeignKey(Invoice, models.CASCADE)
|
||||
order_id = models.CharField(max_length=64)
|
||||
|
||||
class PaypalInvoicePayment(InvoicePayment):
|
||||
class DemoInvoicePayment(InvoicePayment):
|
||||
@property
|
||||
def gateway(self):
|
||||
return "Paypal"
|
||||
|
||||
@staticmethod
|
||||
def initiate(invoice):
|
||||
request = OrdersCreateRequest()
|
||||
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)
|
||||
self.objects.create(invoice=invoice, amount=invoice.amount, gateway_id=uuid.uuid4())
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from django.urls import path
|
||||
|
||||
app_name = "paypal"
|
||||
app_name = "demo"
|
||||
|
||||
urlpatterns = [
|
||||
]
|
||||
|
|
6
public/context_processors.py
Normal file
6
public/context_processors.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.conf import settings
|
||||
|
||||
def demo(request):
|
||||
return {
|
||||
"DEBUG": settings.DEBUG,
|
||||
}
|
3
static/auction/js/biddingtable.js
Normal file
3
static/auction/js/biddingtable.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
$(document).ready( function () {
|
||||
$('#biddingtable').DataTable();
|
||||
} );
|
50
templates/auction/bidding_list.html
Normal file
50
templates/auction/bidding_list.html
Normal 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 %}
|
|
@ -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"><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>
|
||||
{% if DEBUG %}
|
||||
<li class="nav-item"><a class="nav-link" href="#tab-demo" data-toggle="tab">Demo-Zahlung</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
<div class="tab-content">
|
||||
|
@ -273,12 +276,23 @@
|
|||
|
||||
<div class="clearfix"></div>
|
||||
</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 payment-tabs -->
|
||||
|
||||
<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 class="col-md-12 text-center" id="result_msg"></div>
|
||||
<input type="hidden" id="id_payment" name="payment">
|
||||
|
|
|
@ -50,6 +50,7 @@ TEMPLATES = [
|
|||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
'public.context_processors.demo',
|
||||
],
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue