add art# and Price of all items

This commit is contained in:
Ivan Hörler 2018-02-11 18:19:21 +01:00
parent 8b6568c640
commit 775f32887a
2 changed files with 46 additions and 21 deletions

View File

@ -5,17 +5,20 @@
{% if articles_list %} {% if articles_list %}
<table class="table"> <table class="table">
<tr class="table_header"> <tr class="table_header">
<th scope="col">ID</th> <th scope="col">POS.</th>
<th scope="col">ART#</th>
<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">PRICE p.pce.</th>
<th scope="col">PRICE</th> <th scope="col">PRICE</th>
</tr> </tr>
{% for article in articles_list %} {% for article in articles_list %}
<tr class="table_content"> <tr class="table_content">
<td scope="col">{{ article.id }}</td> <td scope="col">{{ article.id }}</td>
<td scope="col">{{ article.article.id }}</td>
<td scope="col"> <td scope="col">
<a href="{% url 'details' article.id %}"> <a href="{% url 'details' article.article.id %}">
{{ article.article.name }} {{ article.article.name }}
</a> </a>
</td> </td>
@ -25,10 +28,11 @@
{{ article.article.price_in_chf }} {{ article.article.price_in_chf }}
{{ currency_name }} {{ currency_name }}
</td> </td>
<td scope="col">{{ totalprice_of_one }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
<tr> <tr>
<td scope="col" colspan="5" class="text-right"> <td scope="col" colspan="7" class="text-right">
Total: {{ total }} Total: {{ total }}
</td> </td>
</tr> </tr>

View File

@ -238,6 +238,8 @@ def cart(request):
if not 'currency' in request.session: if not 'currency' in request.session:
request.session['currency'] = None request.session['currency'] = None
else:
currency = request.session['currency']
if request.method == 'POST': if request.method == 'POST':
currencies_form = CurrenciesForm(request.POST) currencies_form = CurrenciesForm(request.POST)
@ -254,31 +256,50 @@ def cart(request):
cart_id = ShoppingCart.objects.get(user=request.user) cart_id = ShoppingCart.objects.get(user=request.user)
except Exception as e: except Exception as e:
message = "You have no items in the Basket" message = "You have no items in the Basket"
if cart_id and request.session['currency']:
if cart_id:
articles = CartPosition.objects.filter(cart=cart_id) articles = CartPosition.objects.filter(cart=cart_id)
articles_list = list(articles) articles_list = list(articles)
currency = request.session['currency']
for idx, article in enumerate(articles_list): for idx, article in enumerate(articles_list):
article.price_in_chf = rate.exchange( print(article, idx)
currency, article.article.price_in_chf) if currency is not None:
article.price_in_chf = rate.exchange(
currency, article.article.price_in_chf)
currency_name = ExchangeRate_name.objects.get(id=currency)
article.price_in_chf = rate.exchange(
currency,
article.price_in_chf)
amount = article.amount
totalprice_of_one = Decimal(amount) * article.article.price_in_chf
articles_list[idx] = article articles_list[idx] = article
currency_name = ExchangeRate_name.objects.get(id=currency)
article.price_in_chf = rate.exchange( prices_in_cart.append(article.article.price_in_chf)
currency,
article.price_in_chf) # if cart_id and request.session['currency']:
else: # articles = CartPosition.objects.filter(cart=cart_id)
cart_position = CartPosition.objects.filter(cart=cart_id) # articles_list = list(articles)
if len(cart_position) > 0: # currency = request.session['currency']
cart_position_list = list(cart_position) # for idx, article in enumerate(articles_list):
for idx, cart_position in enumerate(cart_position_list): # article.price_in_chf = rate.exchange(
prices_in_cart.append(cart_position.article.price_in_chf) # currency, article.article.price_in_chf)
prices_sum = sum(prices_in_cart) # articles_list[idx] = article
prices_length = len(prices_in_cart) # currency_name = ExchangeRate_name.objects.get(id=currency)
total = prices_sum / prices_length # article.price_in_chf = rate.exchange(
articles_list = cart_position_list # currency,
# article.price_in_chf)
# prices_in_cart.append(article.article.price_in_chf)
#
# if cart_id:
# articles = CartPosition.objects.filter(cart=cart_id)
# articles_list = list(articles)
# for idx, article in enumerate(articles_list):
# prices_in_cart.append(article.article.price_in_chf)
total = sum(prices_in_cart)
return render(request, 'webshop/cart.html', return render(request, 'webshop/cart.html',
{'articles_list': articles_list, {'articles_list': articles_list,
'totalprice_of_one': totalprice_of_one,
'total': total, 'total': total,
'currencies_form': currencies_form, 'currencies_form': currencies_form,
'article_view': article_view, 'article_view': article_view,