Skip to content
Snippets Groups Projects
Verified Commit 7d3aeb81 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Auto-fill billing details from person if not in invoice

parent 6fad47f4
No related branches found
No related tags found
No related merge requests found
......@@ -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 = []
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment