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): def get_addresses_for(user):
return BillingAddress.objects.filter(owner=user) return BillingAddress.objects.filter(owner=user)
@staticmethod @classmethod
def get_preferred_address_for(user): def get_preferred_address_for(cls, user):
addresses = get_addresses_for(user) addresses = cls.get_addresses_for(user)
if len(addresses) == 0: if len(addresses) == 0:
return None return None
else: else:
@ -927,7 +927,7 @@ class Product(UncloudModel):
billing_address = BillingAddress.get_preferred_address_for(self.owner) billing_address = BillingAddress.get_preferred_address_for(self.owner)
if not billing_address: 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, self.order = Order(owner=self.owner,
billing_address=billing_address) billing_address=billing_address)