BillingAddress: make mget_preferred_address a classmethod

This commit is contained in:
Nico Schottelius 2020-05-02 21:20:14 +02:00
parent 736fe27493
commit 4097c2ce13

View file

@ -455,9 +455,9 @@ class BillingAddress(models.Model):
def get_addresses_for(user):
return BillingAddress.objects.filter(owner=user)
@staticmethod
def get_preferred_address_for(user):
addresses = get_addresses_for(user)
@classmethod
def get_preferred_address_for(cls, user):
addresses = cls.get_addresses_for(user)
if len(addresses) == 0:
return None
else:
@ -927,7 +927,7 @@ class Product(UncloudModel):
billing_address = BillingAddress.get_preferred_address_for(self.owner)
if not billing_address:
raise ValidationError("Cannot create order without a billing address")
raise ValidationError("Cannot order without a billing address")
self.order = Order(owner=self.owner,
billing_address=billing_address)