- {{ orp.product.name }}
+ {{ opr.product.name }}
|
- {{ orp.quantity }}
+ {{ opr.quantity }}
|
- {{ orp.product.price|currency }}
+ {{ opr.product.price|currency }}
|
- {{ orp.total|currency }}
+ {{ opr.total|currency }}
{% endfor %}
diff --git a/src/shop/tests.py b/src/shop/tests.py
index e0b78bab..cf289af0 100644
--- a/src/shop/tests.py
+++ b/src/shop/tests.py
@@ -383,7 +383,7 @@ class TestTicketCreation(TestCase):
OrderProductRelationFactory(order=order, product=product, quantity=5)
order.mark_as_paid()
self.assertEquals(
- ShopTicket.objects.filter(product=product, order=order).count(), 5
+ ShopTicket.objects.filter(product=product, opr__order=order).count(), 5
)
def test_single_ticket_created(self):
@@ -394,5 +394,5 @@ class TestTicketCreation(TestCase):
OrderProductRelationFactory(order=order, product=product, quantity=5)
order.mark_as_paid()
self.assertEquals(
- ShopTicket.objects.filter(product=product, order=order).count(), 1
+ ShopTicket.objects.filter(product=product, opr__order=order).count(), 1
)
diff --git a/src/tickets/admin.py b/src/tickets/admin.py
index a14c0e37..bb23291a 100644
--- a/src/tickets/admin.py
+++ b/src/tickets/admin.py
@@ -1,7 +1,5 @@
from django.contrib import admin
-from shop.models import OrderProductRelation
-
from .models import DiscountTicket, ShopTicket, SponsorTicket, TicketType
@@ -57,18 +55,18 @@ class ShopTicketAdmin(BaseTicketAdmin):
"product_quantity",
]
- list_filter = ["ticket_type__camp", "used", "ticket_type", "order", "product"]
+ list_filter = ["ticket_type__camp", "used", "ticket_type", "opr__order", "product"]
- search_fields = ["uuid", "order__id", "order__user__email", "name", "email"]
+ search_fields = [
+ "uuid",
+ "opr__order__id",
+ "opr__order__user__email",
+ "name",
+ "email",
+ ]
def product_quantity(self, ticket):
- orp = OrderProductRelation.objects.get(
- product=ticket.product, order=ticket.order
- )
-
- return (
- str(orp.quantity) if ticket.ticket_type.single_ticket_per_product else "1"
- )
+ return str(ticket.opr.quantity)
product_quantity.short_description = "Quantity"
diff --git a/src/tickets/migrations/0015_shopticket_opr.py b/src/tickets/migrations/0015_shopticket_opr.py
new file mode 100644
index 00000000..d3c7b487
--- /dev/null
+++ b/src/tickets/migrations/0015_shopticket_opr.py
@@ -0,0 +1,25 @@
+# Generated by Django 3.2.5 on 2021-07-26 19:37
+
+import django.db.models.deletion
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("shop", "0064_add_product_comment_and_cost"),
+ ("tickets", "0014_auto_20190803_2241"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="shopticket",
+ name="opr",
+ field=models.ForeignKey(
+ null=True,
+ on_delete=django.db.models.deletion.PROTECT,
+ related_name="shoptickets",
+ to="shop.orderproductrelation",
+ ),
+ ),
+ ]
diff --git a/src/tickets/migrations/0016_populate_opr.py b/src/tickets/migrations/0016_populate_opr.py
new file mode 100644
index 00000000..13d6a686
--- /dev/null
+++ b/src/tickets/migrations/0016_populate_opr.py
@@ -0,0 +1,21 @@
+# Generated by Django 3.2.5 on 2021-07-26 19:38
+
+from django.db import migrations
+
+
+def populate_opr(apps, schema_editor):
+ OrderProductRelation = apps.get_model("shop", "OrderProductRelation")
+ ShopTicket = apps.get_model("tickets", "ShopTicket")
+
+ for st in ShopTicket.objects.all():
+ st.opr = OrderProductRelation.objects.get(product=st.product, order=st.order)
+ st.save()
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("tickets", "0015_shopticket_opr"),
+ ]
+
+ operations = [migrations.RunPython(populate_opr)]
diff --git a/src/tickets/migrations/0017_shopticket_opr_not_null.py b/src/tickets/migrations/0017_shopticket_opr_not_null.py
new file mode 100644
index 00000000..90e92b4d
--- /dev/null
+++ b/src/tickets/migrations/0017_shopticket_opr_not_null.py
@@ -0,0 +1,24 @@
+# Generated by Django 3.2.5 on 2021-07-26 19:52
+
+import django.db.models.deletion
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("shop", "0064_add_product_comment_and_cost"),
+ ("tickets", "0016_populate_opr"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="shopticket",
+ name="opr",
+ field=models.ForeignKey(
+ on_delete=django.db.models.deletion.PROTECT,
+ related_name="shoptickets",
+ to="shop.orderproductrelation",
+ ),
+ ),
+ ]
diff --git a/src/tickets/migrations/0018_remove_shopticket_order.py b/src/tickets/migrations/0018_remove_shopticket_order.py
new file mode 100644
index 00000000..8caea32b
--- /dev/null
+++ b/src/tickets/migrations/0018_remove_shopticket_order.py
@@ -0,0 +1,17 @@
+# Generated by Django 3.2.5 on 2021-07-26 20:00
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("tickets", "0017_shopticket_opr_not_null"),
+ ]
+
+ operations = [
+ migrations.RemoveField(
+ model_name="shopticket",
+ name="order",
+ ),
+ ]
diff --git a/src/tickets/models.py b/src/tickets/models.py
index dad743cd..92524c90 100644
--- a/src/tickets/models.py
+++ b/src/tickets/models.py
@@ -9,7 +9,6 @@ from django.db import models
from django.urls import reverse_lazy
from django.utils.translation import ugettext_lazy as _
-from shop.models import OrderProductRelation
from utils.models import CampRelatedModel, UUIDModel
from utils.pdf import generate_pdf_letter
@@ -104,7 +103,7 @@ class BaseTicket(CampRelatedModel, UUIDModel):
formatdict = {"ticket": self}
if self.ticket_type.single_ticket_per_product and self.shortname == "shop":
- formatdict["quantity"] = self.orp.quantity
+ formatdict["quantity"] = self.opr.quantity
return generate_pdf_letter(
filename="{}_ticket_{}.pdf".format(self.shortname, self.pk),
@@ -138,11 +137,12 @@ class DiscountTicket(BaseTicket):
class ShopTicket(BaseTicket):
- """Why doesn't this have an FK to OrderProductRelation instead of the fk to Order?"""
-
- order = models.ForeignKey(
- "shop.Order", related_name="shoptickets", on_delete=models.PROTECT
+ opr = models.ForeignKey(
+ "shop.OrderProductRelation",
+ related_name="shoptickets",
+ on_delete=models.PROTECT,
)
+
product = models.ForeignKey("shop.Product", on_delete=models.PROTECT)
name = models.CharField(
@@ -178,5 +178,5 @@ class ShopTicket(BaseTicket):
return "shop"
@property
- def orp(self):
- return OrderProductRelation.objects.get(product=self.product, order=self.order)
+ def order(self):
+ return self.opr.order
diff --git a/src/tickets/tests.py b/src/tickets/tests.py
index 7a44a7e4..b6fcb3f2 100644
--- a/src/tickets/tests.py
+++ b/src/tickets/tests.py
@@ -10,12 +10,11 @@ class TicketTests(TestCase):
def test_correct_token_and_badge_token_are_different(self):
ticket_type = TicketTypeFactory()
-
- orp = OrderProductRelationFactory()
+ opr = OrderProductRelationFactory()
shop_ticket = ShopTicket.objects.create(
ticket_type=ticket_type,
- product=orp.product,
- order=orp.order,
+ product=opr.product,
+ opr=opr,
)
self.assertNotEqual(shop_ticket.token, shop_ticket.badge_token)
|