correct the order view
This commit is contained in:
parent
9f89b2681a
commit
7e8ac5077e
|
@ -14,7 +14,7 @@
|
||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<h3>List of Items in your Order:</h3>
|
<h3>List of Items in your Order:</h3>
|
||||||
{% if order_position_list_zip %}
|
{% if order_position_list %}
|
||||||
<table class="table price-table">
|
<table class="table price-table">
|
||||||
<tr class="table_header">
|
<tr class="table_header">
|
||||||
<th scope="col">POS.</th>
|
<th scope="col">POS.</th>
|
||||||
|
@ -22,10 +22,9 @@
|
||||||
<th scope="col">NAME</th>
|
<th scope="col">NAME</th>
|
||||||
<th scope="col">STOCK</th>
|
<th scope="col">STOCK</th>
|
||||||
<th scope="col">AMOUNT</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>
|
<th scope="col" class="price-label">POSITION PRICE</th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for order_position, price, pos_price in order_position_list_zip %}
|
{% for order_position in order_position_list %}
|
||||||
<tr class="table_content">
|
<tr class="table_content">
|
||||||
<td scope="col">{{ order_position.id }}</td>
|
<td scope="col">{{ order_position.id }}</td>
|
||||||
<td scope="col">{{ order_position.article.id }}</td>
|
<td scope="col">{{ order_position.article.id }}</td>
|
||||||
|
@ -37,16 +36,12 @@
|
||||||
<td scope="col">{{ order_position.article.stock }}</td>
|
<td scope="col">{{ order_position.article.stock }}</td>
|
||||||
<td scope="col">{{ order_position.amount }}</td>
|
<td scope="col">{{ order_position.amount }}</td>
|
||||||
<td scope="col" class="price-value">
|
<td scope="col" class="price-value">
|
||||||
{{ price }}
|
{{ order_postion.price_in_chf }} {{ currency_name }}
|
||||||
{{ currency_name }}
|
|
||||||
</td>
|
|
||||||
<td scope="col" class="price-value">
|
|
||||||
{{ pos_price }} {{ currency_name }}
|
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<tr>
|
<tr>
|
||||||
<td scope="col" colspan="5"class="text-right">
|
<td scope="col" colspan="4"class="text-right">
|
||||||
<td scope="col" class="price-value">
|
<td scope="col" class="price-value">
|
||||||
<dl><dt>Total:</dl></dt></td>
|
<dl><dt>Total:</dl></dt></td>
|
||||||
<td scope="col" class="price-value">
|
<td scope="col" class="price-value">
|
||||||
|
|
|
@ -420,9 +420,8 @@ def checkout(request):
|
||||||
|
|
||||||
|
|
||||||
def order(request, order_id):
|
def order(request, order_id):
|
||||||
price_list = []
|
|
||||||
totalprice_list = []
|
totalprice_list = []
|
||||||
order_position_list_zip = []
|
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:
|
||||||
|
@ -436,35 +435,26 @@ def order(request, order_id):
|
||||||
'delete'
|
'delete'
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
message = """something whent wrong.
|
message = """Something went wrong.
|
||||||
We cold not empty your cart. """
|
We could not empty your cart. """
|
||||||
order = Order.objects.get(id=order_id)
|
order = Order.objects.get(id=order_id)
|
||||||
order_positions = OrderPosition.objects.filter(order=order_id)
|
order_positions = OrderPosition.objects.filter(order=order_id)
|
||||||
|
|
||||||
|
if order.exchange_rate is not None:
|
||||||
|
currency_name = order.exchange_rate.name
|
||||||
|
else:
|
||||||
|
currency_name = 'CHF'
|
||||||
|
|
||||||
if (order_positions.count()) > 0:
|
if (order_positions.count()) > 0:
|
||||||
order_position_list = list(order_positions)
|
order_position_list = list(order_positions)
|
||||||
for idx, order_position in enumerate(order_positions):
|
for idx, order_position in enumerate(order_position_list):
|
||||||
# get currencyname to display:
|
# get currencyname to display:
|
||||||
if order.exchange_rate is not None:
|
totalprice_list.append(order_position.price_in_chf)
|
||||||
# get price of position in order and append to a list:
|
print(order_position.price_in_chf)
|
||||||
rate = ExchangeRate.objects.get(id=order.exchange_rate.id)
|
|
||||||
price = round(
|
|
||||||
rate.exchange_rate_to_chf * order_position.price_in_chf,
|
|
||||||
2)
|
|
||||||
currency_name = order.exchange_rate.name
|
|
||||||
else:
|
|
||||||
currency_name = 'CHF'
|
|
||||||
price = order_position.price_in_chf
|
|
||||||
position_price = price * Decimal.from_float(order_position.amount)
|
|
||||||
order_position_list[idx] = order_position
|
|
||||||
price_list.append(price)
|
|
||||||
totalprice_list.append(position_price)
|
|
||||||
total = sum(totalprice_list)
|
total = sum(totalprice_list)
|
||||||
order_position_list_zip = zip(order_position_list,
|
|
||||||
price_list,
|
|
||||||
totalprice_list)
|
|
||||||
return render(request, 'webshop/order.html', {
|
return render(request, 'webshop/order.html', {
|
||||||
'order': order,
|
'order': order,
|
||||||
'order_position_list_zip': order_position_list_zip,
|
'order_position_list': order_positions,
|
||||||
'total': total,
|
'total': total,
|
||||||
'currency_name': currency_name,
|
'currency_name': currency_name,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue