forked from data.coop/membersystem
Add details to order page
This commit is contained in:
parent
6bf42ecba3
commit
e2f4a66645
|
@ -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),
|
||||||
|
),
|
||||||
|
]
|
|
@ -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'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -88,12 +88,12 @@ class Order(CreatedModifiedAbstract):
|
||||||
@property
|
@property
|
||||||
def total(self) -> Money:
|
def total(self) -> Money:
|
||||||
"""Return the total price of the order (excl VAT)."""
|
"""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
|
@property
|
||||||
def total_vat(self) -> Money:
|
def total_vat(self) -> Money:
|
||||||
"""Return the total VAT of the order."""
|
"""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
|
@property
|
||||||
def total_with_vat(self) -> Money:
|
def total_with_vat(self) -> Money:
|
||||||
|
@ -133,14 +133,24 @@ class OrderProduct(CreatedModifiedAbstract):
|
||||||
This includes pricing information.
|
This includes pricing information.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
order = models.ForeignKey(Order, on_delete=models.CASCADE, related_name="order_products")
|
order = models.ForeignKey(Order, on_delete=models.CASCADE, related_name="items")
|
||||||
product = models.ForeignKey(Product, related_name="order_products", on_delete=models.PROTECT)
|
product = models.ForeignKey(Product, on_delete=models.PROTECT)
|
||||||
price = MoneyField(max_digits=16, decimal_places=2)
|
price = MoneyField(max_digits=16, decimal_places=2)
|
||||||
vat = 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:
|
def __str__(self) -> str:
|
||||||
return f"{self.product.name}"
|
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):
|
class Payment(CreatedModifiedAbstract):
|
||||||
"""A payment is a transaction that is made to pay for an order."""
|
"""A payment is a transaction that is made to pay for an order."""
|
||||||
|
|
|
@ -9,5 +9,40 @@
|
||||||
|
|
||||||
<div class="content-view">
|
<div class="content-view">
|
||||||
<h2>Order: {{ order.id }}</h2>
|
<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>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
21
src/membership/migrations/0008_alter_membership_user.py
Normal file
21
src/membership/migrations/0008_alter_membership_user.py
Normal 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),
|
||||||
|
),
|
||||||
|
]
|
Loading…
Reference in a new issue