diff --git a/aleksis/apps/tezor/models/invoice.py b/aleksis/apps/tezor/models/invoice.py index 18c33aec05b26b6be2317594ed96fd6552e7595f..03978c83b39081ca4886364def28653949ad2fff 100644 --- a/aleksis/apps/tezor/models/invoice.py +++ b/aleksis/apps/tezor/models/invoice.py @@ -83,6 +83,28 @@ class Invoice(BasePayment, PureDjangoModel): ) items = models.ManyToManyField("InvoiceItem", verbose_name=_("Invoice items")) + def save(self, *args, **kwargs): + if self.person: + person = self.person + elif self.for_object and getattr(self.for_object, "person", None): + person = self.for_object.person + else: + person = None + + if person: + 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}" + if not self.billing_city: + self.billing_city = person.place + if not self.billing_postcode: + self.billing_postcode = person.postal_code + + super().save(*args, **kwargs) + @classmethod def get_variant_choices(cls): choices = []