Admin for part tracking

- Added 'has_tracking_info' function for StockItem
This commit is contained in:
Oliver 2018-04-16 20:17:58 +10:00
parent 76ee150ca4
commit 09b357976d
3 changed files with 24 additions and 1 deletions

View File

@ -2,7 +2,7 @@ from django.contrib import admin
from simple_history.admin import SimpleHistoryAdmin
from .models import StockLocation, StockItem
from .models import StockItemTracking
class LocationAdmin(admin.ModelAdmin):
list_display = ('name', 'pathstring', 'description')
@ -12,5 +12,9 @@ class StockItemAdmin(SimpleHistoryAdmin):
list_display = ('part', 'quantity', 'location', 'status', 'updated')
class StockTrackingAdmin(admin.ModelAdmin):
list_display = ('item', 'date', 'title')
admin.site.register(StockLocation, LocationAdmin)
admin.site.register(StockItem, StockItemAdmin)
admin.site.register(StockItemTracking, StockTrackingAdmin)

View File

@ -121,6 +121,10 @@ class StockItem(models.Model):
infinite = models.BooleanField(default=False)
@property
def has_tracking_info(self):
return self.tracking_info.all().count() > 0
@transaction.atomic
def stocktake(self, count, user):
""" Perform item stocktake.

View File

@ -72,6 +72,21 @@
{% endif %}
</table>
{% if item.has_tracking_info %}
<h3>Stock Tracking</h3>
<ul class='list-group'>
{% for track in item.tracking_info.all %}
<li class='list-group-item'>
<b>{{ track.title }}</b>
{% if track.description %}
<br><br>{{ track.description }}</i>
{% endif %}
<span class='badge'>{{ track.date }}</span>
</li>
{% endfor %}
</ul>
{% endif %}
<div class='container-fluid'>
<a href="{% url 'stock-item-edit' item.id %}">
<button class='btn btn-info'>Edit Stock Item</button>