From 1751df82068daae6676e3d970132d93d6e64aac7 Mon Sep 17 00:00:00 2001
From: Dominik George <dominik.george@teckids.org>
Date: Fri, 11 Mar 2022 23:27:09 +0100
Subject: [PATCH] Move payment variant icon/name lookup to model

---
 aleksis/apps/tezor/models/invoice.py                | 13 +++++++++++++
 .../apps/tezor/templates/tezor/invoice/full.html    |  8 ++------
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/aleksis/apps/tezor/models/invoice.py b/aleksis/apps/tezor/models/invoice.py
index 84b4413..2cdc04a 100644
--- a/aleksis/apps/tezor/models/invoice.py
+++ b/aleksis/apps/tezor/models/invoice.py
@@ -33,6 +33,13 @@ class InvoiceGroup(ExtensibleModel):
 
 
 class Invoice(BasePayment, PureDjangoModel):
+    VARIANT_DISPLAY = {
+        "paypal": (_("PayPal"), "logos:paypal"),
+        "sofort": (_("Klarna / Sofort"), "simple-icons:klarna"),
+        "pledge": (_("Payment pledge / manual payment"), "mdi:hand-coin"),
+        "sdd": (_("SEPA Direct Debit"), "mdi:bank-transfer"),
+    }
+
     group = models.ForeignKey(
         InvoiceGroup, verbose_name=_("Invoice group"), related_name="invoices", on_delete=models.SET_NULL, null=True
     )
@@ -43,6 +50,12 @@ class Invoice(BasePayment, PureDjangoModel):
     for_object_id = models.PositiveIntegerField()
     for_object = GenericForeignKey("for_content_type", "for_object_id")
 
+    def get_variant_name(self):
+        return self.__class__.VARIANT_DISPLAY[self.variant][0]
+
+    def get_variant_icon(self):
+        return self.__class__.VARIANT_DISPLAY[self.variant][1]
+
     def get_purchased_items(self):
         return self.for_object.get_purchased_items()
 
diff --git a/aleksis/apps/tezor/templates/tezor/invoice/full.html b/aleksis/apps/tezor/templates/tezor/invoice/full.html
index 955d195..e8fc99b 100644
--- a/aleksis/apps/tezor/templates/tezor/invoice/full.html
+++ b/aleksis/apps/tezor/templates/tezor/invoice/full.html
@@ -64,14 +64,10 @@
             <table class="highlight">
               <tr>
                 <td>
-                  {% if object.variant == "paypal" %}
-                  <i class="material-icons iconify" data-icon="logos:paypal"></i>
-                  {% elif object.variant == "sofort" %}
-                  <i class="material-icons iconify" data-icon="simple-icons:klarna"></i>
-                  {% endif %}
+                  <i class="material-icons iconify" data-icon="{{ object.get_variant_icon }}"></i>
                 </td>
                 <td>
-                  {{ object.variant }}
+                  {{ object.get_variant_name }}
                 </td>
               </tr>
               <tr>
-- 
GitLab