Display "stale" status on StockItem info page

This commit is contained in:
Oliver Walters 2021-01-06 22:21:18 +11:00
parent ba915da22b
commit e62873a650
2 changed files with 39 additions and 3 deletions

View File

@ -27,9 +27,11 @@ from mptt.models import MPTTModel, TreeForeignKey
from djmoney.models.fields import MoneyField from djmoney.models.fields import MoneyField
from decimal import Decimal, InvalidOperation from decimal import Decimal, InvalidOperation
from datetime import datetime from datetime import datetime, timedelta
from InvenTree import helpers from InvenTree import helpers
import common.models
from InvenTree.status_codes import StockStatus from InvenTree.status_codes import StockStatus
from InvenTree.models import InvenTreeTree, InvenTreeAttachment from InvenTree.models import InvenTreeTree, InvenTreeAttachment
from InvenTree.fields import InvenTreeURLField from InvenTree.fields import InvenTreeURLField
@ -471,9 +473,38 @@ class StockItem(MPTTModel):
help_text=_('Single unit purchase price at time of purchase'), help_text=_('Single unit purchase price at time of purchase'),
) )
def is_stale(self):
"""
Returns True if this Stock item is "stale".
To be "stale", the following conditions must be met:
- Expiry date is not None
- Expiry date will "expire" within the configured stale date
- The StockItem is otherwise "in stock"
"""
if self.expiry_date is None:
return False
if not self.in_stock:
return False
today = datetime.now().date()
stale_days = common.models.InvenTreeSetting.get_setting('STOCK_STALE_DAYS')
if stale_days <= 0:
return False
expiry_date = today + timedelta(days=stale_days)
return self.expiry_date < expiry_date
def is_expired(self): def is_expired(self):
""" """
Returns true if this StockItem is "expired" Returns True if this StockItem is "expired".
To be "expired", the following conditions must be met: To be "expired", the following conditions must be met:

View File

@ -74,6 +74,9 @@ InvenTree | {% trans "Stock Item" %} - {{ item }}
<span class='label label-large label-large-red'>{% trans "Expired" %}</span> <span class='label label-large label-large-red'>{% trans "Expired" %}</span>
{% else %} {% else %}
{% stock_status_label item.status large=True %} {% stock_status_label item.status large=True %}
{% if item.is_stale %}
<span class='label label-large label-large-yellow'>{% trans "Stale" %}</span>
{% endif %}
{% endif %} {% endif %}
</h3> </h3>
<hr> <hr>
@ -304,7 +307,9 @@ InvenTree | {% trans "Stock Item" %} - {{ item }}
<td> <td>
{{ item.expiry_date }} {{ item.expiry_date }}
{% if item.is_expired %} {% if item.is_expired %}
<span title='[% trans "This StockItem expired on" %} {{ item.expiry_date }}' class='label label-red'>{% trans "Expired" %}</span> <span title='{% trans "This StockItem expired on" %} {{ item.expiry_date }}' class='label label-red'>{% trans "Expired" %}</span>
{% elif item.is_stale %}
<span title='{% trans "This StockItem expires on" %} {{ item.expiry_date }}' class='label label-yellow'>{% trans "Stale" %}</span>
{% endif %} {% endif %}
</td> </td>
</tr> </tr>