add orders RESTfull
This commit is contained in:
parent
f170f5b0da
commit
a18765b0a6
|
@ -30,7 +30,9 @@
|
||||||
<tr class="table_content">
|
<tr class="table_content">
|
||||||
<td scope="col">{{ order.id }}</td>
|
<td scope="col">{{ order.id }}</td>
|
||||||
<td scope="col">{{ order.date }}</td>
|
<td scope="col">{{ order.date }}</td>
|
||||||
<td scope="col">{{ order.status }}</td>
|
<td scope="col">
|
||||||
|
<a href="{% url 'order' order.id %}">{{ order.status }}</a>
|
||||||
|
</td>
|
||||||
<td scope="col">{{ order_positions_count }}</td>
|
<td scope="col">{{ order_positions_count }}</td>
|
||||||
<td scope="col">{{ total }} {{ currency_name }}</td>
|
<td scope="col">{{ total }} {{ currency_name }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -4,4 +4,57 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1> Your order was submitted. </h1>
|
<h1> Your order was submitted. </h1>
|
||||||
<h3> Thank you for Purchase. </h3>
|
<h3> Thank you for Purchase. </h3>
|
||||||
|
<h3>List of Items in your Shopping Cart:</h3>
|
||||||
|
{% if order_position_list %}
|
||||||
|
<table class="table price-table">
|
||||||
|
<tr class="table_header">
|
||||||
|
<th scope="col">POS.</th>
|
||||||
|
<th scope="col">ART#</th>
|
||||||
|
<th scope="col">NAME</th>
|
||||||
|
<th scope="col">STOCK</th>
|
||||||
|
<th scope="col">AMOUNT</th>
|
||||||
|
<th scope="col" class="price-label">PRICE p.pce.</th>
|
||||||
|
<th scope="col" class="price-label">POSITION PRICE</th>
|
||||||
|
</tr>
|
||||||
|
{% for order_position in order_position_list %}
|
||||||
|
<tr class="table_content">
|
||||||
|
<td scope="col">{{ order_position.id }}</td>
|
||||||
|
<td scope="col">{{ order_position.article.id }}</td>
|
||||||
|
<td scope="col">
|
||||||
|
<a href="{% url 'details' order_position.article.id %}">
|
||||||
|
{{ order_position.article.name }}
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td scope="col">{{ order_position.article.stock }}</td>
|
||||||
|
<td scope="col">{{ order_position.amount }}</td>
|
||||||
|
<td scope="col" class="price-value">
|
||||||
|
{{ order_position.article.price_in_chf }}
|
||||||
|
{{ currency_name }}
|
||||||
|
</td>
|
||||||
|
<td scope="col" class="price-value">
|
||||||
|
{{ order_position.position_price }} {{ currency_name }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
<tr>
|
||||||
|
<td scope="col" colspan="5"class="text-right">
|
||||||
|
<td scope="col" class="price-value">
|
||||||
|
<dl><dt>Total:</dl></dt></td>
|
||||||
|
<td scope="col" class="price-value">
|
||||||
|
<dl><dt>{{ total }} {{ currency_name }}</dl></dt>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
{% else %}
|
||||||
|
<p class="alert alert-danger">
|
||||||
|
<strong>
|
||||||
|
This order is empty. Howcome?
|
||||||
|
<strong>
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
<p class="alert text-danger">
|
||||||
|
<strong>
|
||||||
|
{{ message }}
|
||||||
|
<strong>
|
||||||
|
</p>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -23,7 +23,7 @@ urlpatterns = [
|
||||||
url(r'^cart/checkout/$',
|
url(r'^cart/checkout/$',
|
||||||
views.checkout,
|
views.checkout,
|
||||||
name='checkout'),
|
name='checkout'),
|
||||||
url(r'^order/$',
|
url(r'^order/(?P<order_id>[0-9]+)/$',
|
||||||
views.order,
|
views.order,
|
||||||
name='order'),
|
name='order'),
|
||||||
]
|
]
|
||||||
|
|
|
@ -4,6 +4,7 @@ from django.contrib.auth.decorators import login_required
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.auth.forms import UserCreationForm
|
from django.contrib.auth.forms import UserCreationForm
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
from decimal import Decimal
|
||||||
from webshop.models import (Article,
|
from webshop.models import (Article,
|
||||||
Category,
|
Category,
|
||||||
Person,
|
Person,
|
||||||
|
@ -172,6 +173,7 @@ def profile(request):
|
||||||
if orders:
|
if orders:
|
||||||
orders_list = list(orders)
|
orders_list = list(orders)
|
||||||
for idx1, order in enumerate(orders_list):
|
for idx1, order in enumerate(orders_list):
|
||||||
|
print(order.id)
|
||||||
# get all items in the Order:
|
# get all items in the Order:
|
||||||
order_positions = OrderPosition.objects.filter(order=order)
|
order_positions = OrderPosition.objects.filter(order=order)
|
||||||
if (order_positions.count()) > 0:
|
if (order_positions.count()) > 0:
|
||||||
|
@ -417,8 +419,6 @@ def checkout(request):
|
||||||
else:
|
else:
|
||||||
order = Order.objects.create(user=request.user,
|
order = Order.objects.create(user=request.user,
|
||||||
status=orderstatus)
|
status=orderstatus)
|
||||||
|
|
||||||
print('order', order, 'created:', order)
|
|
||||||
for position in cart_positions:
|
for position in cart_positions:
|
||||||
OrderPosition.objects.create(
|
OrderPosition.objects.create(
|
||||||
article=position.article,
|
article=position.article,
|
||||||
|
@ -426,7 +426,7 @@ def checkout(request):
|
||||||
amount=position.amount,
|
amount=position.amount,
|
||||||
price_in_chf=position.article.price_in_chf
|
price_in_chf=position.article.price_in_chf
|
||||||
)
|
)
|
||||||
return HttpResponseRedirect('/order/')
|
return HttpResponseRedirect('/order/%s/' % order.id)
|
||||||
|
|
||||||
return render(request, 'webshop/checkout.html',
|
return render(request, 'webshop/checkout.html',
|
||||||
{'cart_position_list': cart_position_list,
|
{'cart_position_list': cart_position_list,
|
||||||
|
@ -436,11 +436,13 @@ def checkout(request):
|
||||||
'article_view': article_view,
|
'article_view': article_view,
|
||||||
'category_list': category_list,
|
'category_list': category_list,
|
||||||
'message': message,
|
'message': message,
|
||||||
'person': person
|
'person': person,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
def order(request):
|
def order(request, order_id):
|
||||||
|
totalprice_list = []
|
||||||
|
order_position_list = []
|
||||||
cart = ShoppingCart.objects.get(user=request.user)
|
cart = ShoppingCart.objects.get(user=request.user)
|
||||||
if cart:
|
if cart:
|
||||||
# get all items in the cart of this customer:
|
# get all items in the cart of this customer:
|
||||||
|
@ -456,27 +458,29 @@ def order(request):
|
||||||
else:
|
else:
|
||||||
message = """something whent wrong.
|
message = """something whent wrong.
|
||||||
We cold not empty your cart. """
|
We cold not empty your cart. """
|
||||||
|
order = Order.objects.get(id=order_id)
|
||||||
# category_list = get_categories()
|
order_positions = OrderPosition.objects.filter(order=order_id)
|
||||||
# person = Person.objects.get(user=request.user)
|
if (order_positions.count()) > 0:
|
||||||
# orders = Order.objects.filter(user=request.user)
|
order_position_list = list(order_positions)
|
||||||
# for order in orders:
|
for idx, order_position in enumerate(order_positions):
|
||||||
# currency = order.exchange_rate
|
# get currencyname to display:
|
||||||
# # get all items in the Order:
|
if order.exchange_rate is not None:
|
||||||
# order_positions = OrderPosition.objects.filter(order=order)
|
print('order.exchange_rate', order.exchange_rate, order.exchange_rate.id)
|
||||||
# if (order_positions.count()) > 0:
|
# get price of position in order and append to a list:
|
||||||
# order_position_list = list(order_positions)
|
rate = ExchangeRate.objects.get(id=order.exchange_rate.id)
|
||||||
# for idx, order_position in enumerate(order_position_list):
|
order_position.price = round(
|
||||||
# # get currencyname to display:
|
rate.exchange_rate_to_chf * order_position.price_in_chf,
|
||||||
# currency_name = ExchangeRate_name.objects.get(id=currency)
|
2)
|
||||||
# # get exchange_rate multiplyed:
|
currency_name = order.exchange_rate
|
||||||
# cart_position.article.price_in_chf = ExchangeRate.exchange(
|
else:
|
||||||
# currency,
|
currency_name = 'CHF'
|
||||||
# order_position.article.price_in_chf
|
order_position.price = order_position.price_in_chf
|
||||||
# )
|
order_position.position_price = order_position.price * Decimal.from_float(order_position.amount)
|
||||||
# order_position.calculate_position_price()
|
order_position_list[idx] = order_position
|
||||||
# totalprice_list.append(order_position.position_price)
|
totalprice_list.append(order_position.price)
|
||||||
# order_position_list[idx] = order_position
|
total = sum(totalprice_list)
|
||||||
#
|
return render(request, 'webshop/order.html', {
|
||||||
# total = sum(totalprice_list)
|
'order_position_list': order_position_list,
|
||||||
return render(request, 'webshop/order.html', {})
|
'currency_name': currency_name,
|
||||||
|
'total': total
|
||||||
|
})
|
||||||
|
|
Loading…
Reference in New Issue