From 55b533d3efcdc98e275137c20113a89819650b58 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 15 Apr 2018 23:27:56 +1000 Subject: [PATCH] Added edit views for stock - StockItem - StockLocation --- InvenTree/InvenTree/settings.py | 4 +- InvenTree/part/models.py | 1 - .../part/templates/part/category_delete.html | 4 +- InvenTree/part/templates/part/stock.html | 12 ++++- InvenTree/part/templates/part/supplier.html | 4 +- InvenTree/stock/models.py | 12 +++++ InvenTree/stock/templates/stock/item.html | 13 +++++- .../stock/templates/stock/item_create.html | 5 +++ .../stock/templates/stock/item_delete.html | 9 ++++ .../stock/templates/stock/item_edit.html | 5 +++ InvenTree/stock/templates/stock/location.html | 18 ++++++++ .../templates/stock/location_create.html | 5 +++ .../templates/stock/location_delete.html | 41 +++++++++++++++++ .../stock/templates/stock/location_edit.html | 5 +++ .../stock/templates/stock/stock_table.html | 2 +- InvenTree/stock/urls.py | 4 +- InvenTree/stock/views.py | 44 +++++++++++++++---- .../templates/supplier/partdetail.html | 2 +- 18 files changed, 168 insertions(+), 22 deletions(-) create mode 100644 InvenTree/stock/templates/stock/item_create.html create mode 100644 InvenTree/stock/templates/stock/item_delete.html create mode 100644 InvenTree/stock/templates/stock/item_edit.html create mode 100644 InvenTree/stock/templates/stock/location_create.html create mode 100644 InvenTree/stock/templates/stock/location_delete.html create mode 100644 InvenTree/stock/templates/stock/location_edit.html diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index f5f5802278..c8a2be70c9 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -68,7 +68,7 @@ ROOT_URLCONF = 'InvenTree.urls' TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', - 'DIRS': [], + 'DIRS': [os.path.join(BASE_DIR, 'templates')], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ @@ -81,6 +81,8 @@ TEMPLATES = [ }, ] +print(os.path.join(BASE_DIR, 'templates')) + REST_FRAMEWORK = { 'EXCEPTION_HANDLER': 'InvenTree.utils.api_exception_handler' } diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index f08f8da4d8..4c2b8967f5 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -23,7 +23,6 @@ class PartCategory(InvenTreeTree): verbose_name = "Part Category" verbose_name_plural = "Part Categories" - @property def partcount(self): """ Return the total part count under this category diff --git a/InvenTree/part/templates/part/category_delete.html b/InvenTree/part/templates/part/category_delete.html index 960edbbaa1..7814317356 100644 --- a/InvenTree/part/templates/part/category_delete.html +++ b/InvenTree/part/templates/part/category_delete.html @@ -18,7 +18,7 @@ Are you sure you want to delete category '{{ category.name }}'? {% endif %} @@ -33,7 +33,7 @@ Are you sure you want to delete category '{{ category.name }}'?

{% endif %} diff --git a/InvenTree/part/templates/part/stock.html b/InvenTree/part/templates/part/stock.html index 49fbb9736a..825608b73f 100644 --- a/InvenTree/part/templates/part/stock.html +++ b/InvenTree/part/templates/part/stock.html @@ -10,6 +10,7 @@ Total in stock: {{ part.stock }} + @@ -18,8 +19,9 @@ Total in stock: {{ part.stock }} {% for stock in part.locations.all %} + - + {% endfor %} -
Link Quantity Location Supplier part
Click {{ stock.quantity }}{{ stock.location.name }}{{ stock.location.name }} {% if stock.supplier_part %} @@ -31,6 +33,12 @@ Total in stock: {{ part.stock }} {{ stock.notes }}
+ + + + + {% endblock %} \ No newline at end of file diff --git a/InvenTree/part/templates/part/supplier.html b/InvenTree/part/templates/part/supplier.html index e6a26c3781..425c98b3f3 100644 --- a/InvenTree/part/templates/part/supplier.html +++ b/InvenTree/part/templates/part/supplier.html @@ -7,14 +7,14 @@ {% if part.supplier_parts.all|length > 0 %} - + {% for spart in part.supplier_parts.all %} - + {% for item in items.all %} - + diff --git a/InvenTree/stock/urls.py b/InvenTree/stock/urls.py index c83646429b..3712c6f2d6 100644 --- a/InvenTree/stock/urls.py +++ b/InvenTree/stock/urls.py @@ -52,10 +52,10 @@ stock_urls = [ url(r'^location/new/', views.StockLocationCreate.as_view(), name='stock-location-create'), + url(r'^item/new/?', views.StockItemCreate.as_view(), name='stock-item-create'), + # Individual stock items url(r'^item/(?P\d+)/', include(stock_item_detail_urls)), - url(r'^item/new/', views.StockItemCreate.as_view(), name='stock-item-create'), - url(r'^.*$', views.StockIndex.as_view(), name='stock-index'), ] \ No newline at end of file diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index 7d42045a80..18c1e92dae 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -5,7 +5,7 @@ from django.urls import reverse from django.views.generic import DetailView, ListView from django.views.generic.edit import UpdateView, DeleteView, CreateView - +from part.models import Part from .models import StockItem, StockLocation from .forms import EditStockLocationForm @@ -46,35 +46,60 @@ class StockItemDetail(DetailView): class StockLocationEdit(UpdateView): model = StockLocation form_class = EditStockLocationForm - template_name = '/stock/location-edit.html' + template_name = 'stock/location_edit.html' context_object_name = 'location' class StockItemEdit(UpdateView): model = StockItem form_class = EditStockItemForm - template_name = '/stock/item-edit.html' + template_name = 'stock/item_edit.html' context_object_name = 'item' class StockLocationCreate(CreateView): model = StockLocation form_class = EditStockLocationForm - template_name = '/stock/location-create.html' + template_name = 'stock/location_create.html' context_object_name = 'location' + def get_initial(self): + initials = super(StockLocationCreate, self).get_initial().copy() + + loc_id = self.request.GET.get('location', None) + + if loc_id: + initials['parent'] = get_object_or_404(StockLocation, pk=loc_id) + + return initials + class StockItemCreate(CreateView): model = StockItem form_class = EditStockItemForm - template_name = '/stock/item-create.html' + template_name = 'stock/item_create.html' context_object_name = 'item' + def get_initial(self): + initials = super(StockItemCreate, self).get_initial().copy() + + part_id = self.request.GET.get('part', None) + loc_id = self.request.GET.get('location', None) + + if part_id: + initials['part'] = get_object_or_404(Part, pk=part_id) + + if loc_id: + initials['location'] = get_object_or_404(StockLocation, pk=loc_id) + + return initials + class StockLocationDelete(DeleteView): model = StockLocation - success_url = '/stock/' - template_name = '/stock/location-delete.html' + success_url = '/stock' + template_name = 'stock/location_delete.html' + context_object_name = 'location' def post(self, request, *args, **kwargs): if 'confirm' in request.POST: @@ -84,9 +109,10 @@ class StockLocationDelete(DeleteView): class StockItemDelete(DeleteView): - model = StockLocation + model = StockItem success_url = '/stock/' - template_name = '/stock/item-delete.html' + template_name = 'stock/item_delete.html' + context_object_name = 'item' def post(self, request, *args, **kwargs): if 'confirm' in request.POST: diff --git a/InvenTree/supplier/templates/supplier/partdetail.html b/InvenTree/supplier/templates/supplier/partdetail.html index 3c1fa315e0..ccee02fe71 100644 --- a/InvenTree/supplier/templates/supplier/partdetail.html +++ b/InvenTree/supplier/templates/supplier/partdetail.html @@ -11,7 +11,7 @@
Supplier SKUSupplier URL
{{ spart.supplier.name }} {{ spart.SKU }}{{ spart.supplier.name }} {% if spart.URL %} {{ spart.URL }} diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 146943e1b0..32fca52124 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -20,6 +20,9 @@ class StockLocation(InvenTreeTree): Stock locations can be heirarchical as required """ + def get_absolute_url(self): + return '/stock/location/{id}/'.format(id=self.id) + @property def items(self): stock_list = self.stockitem_set.all() @@ -34,7 +37,16 @@ def before_delete_stock_location(sender, instance, using, **kwargs): item.location = instance.parent item.save() + # Update each child category + for child in instance.children.all(): + child.parent = instance.parent + child.save() + class StockItem(models.Model): + + def get_absolute_url(self): + return '/stock/item/{id}/'.format(id=self.id) + part = models.ForeignKey(Part, on_delete=models.CASCADE, related_name='locations') supplier_part = models.ForeignKey(SupplierPart, blank=True, null=True, on_delete=models.SET_NULL) diff --git a/InvenTree/stock/templates/stock/item.html b/InvenTree/stock/templates/stock/item.html index 8b7c80e5f9..1f4e63cdb4 100644 --- a/InvenTree/stock/templates/stock/item.html +++ b/InvenTree/stock/templates/stock/item.html @@ -4,10 +4,12 @@ {% include "stock/loc_link.html" with location=item.location %} +

Stock entry details

+ - + @@ -45,4 +47,13 @@ {% endif %}
Part{{ item.part.name }}{{ item.part.name }}
Location
+ + {% endblock %} \ No newline at end of file diff --git a/InvenTree/stock/templates/stock/item_create.html b/InvenTree/stock/templates/stock/item_create.html new file mode 100644 index 0000000000..862acc859b --- /dev/null +++ b/InvenTree/stock/templates/stock/item_create.html @@ -0,0 +1,5 @@ +{% extends "create_edit_obj.html" %} + +{% block obj_title %} +Create a new stock item +{% endblock %} \ No newline at end of file diff --git a/InvenTree/stock/templates/stock/item_delete.html b/InvenTree/stock/templates/stock/item_delete.html new file mode 100644 index 0000000000..dfbac09c26 --- /dev/null +++ b/InvenTree/stock/templates/stock/item_delete.html @@ -0,0 +1,9 @@ +{% extends "delete_obj.html" %} + +{% block del_title %} +Are you sure you want to delete this stock item? +{% endblock %} + +{% block del_body %} +This will remove {{ item.quantity }} units of '{{ item.part.name }}' from stock. +{% endblock %} \ No newline at end of file diff --git a/InvenTree/stock/templates/stock/item_edit.html b/InvenTree/stock/templates/stock/item_edit.html new file mode 100644 index 0000000000..5f0de213b9 --- /dev/null +++ b/InvenTree/stock/templates/stock/item_edit.html @@ -0,0 +1,5 @@ +{% extends "create_edit_obj.html" %} + +{% block obj_title %} +Edit stock item for part '{{ item.part.name }}' +{% endblock %} \ No newline at end of file diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index 54352b0284..f68f8cb6b0 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -14,4 +14,22 @@ {% include "stock/stock_table.html" with items=location.items %} + + {% endblock %} \ No newline at end of file diff --git a/InvenTree/stock/templates/stock/location_create.html b/InvenTree/stock/templates/stock/location_create.html new file mode 100644 index 0000000000..c79e09ae70 --- /dev/null +++ b/InvenTree/stock/templates/stock/location_create.html @@ -0,0 +1,5 @@ +{% extends "create_edit_obj.html" %} + +{% block obj_title %} +Create a new stock location +{% endblock %} \ No newline at end of file diff --git a/InvenTree/stock/templates/stock/location_delete.html b/InvenTree/stock/templates/stock/location_delete.html new file mode 100644 index 0000000000..135ed55d51 --- /dev/null +++ b/InvenTree/stock/templates/stock/location_delete.html @@ -0,0 +1,41 @@ +{% extends 'delete_obj.html' %} + +{% block del_title %} +Are you sure you want to delete stock location '{{ location.name }}'? +{% endblock %} + +{% block del_body %} +{% if location.children.all|length > 0 %} +

This location contains {{ location.children.all|length }} child locations.
+If this location is deleted, these child locations will be moved to +{% if location.parent %} +the '{{ location.parent.name }}' location. +{% else %} +the top level 'Stock' category. +{% endif %} +

+ +
    + {% for loc in location.children.all %} +
  • {{ loc.name }} - {{ loc.description}}
  • + {% endfor %} +
+{% endif %} + +{% if location.items.all|length > 0 %} +

This location contains {{ location.items.all|length }} stock items.
+{% if location.parent %} +If this location is deleted, these items will be moved to the '{{ location.parent.name }}' location. +{% else %} +If this location is deleted, these items will be deleted! +{% endif %} +

+ +
    + {% for item in location.items.all %} +
  • {{ item.part.name }} - {{ item.part.description }}{{ item.quantity }}
  • + {% endfor %} +
+{% endif %} + +{% endblock %} \ No newline at end of file diff --git a/InvenTree/stock/templates/stock/location_edit.html b/InvenTree/stock/templates/stock/location_edit.html new file mode 100644 index 0000000000..d2fbdbb84e --- /dev/null +++ b/InvenTree/stock/templates/stock/location_edit.html @@ -0,0 +1,5 @@ +{% extends "create_edit_obj.html" %} + +{% block obj_title %} +Edit stock location '{{ location.name }}' +{% endblock %} \ No newline at end of file diff --git a/InvenTree/stock/templates/stock/stock_table.html b/InvenTree/stock/templates/stock/stock_table.html index d3684ffe63..b6e92e060f 100644 --- a/InvenTree/stock/templates/stock/stock_table.html +++ b/InvenTree/stock/templates/stock/stock_table.html @@ -8,7 +8,7 @@
{{ item.part.name }}{{ item.part.name }} {{ item.quantity }} {{ item.status }} {{ item.stocktake_date }}Part {% if part.part %} - {{ part.part.name }} + {{ part.part.name }} {% endif %}