add total summ

This commit is contained in:
Ivan Hörler 2018-02-04 21:48:29 +01:00
parent a01d08fded
commit 4f17a85dc7
2 changed files with 18 additions and 5 deletions

View File

@ -17,12 +17,21 @@
<td scope="col">
<a href="{% url 'details' article.id %}">
{{ article.article.name }}
</a></td>
</a>
</td>
<td scope="col">{{ article.article.stock }}</td>
<td scope="col">{{ article.amount }}</td>
<td scope="col">{{ article.article.price_in_chf }} {{ currency_name }}</td>
<td scope="col">
{{ article.article.price_in_chf }}
{{ currency_name }}
</td>
</tr>
{% endfor %}
<tr>
<td scope="col" colspan="5" class="text-right">
Total: {{ total }}
</td>
</tr>
</table>
{% else %}
<p class="alert">

View File

@ -9,10 +9,9 @@ from webshop.forms import RegistrationForm, AddToCartForm
from currencies.models import ExchangeRate, ExchangeRate_name
from currencies.forms import CurrenciesForm
from decimal import Decimal
# Create your views here.
def get_categories():
parent_category_list = Category.objects.filter(parent_category=None)
category_list = {}
@ -234,6 +233,7 @@ def cart(request):
message = ""
cart_id = False
articles_list = ""
total = Decimal(0)
if not 'currency' in request.session:
request.session['currency'] = None
@ -262,13 +262,17 @@ def cart(request):
currency, article.article.price_in_chf)
articles_list[idx] = article
currency_name = ExchangeRate_name.objects.get(id=currency)
article.price_in_chf = rate.exchange(currency, article.price_in_chf)
article.price_in_chf = rate.exchange(
currency,
article.price_in_chf)
total += article.price_in_chf
else:
articles = CartPosition.objects.filter(cart=cart_id)
articles_list = list(articles)
return render(request, 'webshop/cart.html',
{'articles_list': articles_list,
'total': total,
'currencies_form': currencies_form,
'article_view': article_view,
'currency_name': currency_name,