We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Cannot view inventory
## What kind of an issue is this?

- [x] Bug report


## What is the expected behaviour?

To be able to view the inventory

## What is the current behaviour?

A 500 error, with the message `TypeError: '>=' not supported between instances of 'datetime.date' and 'NoneType'`. 


## How do you reproduce this problem? 

Make sure the inventory is not empty, and try to visit it.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `apps/inventory/models.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 
3 from django.conf import settings
4 from django.core.mail import EmailMessage
5 from django.db import models
6 from django.utils import timezone
7 from django.utils.translation import ugettext as _
8 
9 from apps.gallery.models import ResponsiveImage
10 
11 
12 class ItemCategory(models.Model):
13     name = models.CharField(_("Kategori"), max_length=50)
14 
15     def __str__(self):
16         return self.name
17 
18 
19 class Item(models.Model):
20 
21     name = models.CharField(_("Varetype"), max_length=50)
22     description = models.CharField(_("Beskrivelse"), max_length=50, null=True, blank=True)
23     price = models.IntegerField(_("Pris"), null=True, blank=True)
24     available = models.BooleanField(_("Til salgs"), default=False)
25     category = models.ForeignKey(ItemCategory, verbose_name=_("Kategori"),
26                                  related_name="category", null=True, blank=True)
27     image = models.ForeignKey(ResponsiveImage, null=True, blank=True, default=None)
28 
29     @property
30     def oldest_expiration_date(self):
31         batches = self.batches.all().order_by("expiration_date")
32         if batches:
33             return batches[0].expiration_date
34         else:
35             return None
36 
37     @property
38     def last_added(self):
39         batches = self.batches.all().order_by("-date_added")
40         if batches:
41             return batches[0].date_added
42         else:
43             return None
44 
45     def oldest_batch(self):
46         batches = self.batches.filter(amount__gt=0).order_by("date_added")
47         if batches:
48             return batches[0]
49         else:
50             return None
51 
52     @property
53     def total_amount(self):
54         return sum([batch.amount for batch in self.batches.all()])
55 
56     @property
57     def has_expired_batch(self):
58         if timezone.now().date() >= self.oldest_expiration_date:
59             return True
60         return False
61 
62     def reduce_stock(self, amount):
63         """
64         Makes an assumption that the oldest batches are sold first and reduce them first.
65         """
66 
67         oldest_batch = self.oldest_batch()
68 
69         if oldest_batch:
70             if oldest_batch.amount > amount:
71                 oldest_batch.amount = oldest_batch.amount - amount
72                 oldest_batch.save()
73             else:
74                 diff = amount - oldest_batch.amount
75                 oldest_batch.amount = 0
76                 oldest_batch.save()
77                 self.reduce_stock(diff)
78 
79         self.handle_notifications(amount)
80 
81     def handle_notifications(self, amount):
82 
83         # Send one notification when the stock goes to or below 10
84         if self.total_amount <= 10 and self.total_amount + amount > 10:
85             message = "Det er kun " + str(self.total_amount) + " igjen av " + str(self.name) + \
86                       " på kontoret.\n\n" \
87                       "Dette er en automatisk generert melding og antallet kan være noe feil."
88 
89             EmailMessage(
90                 "[Nibble] Lav stock på " + self.name,
91                 str(message),
92                 "online@online.ntnu.no",
93                 [],
94                 [settings.EMAIL_TRIKOM]
95             ).send()
96 
97     def __str__(self):
98         return self.name
99 
100     class Meta(object):
101         verbose_name = _("Vare")
102         verbose_name_plural = _("Varer")
103         permissions = (
104             ("view_item", "View Inventory Item"),
105         )
106 
107 
108 class Batch(models.Model):
109 
110     item = models.ForeignKey(Item, verbose_name=_("Vare"), related_name="batches")
111     amount = models.IntegerField(_("Antall"), default=0)
112     date_added = models.DateField(_("Dato lagt til"), editable=False, auto_now_add=True)
113     expiration_date = models.DateField(_("Utløpsdato"), null=True, blank=True, editable=True)
114 
115     class Meta(object):
116         verbose_name = _("Batch")
117         verbose_name_plural = _("Batches")
118
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/apps/inventory/models.py b/apps/inventory/models.py
--- a/apps/inventory/models.py
+++ b/apps/inventory/models.py
@@ -55,7 +55,7 @@
 
     @property
     def has_expired_batch(self):
-        if timezone.now().date() >= self.oldest_expiration_date:
+        if self.oldest_expiration_date and timezone.now().date() >= self.oldest_expiration_date:
             return True
         return False

{"golden_diff": "diff --git a/apps/inventory/models.py b/apps/inventory/models.py\n--- a/apps/inventory/models.py\n+++ b/apps/inventory/models.py\n@@ -55,7 +55,7 @@\n \n     @property\n     def has_expired_batch(self):\n-        if timezone.now().date() >= self.oldest_expiration_date:\n+        if self.oldest_expiration_date and timezone.now().date() >= self.oldest_expiration_date:\n             return True\n         return False\n", "issue": "Cannot view inventory\n## What kind of an issue is this?\r\n\r\n- [x] Bug report\r\n\r\n\r\n## What is the expected behaviour?\r\n\r\nTo be able to view the inventory\r\n\r\n## What is the current behaviour?\r\n\r\nA 500 error, with the message `TypeError: '>=' not supported between instances of 'datetime.date' and 'NoneType'`. \r\n\r\n\r\n## How do you reproduce this problem? \r\n\r\nMake sure the inventory is not empty, and try to visit it.\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\nfrom django.conf import settings\nfrom django.core.mail import EmailMessage\nfrom django.db import models\nfrom django.utils import timezone\nfrom django.utils.translation import ugettext as _\n\nfrom apps.gallery.models import ResponsiveImage\n\n\nclass ItemCategory(models.Model):\n    name = models.CharField(_(\"Kategori\"), max_length=50)\n\n    def __str__(self):\n        return self.name\n\n\nclass Item(models.Model):\n\n    name = models.CharField(_(\"Varetype\"), max_length=50)\n    description = models.CharField(_(\"Beskrivelse\"), max_length=50, null=True, blank=True)\n    price = models.IntegerField(_(\"Pris\"), null=True, blank=True)\n    available = models.BooleanField(_(\"Til salgs\"), default=False)\n    category = models.ForeignKey(ItemCategory, verbose_name=_(\"Kategori\"),\n                                 related_name=\"category\", null=True, blank=True)\n    image = models.ForeignKey(ResponsiveImage, null=True, blank=True, default=None)\n\n    @property\n    def oldest_expiration_date(self):\n        batches = self.batches.all().order_by(\"expiration_date\")\n        if batches:\n            return batches[0].expiration_date\n        else:\n            return None\n\n    @property\n    def last_added(self):\n        batches = self.batches.all().order_by(\"-date_added\")\n        if batches:\n            return batches[0].date_added\n        else:\n            return None\n\n    def oldest_batch(self):\n        batches = self.batches.filter(amount__gt=0).order_by(\"date_added\")\n        if batches:\n            return batches[0]\n        else:\n            return None\n\n    @property\n    def total_amount(self):\n        return sum([batch.amount for batch in self.batches.all()])\n\n    @property\n    def has_expired_batch(self):\n        if timezone.now().date() >= self.oldest_expiration_date:\n            return True\n        return False\n\n    def reduce_stock(self, amount):\n        \"\"\"\n        Makes an assumption that the oldest batches are sold first and reduce them first.\n        \"\"\"\n\n        oldest_batch = self.oldest_batch()\n\n        if oldest_batch:\n            if oldest_batch.amount > amount:\n                oldest_batch.amount = oldest_batch.amount - amount\n                oldest_batch.save()\n            else:\n                diff = amount - oldest_batch.amount\n                oldest_batch.amount = 0\n                oldest_batch.save()\n                self.reduce_stock(diff)\n\n        self.handle_notifications(amount)\n\n    def handle_notifications(self, amount):\n\n        # Send one notification when the stock goes to or below 10\n        if self.total_amount <= 10 and self.total_amount + amount > 10:\n            message = \"Det er kun \" + str(self.total_amount) + \" igjen av \" + str(self.name) + \\\n                      \" p\u00e5 kontoret.\\n\\n\" \\\n                      \"Dette er en automatisk generert melding og antallet kan v\u00e6re noe feil.\"\n\n            EmailMessage(\n                \"[Nibble] Lav stock p\u00e5 \" + self.name,\n                str(message),\n                \"online@online.ntnu.no\",\n                [],\n                [settings.EMAIL_TRIKOM]\n            ).send()\n\n    def __str__(self):\n        return self.name\n\n    class Meta(object):\n        verbose_name = _(\"Vare\")\n        verbose_name_plural = _(\"Varer\")\n        permissions = (\n            (\"view_item\", \"View Inventory Item\"),\n        )\n\n\nclass Batch(models.Model):\n\n    item = models.ForeignKey(Item, verbose_name=_(\"Vare\"), related_name=\"batches\")\n    amount = models.IntegerField(_(\"Antall\"), default=0)\n    date_added = models.DateField(_(\"Dato lagt til\"), editable=False, auto_now_add=True)\n    expiration_date = models.DateField(_(\"Utl\u00f8psdato\"), null=True, blank=True, editable=True)\n\n    class Meta(object):\n        verbose_name = _(\"Batch\")\n        verbose_name_plural = _(\"Batches\")\n", "path": "apps/inventory/models.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\nfrom django.conf import settings\nfrom django.core.mail import EmailMessage\nfrom django.db import models\nfrom django.utils import timezone\nfrom django.utils.translation import ugettext as _\n\nfrom apps.gallery.models import ResponsiveImage\n\n\nclass ItemCategory(models.Model):\n    name = models.CharField(_(\"Kategori\"), max_length=50)\n\n    def __str__(self):\n        return self.name\n\n\nclass Item(models.Model):\n\n    name = models.CharField(_(\"Varetype\"), max_length=50)\n    description = models.CharField(_(\"Beskrivelse\"), max_length=50, null=True, blank=True)\n    price = models.IntegerField(_(\"Pris\"), null=True, blank=True)\n    available = models.BooleanField(_(\"Til salgs\"), default=False)\n    category = models.ForeignKey(ItemCategory, verbose_name=_(\"Kategori\"),\n                                 related_name=\"category\", null=True, blank=True)\n    image = models.ForeignKey(ResponsiveImage, null=True, blank=True, default=None)\n\n    @property\n    def oldest_expiration_date(self):\n        batches = self.batches.all().order_by(\"expiration_date\")\n        if batches:\n            return batches[0].expiration_date\n        else:\n            return None\n\n    @property\n    def last_added(self):\n        batches = self.batches.all().order_by(\"-date_added\")\n        if batches:\n            return batches[0].date_added\n        else:\n            return None\n\n    def oldest_batch(self):\n        batches = self.batches.filter(amount__gt=0).order_by(\"date_added\")\n        if batches:\n            return batches[0]\n        else:\n            return None\n\n    @property\n    def total_amount(self):\n        return sum([batch.amount for batch in self.batches.all()])\n\n    @property\n    def has_expired_batch(self):\n        if self.oldest_expiration_date and timezone.now().date() >= self.oldest_expiration_date:\n            return True\n        return False\n\n    def reduce_stock(self, amount):\n        \"\"\"\n        Makes an assumption that the oldest batches are sold first and reduce them first.\n        \"\"\"\n\n        oldest_batch = self.oldest_batch()\n\n        if oldest_batch:\n            if oldest_batch.amount > amount:\n                oldest_batch.amount = oldest_batch.amount - amount\n                oldest_batch.save()\n            else:\n                diff = amount - oldest_batch.amount\n                oldest_batch.amount = 0\n                oldest_batch.save()\n                self.reduce_stock(diff)\n\n        self.handle_notifications(amount)\n\n    def handle_notifications(self, amount):\n\n        # Send one notification when the stock goes to or below 10\n        if self.total_amount <= 10 and self.total_amount + amount > 10:\n            message = \"Det er kun \" + str(self.total_amount) + \" igjen av \" + str(self.name) + \\\n                      \" p\u00e5 kontoret.\\n\\n\" \\\n                      \"Dette er en automatisk generert melding og antallet kan v\u00e6re noe feil.\"\n\n            EmailMessage(\n                \"[Nibble] Lav stock p\u00e5 \" + self.name,\n                str(message),\n                \"online@online.ntnu.no\",\n                [],\n                [settings.EMAIL_TRIKOM]\n            ).send()\n\n    def __str__(self):\n        return self.name\n\n    class Meta(object):\n        verbose_name = _(\"Vare\")\n        verbose_name_plural = _(\"Varer\")\n        permissions = (\n            (\"view_item\", \"View Inventory Item\"),\n        )\n\n\nclass Batch(models.Model):\n\n    item = models.ForeignKey(Item, verbose_name=_(\"Vare\"), related_name=\"batches\")\n    amount = models.IntegerField(_(\"Antall\"), default=0)\n    date_added = models.DateField(_(\"Dato lagt til\"), editable=False, auto_now_add=True)\n    expiration_date = models.DateField(_(\"Utl\u00f8psdato\"), null=True, blank=True, editable=True)\n\n    class Meta(object):\n        verbose_name = _(\"Batch\")\n        verbose_name_plural = _(\"Batches\")\n", "path": "apps/inventory/models.py"}]}