From 2a9baceb082593a56cfdacf8e3d177417d0d971d Mon Sep 17 00:00:00 2001
From: magicfelix <felix@felix-zauberer.de>
Date: Thu, 27 Mar 2025 16:45:12 +0100
Subject: [PATCH] Adapt to new Address model

---
 aleksis/apps/tezor/models/invoice.py | 13 ++++++++++---
 aleksis/apps/tezor/signals.py        | 12 +++++++++---
 2 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/aleksis/apps/tezor/models/invoice.py b/aleksis/apps/tezor/models/invoice.py
index 550cbe0..d5b3896 100644
--- a/aleksis/apps/tezor/models/invoice.py
+++ b/aleksis/apps/tezor/models/invoice.py
@@ -113,16 +113,23 @@ class Invoice(BasePayment, PureDjangoModel):
 
         if person:
             self.person = person
+
+            address = person.addresses.first()
+            street = address.street if address is not None else ""
+            housenumber = address.housenumber if address is not None else ""
+            postal_code = address.postal_code if address is not None else ""
+            place = address.place if address is not None else ""
+
             if not self.billing_last_name:
                 self.billing_last_name = person.last_name
             if not self.billing_first_name:
                 self.billing_first_name = person.first_name
             if not self.billing_address_1:
-                self.billing_address_1 = f"{person.street} {person.housenumber}"
+                self.billing_address_1 = f"{street} {housenumber}"
             if not self.billing_city:
-                self.billing_city = person.place
+                self.billing_city = place
             if not self.billing_postcode:
-                self.billing_postcode = person.postal_code
+                self.billing_postcode = postal_code
 
         super().save(*args, **kwargs)
 
diff --git a/aleksis/apps/tezor/signals.py b/aleksis/apps/tezor/signals.py
index ab72a66..e0b3113 100644
--- a/aleksis/apps/tezor/signals.py
+++ b/aleksis/apps/tezor/signals.py
@@ -10,11 +10,17 @@ from .models.invoice import Invoice
 @receiver(post_save, sender=Person)
 def update_on_person_change(sender, instance, **kwargs):
     if get_site_preferences()["payments__update_on_person_change"]:
+        address = instance.addresses.first()
+        street = address.street if address is not None else ""
+        housenumber = address.housenumber if address is not None else ""
+        postal_code = address.postal_code if address is not None else ""
+        place = address.place if address is not None else ""
+
         Invoice.objects.filter(person=instance, status__in=("waiting", "input", "preauth")).update(
             billing_email=instance.email,
             billing_first_name=instance.first_name,
             billing_last_name=instance.last_name,
-            billing_address_1=f"{instance.street} {instance.housenumber}",
-            billing_postcode=instance.postal_code,
-            billing_city=instance.place,
+            billing_address_1=f"{street} {housenumber}",
+            billing_postcode=postal_code,
+            billing_city=place,
         )
-- 
GitLab