From eaf191dc8dc19a36f9c5d2f1f86b82f617aeb914 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 4 Jul 2021 23:45:04 +0200 Subject: [PATCH 1/7] fetching supplier part for stock tables --- InvenTree/build/templates/build/build_output.html | 1 + InvenTree/company/templates/company/assigned_stock.html | 1 + InvenTree/company/templates/company/detail_stock.html | 1 + InvenTree/company/templates/company/supplier_part_stock.html | 1 + InvenTree/order/templates/order/po_received_items.html | 1 + InvenTree/stock/templates/stock/item_childs.html | 1 + InvenTree/stock/templates/stock/location.html | 1 + InvenTree/templates/InvenTree/index.html | 3 +++ 8 files changed, 10 insertions(+) diff --git a/InvenTree/build/templates/build/build_output.html b/InvenTree/build/templates/build/build_output.html index 00d7c5d5d2..d3863a2e04 100644 --- a/InvenTree/build/templates/build/build_output.html +++ b/InvenTree/build/templates/build/build_output.html @@ -72,6 +72,7 @@ loadStockTable($("#stock-table"), { params: { location_detail: true, part_detail: true, + supplier_part_detail: true, build: {{ build.id }}, }, groupByField: 'location', diff --git a/InvenTree/company/templates/company/assigned_stock.html b/InvenTree/company/templates/company/assigned_stock.html index d64719407b..50b48b283f 100644 --- a/InvenTree/company/templates/company/assigned_stock.html +++ b/InvenTree/company/templates/company/assigned_stock.html @@ -29,6 +29,7 @@ loadStockTable($("#stock-table"), { params: { customer: {{ company.id }}, part_detail: true, + supplier_part_detail: true, location_detail: true, }, url: "{% url 'api-stock-list' %}", diff --git a/InvenTree/company/templates/company/detail_stock.html b/InvenTree/company/templates/company/detail_stock.html index f10a99ba5a..d61dd05954 100644 --- a/InvenTree/company/templates/company/detail_stock.html +++ b/InvenTree/company/templates/company/detail_stock.html @@ -24,6 +24,7 @@ company: {{ company.id }}, part_detail: true, supplier_detail: true, + supplier_part_detail: true, location_detail: true, }, buttons: [ diff --git a/InvenTree/company/templates/company/supplier_part_stock.html b/InvenTree/company/templates/company/supplier_part_stock.html index 1187b95bca..73028f9d91 100644 --- a/InvenTree/company/templates/company/supplier_part_stock.html +++ b/InvenTree/company/templates/company/supplier_part_stock.html @@ -23,6 +23,7 @@ supplier_part: {{ part.id }}, location_detail: true, part_detail: false, + supplier_part_detail: true, }, groupByField: 'location', buttons: ['#stock-options'], diff --git a/InvenTree/order/templates/order/po_received_items.html b/InvenTree/order/templates/order/po_received_items.html index 96dcb4fcf7..f551eda977 100644 --- a/InvenTree/order/templates/order/po_received_items.html +++ b/InvenTree/order/templates/order/po_received_items.html @@ -26,6 +26,7 @@ loadStockTable($("#stock-table"), { purchase_order: {{ order.id }}, part_detail: true, supplier_detail: true, + supplier_part_detail: true, location_detail: true, }, buttons: [ diff --git a/InvenTree/stock/templates/stock/item_childs.html b/InvenTree/stock/templates/stock/item_childs.html index f5d80e5ad1..7c111af06d 100644 --- a/InvenTree/stock/templates/stock/item_childs.html +++ b/InvenTree/stock/templates/stock/item_childs.html @@ -31,6 +31,7 @@ loadStockTable($("#stock-table"), { params: { location_detail: true, part_detail: false, + supplier_part_detail: true, ancestor: {{ item.id }}, }, name: 'item-childs', diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index 499aaa6948..6a69be260e 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -265,6 +265,7 @@ {% endif %} part_detail: true, location_detail: true, + supplier_part_detail: true, }, url: "{% url 'api-stock-list' %}", }); diff --git a/InvenTree/templates/InvenTree/index.html b/InvenTree/templates/InvenTree/index.html index a3d793dd26..6a523d152a 100644 --- a/InvenTree/templates/InvenTree/index.html +++ b/InvenTree/templates/InvenTree/index.html @@ -134,6 +134,7 @@ addHeaderAction('stock-to-build', '{% trans "Required for Build Orders" %}', 'fa loadStockTable($('#table-recently-updated-stock'), { params: { part_detail: true, + supplier_part_detail: true, ordering: "-updated", max_results: {% settings_value "STOCK_RECENT_COUNT" %}, }, @@ -151,6 +152,7 @@ loadStockTable($("#table-expired-stock"), { expired: true, location_detail: true, part_detail: true, + supplier_part_detail: true, }, }); @@ -160,6 +162,7 @@ loadStockTable($("#table-stale-stock"), { expired: false, location_detail: true, part_detail: true, + supplier_part_detail: true, }, }); {% endif %} From 369acb494b18abb1ba0384667e3a5e6e91da97c7 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 5 Jul 2021 00:46:51 +0200 Subject: [PATCH 2/7] new tag for url resolve --- InvenTree/part/templatetags/inventree_extras.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py index 38689df26b..4cc219454b 100644 --- a/InvenTree/part/templatetags/inventree_extras.py +++ b/InvenTree/part/templatetags/inventree_extras.py @@ -11,7 +11,7 @@ from django.utils.translation import ugettext_lazy as _ from django.conf import settings as djangosettings from django import template -from django.urls import reverse +from django.urls import reverse, resolve as resolve_fnc from django.utils.safestring import mark_safe from django.templatetags.static import StaticNode from InvenTree import version, settings @@ -267,6 +267,12 @@ def object_link(url_name, pk, ref): return mark_safe('{}'.format(ref_url, ref)) +@register.simple_tag() +def resolve(url): + """provides access to resolve function in templates""" + return resolve_fnc(url) + + class I18nStaticNode(StaticNode): """ custom StaticNode From 1786c029b4b3c9edb7a5824998b2b3b7e08c3b08 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 5 Jul 2021 00:47:45 +0200 Subject: [PATCH 3/7] prev and next serial link in stock items --- .../stock/templates/stock/item_base.html | 11 ++++++++- InvenTree/stock/views.py | 23 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index b674c5c7fc..0427111f57 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -247,7 +247,16 @@ {% trans "Serial Number" %} - {{ item.serial }} + + {% resolve request.path as url_path %} + {% if previous %} + {{ previous.serial }} ‹ + {% endif %} + {{ item.serial }} + {% if next %} + › {{ next.serial }} + {% endif %} + {% else %} diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index 280b1bb533..3af064a525 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -86,6 +86,29 @@ class StockItemDetail(InvenTreeRoleMixin, DetailView): queryset = StockItem.objects.all() model = StockItem + def get_context_data(self, **kwargs): + """ add previous and next item """ + data = super().get_context_data(**kwargs) + + if self.object.serialized: + serial_elem = {a.serial: a for a in self.object.part.stock_items.all() if a.serialized} + serials = [int(a) for a in serial_elem.keys()] + current = int(self.object.serial) + + # previous + for nbr in range(current - 1, 0, -1): + if nbr in serials: + data['previous'] = serial_elem.get(str(nbr), None) + break + + # next + for nbr in range(current + 1, max(serials)): + if nbr in serials: + data['next'] = serial_elem.get(str(nbr), None) + break + + return data + class StockItemNotes(InvenTreeRoleMixin, UpdateView): """ View for editing the 'notes' field of a StockItem object """ From 84b67e2cc1583115ff862b2d9e2d7c12ec5a0491 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 5 Jul 2021 00:53:05 +0200 Subject: [PATCH 4/7] also allow the boundaries --- InvenTree/stock/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index 3af064a525..5bcc38da50 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -96,13 +96,13 @@ class StockItemDetail(InvenTreeRoleMixin, DetailView): current = int(self.object.serial) # previous - for nbr in range(current - 1, 0, -1): + for nbr in range(current - 1, -1, -1): if nbr in serials: data['previous'] = serial_elem.get(str(nbr), None) break # next - for nbr in range(current + 1, max(serials)): + for nbr in range(current + 1, max(serials) + 1): if nbr in serials: data['next'] = serial_elem.get(str(nbr), None) break From 9ed23381624343064e606f762ac60f2644c85f3d Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 6 Jul 2021 21:10:42 +0200 Subject: [PATCH 5/7] bolder type for serial numbers --- InvenTree/stock/templates/stock/item_base.html | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index 0427111f57..9d9062212a 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -250,11 +250,15 @@ {% resolve request.path as url_path %} {% if previous %} - {{ previous.serial }} ‹ + + {{ previous.serial }} ‹ + {% endif %} - {{ item.serial }} + {{ item.serial }} {% if next %} - › {{ next.serial }} + + › {{ next.serial }} + {% endif %} From 98c52c06acd6a06454b680b125159cb11f90407a Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 6 Jul 2021 21:20:27 +0200 Subject: [PATCH 6/7] Revert "fetching supplier part for stock tables" This reverts commit eaf191dc8dc19a36f9c5d2f1f86b82f617aeb914. --- InvenTree/build/templates/build/build_output.html | 1 - InvenTree/company/templates/company/assigned_stock.html | 1 - InvenTree/company/templates/company/detail_stock.html | 1 - InvenTree/company/templates/company/supplier_part_stock.html | 1 - InvenTree/order/templates/order/po_received_items.html | 1 - InvenTree/stock/templates/stock/item_childs.html | 1 - InvenTree/stock/templates/stock/location.html | 1 - InvenTree/templates/InvenTree/index.html | 3 --- 8 files changed, 10 deletions(-) diff --git a/InvenTree/build/templates/build/build_output.html b/InvenTree/build/templates/build/build_output.html index d3863a2e04..00d7c5d5d2 100644 --- a/InvenTree/build/templates/build/build_output.html +++ b/InvenTree/build/templates/build/build_output.html @@ -72,7 +72,6 @@ loadStockTable($("#stock-table"), { params: { location_detail: true, part_detail: true, - supplier_part_detail: true, build: {{ build.id }}, }, groupByField: 'location', diff --git a/InvenTree/company/templates/company/assigned_stock.html b/InvenTree/company/templates/company/assigned_stock.html index 50b48b283f..d64719407b 100644 --- a/InvenTree/company/templates/company/assigned_stock.html +++ b/InvenTree/company/templates/company/assigned_stock.html @@ -29,7 +29,6 @@ loadStockTable($("#stock-table"), { params: { customer: {{ company.id }}, part_detail: true, - supplier_part_detail: true, location_detail: true, }, url: "{% url 'api-stock-list' %}", diff --git a/InvenTree/company/templates/company/detail_stock.html b/InvenTree/company/templates/company/detail_stock.html index d61dd05954..f10a99ba5a 100644 --- a/InvenTree/company/templates/company/detail_stock.html +++ b/InvenTree/company/templates/company/detail_stock.html @@ -24,7 +24,6 @@ company: {{ company.id }}, part_detail: true, supplier_detail: true, - supplier_part_detail: true, location_detail: true, }, buttons: [ diff --git a/InvenTree/company/templates/company/supplier_part_stock.html b/InvenTree/company/templates/company/supplier_part_stock.html index 73028f9d91..1187b95bca 100644 --- a/InvenTree/company/templates/company/supplier_part_stock.html +++ b/InvenTree/company/templates/company/supplier_part_stock.html @@ -23,7 +23,6 @@ supplier_part: {{ part.id }}, location_detail: true, part_detail: false, - supplier_part_detail: true, }, groupByField: 'location', buttons: ['#stock-options'], diff --git a/InvenTree/order/templates/order/po_received_items.html b/InvenTree/order/templates/order/po_received_items.html index f551eda977..96dcb4fcf7 100644 --- a/InvenTree/order/templates/order/po_received_items.html +++ b/InvenTree/order/templates/order/po_received_items.html @@ -26,7 +26,6 @@ loadStockTable($("#stock-table"), { purchase_order: {{ order.id }}, part_detail: true, supplier_detail: true, - supplier_part_detail: true, location_detail: true, }, buttons: [ diff --git a/InvenTree/stock/templates/stock/item_childs.html b/InvenTree/stock/templates/stock/item_childs.html index 7c111af06d..f5d80e5ad1 100644 --- a/InvenTree/stock/templates/stock/item_childs.html +++ b/InvenTree/stock/templates/stock/item_childs.html @@ -31,7 +31,6 @@ loadStockTable($("#stock-table"), { params: { location_detail: true, part_detail: false, - supplier_part_detail: true, ancestor: {{ item.id }}, }, name: 'item-childs', diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index 6a69be260e..499aaa6948 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -265,7 +265,6 @@ {% endif %} part_detail: true, location_detail: true, - supplier_part_detail: true, }, url: "{% url 'api-stock-list' %}", }); diff --git a/InvenTree/templates/InvenTree/index.html b/InvenTree/templates/InvenTree/index.html index 6a523d152a..a3d793dd26 100644 --- a/InvenTree/templates/InvenTree/index.html +++ b/InvenTree/templates/InvenTree/index.html @@ -134,7 +134,6 @@ addHeaderAction('stock-to-build', '{% trans "Required for Build Orders" %}', 'fa loadStockTable($('#table-recently-updated-stock'), { params: { part_detail: true, - supplier_part_detail: true, ordering: "-updated", max_results: {% settings_value "STOCK_RECENT_COUNT" %}, }, @@ -152,7 +151,6 @@ loadStockTable($("#table-expired-stock"), { expired: true, location_detail: true, part_detail: true, - supplier_part_detail: true, }, }); @@ -162,7 +160,6 @@ loadStockTable($("#table-stale-stock"), { expired: false, location_detail: true, part_detail: true, - supplier_part_detail: true, }, }); {% endif %} From 2db42eff500f9255729312f137b09127bae75ae1 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 6 Jul 2021 21:25:42 +0200 Subject: [PATCH 7/7] remove unneeded tag --- InvenTree/part/templatetags/inventree_extras.py | 8 +------- InvenTree/stock/templates/stock/item_base.html | 5 ++--- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/InvenTree/part/templatetags/inventree_extras.py b/InvenTree/part/templatetags/inventree_extras.py index 4cc219454b..38689df26b 100644 --- a/InvenTree/part/templatetags/inventree_extras.py +++ b/InvenTree/part/templatetags/inventree_extras.py @@ -11,7 +11,7 @@ from django.utils.translation import ugettext_lazy as _ from django.conf import settings as djangosettings from django import template -from django.urls import reverse, resolve as resolve_fnc +from django.urls import reverse from django.utils.safestring import mark_safe from django.templatetags.static import StaticNode from InvenTree import version, settings @@ -267,12 +267,6 @@ def object_link(url_name, pk, ref): return mark_safe('{}'.format(ref_url, ref)) -@register.simple_tag() -def resolve(url): - """provides access to resolve function in templates""" - return resolve_fnc(url) - - class I18nStaticNode(StaticNode): """ custom StaticNode diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index 9d9062212a..2eb7695498 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -248,15 +248,14 @@ {% trans "Serial Number" %} - {% resolve request.path as url_path %} {% if previous %} - + {{ previous.serial }} {% endif %} {{ item.serial }} {% if next %} - + {{ next.serial }} {% endif %}