Fix products not available for purchased anymore

This commit is contained in:
Víðir Valberg Guðmundsson 2016-08-25 00:10:13 +02:00
parent ffb7fb38e4
commit 77422417ec
2 changed files with 14 additions and 0 deletions

View file

@ -282,6 +282,16 @@ class Product(CreatedUpdatedModel, UUIDModel):
now = timezone.now()
return now in self.available_in
def is_old(self):
now = timezone.now()
if hasattr(self.available_in, 'upper') and self.available_in.upper:
return self.available_in.upper < now
return False
def is_upcoming(self):
now = timezone.now()
return self.available_in.lower > now
class OrderProductRelation(CreatedUpdatedModel):
order = models.ForeignKey('shop.Order')

View file

@ -40,8 +40,12 @@
{% else %}
<p>
{% if product.is_old %}
This product is not available anymore.
{% elif product.is_upcoming %}
This product is available from
{{ product.available_in.lower|date:"Y-m-d H:i T" }}
{% endif %}
</p>
{% endif %}