Add details to order page
Some checks failed
continuous-integration/drone/pr Build is failing

This commit is contained in:
Benjamin Bach 2024-07-28 23:27:53 +02:00
parent 6bf42ecba3
commit e2f4a66645
No known key found for this signature in database
GPG key ID: 486F0D69C845416E
5 changed files with 116 additions and 4 deletions

View file

@ -0,0 +1,22 @@
# Generated by Django 5.1b1 on 2024-07-28 21:20
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('accounting', '0007_rename_user_order_member'),
]
operations = [
migrations.AlterModelOptions(
name='orderproduct',
options={'verbose_name': 'ordered products'},
),
migrations.AddField(
model_name='orderproduct',
name='quantity',
field=models.PositiveSmallIntegerField(default=1),
),
]

View file

@ -0,0 +1,24 @@
# Generated by Django 5.1b1 on 2024-07-28 21:27
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('accounting', '0008_alter_orderproduct_options_orderproduct_quantity'),
]
operations = [
migrations.AlterField(
model_name='orderproduct',
name='order',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='items', to='accounting.order'),
),
migrations.AlterField(
model_name='orderproduct',
name='product',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='accounting.product'),
),
]

View file

@ -88,12 +88,12 @@ class Order(CreatedModifiedAbstract):
@property
def total(self) -> Money:
"""Return the total price of the order (excl VAT)."""
return sum(order_product.price for order_product in self.order_products)
return sum(item.price * item.quantity for item in self.items.all())
@property
def total_vat(self) -> Money:
"""Return the total VAT of the order."""
return sum(order_product.vat for order_product in self.order_products)
return sum(item.vat * item.quantity for item in self.items.all())
@property
def total_with_vat(self) -> Money:
@ -133,14 +133,24 @@ class OrderProduct(CreatedModifiedAbstract):
This includes pricing information.
"""
order = models.ForeignKey(Order, on_delete=models.CASCADE, related_name="order_products")
product = models.ForeignKey(Product, related_name="order_products", on_delete=models.PROTECT)
order = models.ForeignKey(Order, on_delete=models.CASCADE, related_name="items")
product = models.ForeignKey(Product, on_delete=models.PROTECT)
price = MoneyField(max_digits=16, decimal_places=2)
vat = MoneyField(max_digits=16, decimal_places=2)
quantity = models.PositiveSmallIntegerField(default=1)
class Meta:
verbose_name = _("ordered product")
verbose_name_plural = _("ordered products")
def __str__(self) -> str:
return f"{self.product.name}"
@property
def total_with_vat(self) -> Money:
"""Total price of this item."""
return (self.price + self.vat) * self.quantity
class Payment(CreatedModifiedAbstract):
"""A payment is a transaction that is made to pay for an order."""

View file

@ -9,5 +9,40 @@
<div class="content-view">
<h2>Order: {{ order.id }}</h2>
<p>
{% trans "Ordered" %}: {{ order.created }}<br>
{% trans "Status" %}: {{ order.is_paid|yesno:_("paid,unpaid") }}
</p>
<table class="table">
<thead>
<tr>
<th>{% trans "Item" %}</th>
<th>{% trans "Quantity" %}</th>
<th>{% trans "Price" %}</th>
<th>{% trans "VAT" %}</th>
<th>{% trans "Total" %}</th>
</tr>
</thead>
<tbody>
{% for item in order.items.all %}
<tr>
<td>{{ item.product.name }}</td>
<td>{{ item.quantity }}</td>
<td>{{ item.price }}</td>
<td>{{ item.vat }}</td>
<td>{{ item.total_with_vat }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<h2>{% trans "Total price" %}: {{ order.total_with_vat }}</h2>
<p>
<a href="" class="button">{% trans "Pay now" %}</a>
</p>
</div>
{% endblock %}

View file

@ -0,0 +1,21 @@
# Generated by Django 5.1b1 on 2024-07-28 21:20
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('membership', '0007_membership_activated_membership_activated_on_and_more'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.AlterField(
model_name='membership',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='memberships', to=settings.AUTH_USER_MODEL),
),
]