add profile oders in tableform with
This commit is contained in:
parent
c74438904c
commit
f6ae6cf872
File diff suppressed because it is too large
Load Diff
|
@ -100,6 +100,10 @@ class OrderPosition(models.Model):
|
||||||
validators=[MinValueValidator(
|
validators=[MinValueValidator(
|
||||||
Decimal('0.00'))])
|
Decimal('0.00'))])
|
||||||
|
|
||||||
|
def calculate_position_price(self):
|
||||||
|
decimal_amount = Decimal.from_float(self.amount)
|
||||||
|
self.position_price = decimal_amount * self.article.price_in_chf
|
||||||
|
|
||||||
|
|
||||||
class ShoppingCart(models.Model):
|
class ShoppingCart(models.Model):
|
||||||
""" Cart to User Relationships """
|
""" Cart to User Relationships """
|
||||||
|
|
|
@ -34,8 +34,8 @@
|
||||||
<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>
|
||||||
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
{% endfor %}
|
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>
|
<p>
|
||||||
you don't have Ordered anything yet.
|
you don't have Ordered anything yet.
|
||||||
|
|
|
@ -171,33 +171,35 @@ def profile(request):
|
||||||
orders = Order.objects.filter(user=request.user)
|
orders = Order.objects.filter(user=request.user)
|
||||||
orders_list = list(orders)
|
orders_list = list(orders)
|
||||||
for idx1, order in enumerate(orders_list):
|
for idx1, order in enumerate(orders_list):
|
||||||
currency = order.exchange_rate
|
|
||||||
print('order:', order, 'currency:', currency)
|
|
||||||
# get all items in the Order:
|
# get all items in the Order:
|
||||||
order_positions = OrderPosition.objects.get(order=order)
|
order_positions = OrderPosition.objects.filter(order=order)
|
||||||
if (order_positions.count()) > 0:
|
if (order_positions.count()) > 0:
|
||||||
order_position_list = list(order_positions)
|
order_position_list = list(order_positions)
|
||||||
print('order_position_list:', order_position_list)
|
|
||||||
for idx2, order_position in enumerate(order_position_list):
|
for idx2, order_position in enumerate(order_position_list):
|
||||||
# get currencyname to display:
|
# get currencyname to display:
|
||||||
currency_name = ExchangeRate_name.objects.get(id=currency)
|
if order.exchange_rate is not None:
|
||||||
# get exchange_rate multiplyed:
|
print('order.exchange_rate', order.exchange_rate, order.exchange_rate.id)
|
||||||
order_position.article.price_in_chf = ExchangeRate.exchange(
|
# get price of position in order and append to a list:
|
||||||
currency,
|
rate = ExchangeRate.objects.get(id=order.exchange_rate.id)
|
||||||
order_position.article.price_in_chf
|
order_position.price_in_chf = round(
|
||||||
)
|
rate.exchange_rate_to_chf * order_position.price_in_chf,
|
||||||
# get price of position in order and append to a summed list:
|
2)
|
||||||
order_position.calculate_position_price()
|
currency_name = order.exchange_rate
|
||||||
totalprice_list.append(order_position.position_price)
|
else:
|
||||||
|
currency_name = 'CHF'
|
||||||
|
totalprice_list.append(order_position.price_in_chf)
|
||||||
order_position_list[idx2] = order_position
|
order_position_list[idx2] = order_position
|
||||||
|
total = sum(totalprice_list)
|
||||||
currency_list.append(currency_name)
|
currency_list.append(currency_name)
|
||||||
total = sum(totalprice_list)
|
|
||||||
total_list.append(total)
|
total_list.append(total)
|
||||||
order_positions_count = order_positions.count()
|
order_positions_count = order_positions.count()
|
||||||
order_positions_count_list.append(order_positions_count)
|
order_positions_count_list.append(order_positions_count)
|
||||||
orders_list[idx1] = order
|
orders_list[idx1] = order
|
||||||
order_list_zip = zip(orders_list, order_positions_count_list, total, currency_name)
|
order_list_zip = zip(orders_list,
|
||||||
assert False
|
order_positions_count_list,
|
||||||
|
total_list,
|
||||||
|
currency_list)
|
||||||
|
# assert False
|
||||||
return render(request, 'registration/profile.html',
|
return render(request, 'registration/profile.html',
|
||||||
{'person': person,
|
{'person': person,
|
||||||
'order_list_zip': order_list_zip,
|
'order_list_zip': order_list_zip,
|
||||||
|
|
Loading…
Reference in New Issue