From db1a434f81524a98cf5cce2312f544db65e60116 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 26 Nov 2021 23:56:24 +0100 Subject: [PATCH 01/33] [FR] User sessions Fixes #2327 --- InvenTree/InvenTree/settings.py | 10 ++++- InvenTree/InvenTree/urls.py | 5 +++ InvenTree/InvenTree/views.py | 20 +++++++++ .../templates/InvenTree/settings/user.html | 42 +++++++++++++++++++ requirements.txt | 1 + 5 files changed, 76 insertions(+), 2 deletions(-) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 038d07600f..df84ba315e 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -257,7 +257,7 @@ INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', - 'django.contrib.sessions', + 'user_sessions', # db user sessions 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.sites', @@ -299,7 +299,7 @@ INSTALLED_APPS = [ MIDDLEWARE = CONFIG.get('middleware', [ 'django.middleware.security.SecurityMiddleware', - 'django.contrib.sessions.middleware.SessionMiddleware', + 'user_sessions.middleware.SessionMiddleware', # db user sessions 'django.middleware.locale.LocaleMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', @@ -626,6 +626,12 @@ if _cache_host: # as well Q_CLUSTER["django_redis"] = "worker" +# database user sessions +SESSION_ENGINE = 'user_sessions.backends.db' +LOGOUT_REDIRECT_URL = 'index' +SILENCED_SYSTEM_CHECKS = [ + 'admin.E410', +] # Password validation # https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index 584403fc84..15ed8d5478 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -38,6 +38,7 @@ from rest_framework.documentation import include_docs_urls from .views import auth_request from .views import IndexView, SearchView, DatabaseStatsView from .views import SettingsView, EditUserView, SetPasswordView, CustomEmailView, CustomConnectionsView, CustomPasswordResetFromKeyView +from .views import CustomSessionDeleteView, CustomSessionDeleteOtherView from .views import CurrencyRefreshView from .views import AppearanceSelectView, SettingCategorySelectView from .views import DynamicJsView @@ -156,6 +157,10 @@ urlpatterns = [ url(r'^markdownx/', include('markdownx.urls')), + # DB user sessions + url(r'^accounts/sessions/other/delete/$', view=CustomSessionDeleteOtherView.as_view(), name='session_delete_other', ), + url(r'^accounts/sessions/(?P\w+)/delete/$', view=CustomSessionDeleteView.as_view(), name='session_delete', ), + # Single Sign On / allauth # overrides of urlpatterns url(r'^accounts/email/', CustomEmailView.as_view(), name='account_email'), diff --git a/InvenTree/InvenTree/views.py b/InvenTree/InvenTree/views.py index 989fb1bc9d..a5c4da48b6 100644 --- a/InvenTree/InvenTree/views.py +++ b/InvenTree/InvenTree/views.py @@ -14,6 +14,7 @@ from django.utils.translation import gettext_lazy as _ from django.template.loader import render_to_string from django.http import HttpResponse, JsonResponse, HttpResponseRedirect from django.urls import reverse_lazy +from django.utils.timezone import now from django.shortcuts import redirect from django.conf import settings @@ -29,6 +30,7 @@ from allauth.socialaccount.forms import DisconnectForm from allauth.account.models import EmailAddress from allauth.account.views import EmailView, PasswordResetFromKeyView from allauth.socialaccount.views import ConnectionsView +from user_sessions.views import SessionDeleteView, SessionDeleteOtherView from common.settings import currency_code_default, currency_codes @@ -733,6 +735,10 @@ class SettingsView(TemplateView): ctx["request"] = self.request ctx['social_form'] = DisconnectForm(request=self.request) + # user db sessions + ctx['session_key'] = self.request.session.session_key + ctx['session_list'] = self.request.user.session_set.filter(expire_date__gt=now()).order_by('-last_activity') + return ctx @@ -766,6 +772,20 @@ class CustomPasswordResetFromKeyView(PasswordResetFromKeyView): success_url = reverse_lazy("account_login") +class UserSessionOverride(): + """overrides sucessurl to lead to settings""" + def get_success_url(self): + return str(reverse_lazy('settings')) + + +class CustomSessionDeleteView(UserSessionOverride, SessionDeleteView): + pass + + +class CustomSessionDeleteOtherView(UserSessionOverride, SessionDeleteOtherView): + pass + + class CurrencyRefreshView(RedirectView): """ POST endpoint to refresh / update exchange rates diff --git a/InvenTree/templates/InvenTree/settings/user.html b/InvenTree/templates/InvenTree/settings/user.html index a4c12a9bb0..43dee386be 100644 --- a/InvenTree/templates/InvenTree/settings/user.html +++ b/InvenTree/templates/InvenTree/settings/user.html @@ -4,6 +4,7 @@ {% load inventree_extras %} {% load socialaccount %} {% load crispy_forms_tags %} +{% load user_sessions i18n %} {% block label %}account{% endblock %} @@ -173,6 +174,47 @@ +
+

{% trans "Active Sessions" %}

+
+ +
+ {% trans "unknown on unknown" as unknown_on_unknown %} + {% trans "unknown" as unknown %} + + + + + + + + + {% for object in session_list %} + + + + + + {% endfor %} +
{% trans "IP Address" %}{% trans "Device" %}{% trans "Last Activity" %}
{{ object.ip }}{{ object.user_agent|device|default_if_none:unknown_on_unknown|safe }} + {% if object.session_key == session_key %} + {% blocktrans with time=object.last_activity|timesince %}{{ time }} ago (this session){% endblocktrans %} + {% else %} + {% blocktrans with time=object.last_activity|timesince %}{{ time }} ago{% endblocktrans %} + {% endif %} +
+ + {% if session_list.count > 1 %} +
+ {% csrf_token %} +

{% blocktrans %}You can also end all other sessions but the current. + This will log you out on all other devices.{% endblocktrans %} +

+
+ {% endif %} +
+ +

{% trans "Language Settings" %}

diff --git a/requirements.txt b/requirements.txt index 139942fd80..5f5695ed3d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -23,6 +23,7 @@ django-q==1.3.4 # Background task scheduling django-sql-utils==0.5.0 # Advanced query annotation / aggregation django-stdimage==5.1.1 # Advanced ImageField management django-test-migrations==1.1.0 # Unit testing for database migrations +django-user-sessions==1.7.1 # user sessions in DB django-weasyprint==1.0.1 # django weasyprint integration djangorestframework==3.12.4 # DRF framework flake8==3.8.3 # PEP checking From 84f0966e4fd8a3c5d6a6850e9441bef6bb69e2d5 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 27 Nov 2021 00:02:39 +0100 Subject: [PATCH 02/33] movelanguage to display settings --- .../templates/InvenTree/settings/user.html | 55 ------------------- .../InvenTree/settings/user_display.html | 53 ++++++++++++++++++ 2 files changed, 53 insertions(+), 55 deletions(-) diff --git a/InvenTree/templates/InvenTree/settings/user.html b/InvenTree/templates/InvenTree/settings/user.html index 43dee386be..97ed4805c9 100644 --- a/InvenTree/templates/InvenTree/settings/user.html +++ b/InvenTree/templates/InvenTree/settings/user.html @@ -213,61 +213,6 @@ {% endif %} - - -
-

{% trans "Language Settings" %}

-
- -
-
-
- {% csrf_token %} - - -
- -
- -
-
-

{% trans "Some languages are not complete" %} - {% if ALL_LANG %} - . {% trans "Show only sufficent" %} - {% else %} - {% trans "and hidden." %} {% trans "Show them too" %} - {% endif %} -

-
-
-
-

{% trans "Help the translation efforts!" %}

-

{% blocktrans with link="https://crowdin.com/project/inventree" %}Native language translation of the InvenTree web application is community contributed via crowdin. Contributions are welcomed and encouraged.{% endblocktrans %}

-
-
- {% endblock %} {% block js_ready %} diff --git a/InvenTree/templates/InvenTree/settings/user_display.html b/InvenTree/templates/InvenTree/settings/user_display.html index ae7843df9c..9f5c22f991 100644 --- a/InvenTree/templates/InvenTree/settings/user_display.html +++ b/InvenTree/templates/InvenTree/settings/user_display.html @@ -50,4 +50,57 @@ +
+

{% trans "Language Settings" %}

+
+ +
+
+
+ {% csrf_token %} + + +
+ +
+ +
+
+

{% trans "Some languages are not complete" %} + {% if ALL_LANG %} + . {% trans "Show only sufficent" %} + {% else %} + {% trans "and hidden." %} {% trans "Show them too" %} + {% endif %} +

+
+
+
+

{% trans "Help the translation efforts!" %}

+

{% blocktrans with link="https://crowdin.com/project/inventree" %}Native language translation of the InvenTree web application is community contributed via crowdin. Contributions are welcomed and encouraged.{% endblocktrans %}

+
+
+ {% endblock %} \ No newline at end of file From 6511a774d141d54c7e83854abef778e9f0cc5eb7 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 27 Nov 2021 00:04:43 +0100 Subject: [PATCH 03/33] exclude sessions from imort / exports --- tasks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tasks.py b/tasks.py index 21f7616d76..a8f9bcaf84 100644 --- a/tasks.py +++ b/tasks.py @@ -291,6 +291,7 @@ def content_excludes(): "exchange.rate", "exchange.exchangebackend", "common.notificationentry", + "sessions.session", ] output = "" From ace4370ee9773292b9493a15780cd5c9caddbe0f Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 28 Nov 2021 16:50:34 +0100 Subject: [PATCH 04/33] add ruleset --- InvenTree/users/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/InvenTree/users/models.py b/InvenTree/users/models.py index 4d1b46ae5d..c9ce20e567 100644 --- a/InvenTree/users/models.py +++ b/InvenTree/users/models.py @@ -159,6 +159,7 @@ class RuleSet(models.Model): 'error_report_error', 'exchange_rate', 'exchange_exchangebackend', + 'django_session', # Django-q 'django_q_ormq', From 5f685f3c2a283604bcefae382754b5c1d7b63a45 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 28 Nov 2021 16:54:11 +0100 Subject: [PATCH 05/33] fix db sessions in import / export --- tasks.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tasks.py b/tasks.py index a8f9bcaf84..f56ed44bc8 100644 --- a/tasks.py +++ b/tasks.py @@ -279,7 +279,6 @@ def content_excludes(): excludes = [ "contenttypes", - "sessions.session", "auth.permission", "authtoken.token", "error_report.error", @@ -291,7 +290,7 @@ def content_excludes(): "exchange.rate", "exchange.exchangebackend", "common.notificationentry", - "sessions.session", + "django_session", ] output = "" From 9454b51866bcaec85446416743b25352aace6521 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 28 Nov 2021 17:18:46 +0100 Subject: [PATCH 06/33] fix rules --- InvenTree/users/models.py | 3 +-- tasks.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/InvenTree/users/models.py b/InvenTree/users/models.py index c9ce20e567..48644e1889 100644 --- a/InvenTree/users/models.py +++ b/InvenTree/users/models.py @@ -145,7 +145,6 @@ class RuleSet(models.Model): # Core django models (not user configurable) 'admin_logentry', 'contenttypes_contenttype', - 'sessions_session', # Models which currently do not require permissions 'common_colortheme', @@ -159,7 +158,7 @@ class RuleSet(models.Model): 'error_report_error', 'exchange_rate', 'exchange_exchangebackend', - 'django_session', + 'user_sessions_session', # Django-q 'django_q_ormq', diff --git a/tasks.py b/tasks.py index f56ed44bc8..51df809149 100644 --- a/tasks.py +++ b/tasks.py @@ -290,7 +290,7 @@ def content_excludes(): "exchange.rate", "exchange.exchangebackend", "common.notificationentry", - "django_session", + "user_sessions_session", ] output = "" From a06d91d9a3218d5a63b700ddc2a58b81159539a8 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 28 Nov 2021 17:21:54 +0100 Subject: [PATCH 07/33] fix reference name --- tasks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks.py b/tasks.py index 51df809149..7408bb40b5 100644 --- a/tasks.py +++ b/tasks.py @@ -290,7 +290,7 @@ def content_excludes(): "exchange.rate", "exchange.exchangebackend", "common.notificationentry", - "user_sessions_session", + "user_sessions.session", ] output = "" From 7b339b35ccbef37446117af9dd800361ab9428a2 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 29 Nov 2021 07:46:37 +1100 Subject: [PATCH 08/33] Small UI tweaks for "sessions" view --- .../templates/InvenTree/settings/user.html | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/InvenTree/templates/InvenTree/settings/user.html b/InvenTree/templates/InvenTree/settings/user.html index 97ed4805c9..cfc5b421e3 100644 --- a/InvenTree/templates/InvenTree/settings/user.html +++ b/InvenTree/templates/InvenTree/settings/user.html @@ -15,12 +15,12 @@ {% block actions %} {% inventree_demo_mode as demo %} {% if not demo %} +
+ {% trans "Set Password" %} +
{% trans "Edit" %}
-
- {% trans "Set Password" %} -
{% endif %} {% endblock %} @@ -175,7 +175,20 @@
-

{% trans "Active Sessions" %}

+
+

{% trans "Active Sessions" %}

+ {% include "spacer.html" %} +
+ {% if session_list.count > 1 %} +
+ {% csrf_token %} + +
+ {% endif %} +
+
@@ -203,15 +216,6 @@ {% endfor %} - - {% if session_list.count > 1 %} -
- {% csrf_token %} -

{% blocktrans %}You can also end all other sessions but the current. - This will log you out on all other devices.{% endblocktrans %} -

-
- {% endif %}
{% endblock %} From 6e9937e0e9996a1c1e0ac9dcd25fd39a3bbfb764 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 30 Nov 2021 15:24:19 +1100 Subject: [PATCH 09/33] Don't be dull, check for null --- InvenTree/templates/js/translated/order.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/InvenTree/templates/js/translated/order.js b/InvenTree/templates/js/translated/order.js index c61722858d..a471182399 100644 --- a/InvenTree/templates/js/translated/order.js +++ b/InvenTree/templates/js/translated/order.js @@ -701,6 +701,11 @@ function loadPurchaseOrderTable(table, options) { switchable: true, sortable: false, formatter: function(value, row) { + + if (!row.responsible_detail) { + return '-'; + } + var html = row.responsible_detail.name; if (row.responsible_detail.label == 'group') { From b34b3c6d85db19eedfe83c4b8a26abe7be9bc459 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 30 Nov 2021 19:38:48 +1100 Subject: [PATCH 10/33] Place part details below main part display tab --- InvenTree/part/templates/part/detail.html | 107 --------- InvenTree/part/templates/part/part_base.html | 212 ++++++++++++++---- .../part/templates/part/part_sidebar.html | 2 - InvenTree/templates/page_base.html | 12 +- 4 files changed, 176 insertions(+), 157 deletions(-) diff --git a/InvenTree/part/templates/part/detail.html b/InvenTree/part/templates/part/detail.html index 4cf6f5e824..ce78e445e1 100644 --- a/InvenTree/part/templates/part/detail.html +++ b/InvenTree/part/templates/part/detail.html @@ -11,113 +11,6 @@ {% block page_content %} -
-
-

{% trans "Part Details" %}

-
-
- - - - - - - - - - - - - - - {% if part.category %} - - - - - - {% endif %} - {% if part.IPN %} - - - - - - {% endif %} - {% if part.revision %} - - - - - - {% endif %} - {% if part.units %} - - - - - - {% endif %} - {% if part.minimum_stock %} - - - - - - {% endif %} - {% if part.keywords %} - - - - - - {% endif %} - {% if part.link %} - - - - - - {% endif %} - - - - - - {% if part.trackable and part.getLatestSerialNumber %} - - - - - - {% endif %} - {% if part.default_location %} - - - - - - {% endif %} - {% if part.default_supplier %} - - - - - - {% endif %} -
{% trans "Name" %}{{ part.name }}{% include "clip.html"%}
{% trans "Description" %}{{ part.description }}{% include "clip.html"%}
{% trans "Category" %} - {{ part.category.name }} -
{% trans "IPN" %}{{ part.IPN }}{% include "clip.html"%}
{% trans "Revision" %}{{ part.revision }}{% include "clip.html"%}
{% trans "Units" %}{{ part.units }}
{% trans "Minimum stock level" %}{{ part.minimum_stock }}
{% trans "Keywords" %}{{ part.keywords }}{% include "clip.html"%}
{% trans "External Link" %}{{ part.link }}{% include "clip.html"%}
{% trans "Creation Date" %} - {{ part.creation_date }} - {% if part.creation_user %} - {{ part.creation_user }} - {% endif %} -
{% trans "Latest Serial Number" %}{{ part.getLatestSerialNumber }}{% include "clip.html"%}
{% trans "Default Location" %} - {{ part.default_location }} -
{% trans "Default Supplier" %}{{ part.default_supplier }}
-
-
-
diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index 4ca7c80d65..4e85853e69 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -99,54 +99,74 @@ {% block details %} - -

-
- {% if part.is_template %} -   - - {% endif %} - {% if part.assembly %} -   - - {% endif %} - {% if part.component %} -   - - {% endif %} - {% if part.trackable %} -   - - {% endif %} - {% if part.purchaseable %} -   - - {% endif %} - {% if part.salable %} -   - - {% endif %} - - {% if not part.active %} -   -
- - {% trans 'Inactive' %} +
+
+ {% if part.is_template %} +   + + {% endif %} + {% if part.assembly %} +   + + {% endif %} + {% if part.component %} +   + + {% endif %} + {% if part.trackable %} +   + + {% endif %} + {% if part.purchaseable %} +   + + {% endif %} + {% if part.salable %} +   + + {% endif %} + + {% if not part.active %} +   +
+ + {% trans 'Inactive' %} +
+ {% endif %} + + {% if part.virtual and part.active %} +   +
+ + {% trans 'Virtual' %} +
+ {% endif %}
- {% endif %} - - {% if part.virtual and part.active %} -   -
- - {% trans 'Virtual' %} -
- {% endif %} + + {% include "spacer.html" %} +

+ + + + + + + + + + + + +
{% trans "Part Name" %}{{ part.full_name }}{% include "clip.html"%}
{% trans "Description" %}{{ part.description }}{% include "clip.html"%}
+
{% if part.variant_of %} @@ -157,7 +177,7 @@ {% endif %}
-{% endblock %} +{% endblock details %} {% block details_right %} @@ -231,7 +251,111 @@ {% endif %} {% endif %}
-{% endblock %} +{% endblock details_right %} + +{% block details_below %} + +
+
+
+ + + + {% if part.category %} + + + + + + {% endif %} + {% if part.IPN %} + + + + + + {% endif %} + {% if part.revision %} + + + + + + {% endif %} + {% if part.units %} + + + + + + {% endif %} + {% if part.minimum_stock %} + + + + + + {% endif %} + {% if part.keywords %} + + + + + + {% endif %} +
{% trans "Category" %} + {{ part.category.name }} +
{% trans "IPN" %}{{ part.IPN }}{% include "clip.html"%}
{% trans "Revision" %}{{ part.revision }}{% include "clip.html"%}
{% trans "Units" %}{{ part.units }}
{% trans "Minimum stock level" %}{{ part.minimum_stock }}
{% trans "Keywords" %}{{ part.keywords }}{% include "clip.html"%}
+
+
+ + + + + + + + {% if part.trackable and part.getLatestSerialNumber %} + + + + + + {% endif %} + {% if part.default_location %} + + + + + + {% endif %} + {% if part.default_supplier %} + + + + + + {% endif %} + {% if part.link %} + + + + + + {% endif %} +
{% trans "Creation Date" %} + {{ part.creation_date }} + {% if part.creation_user %} + {{ part.creation_user }} + {% endif %} +
{% trans "Latest Serial Number" %}{{ part.getLatestSerialNumber }}{% include "clip.html"%}
{% trans "Default Location" %} + {{ part.default_location }} +
{% trans "Default Supplier" %}{{ part.default_supplier }}
{% trans "External Link" %}{{ part.link }}{% include "clip.html"%}
+
+
+
+ +{% endblock details_below %} {% block js_ready %} {{ block.super }} diff --git a/InvenTree/part/templates/part/part_sidebar.html b/InvenTree/part/templates/part/part_sidebar.html index c590c51c37..f4e59af865 100644 --- a/InvenTree/part/templates/part/part_sidebar.html +++ b/InvenTree/part/templates/part/part_sidebar.html @@ -5,8 +5,6 @@ {% settings_value "PART_INTERNAL_PRICE" as show_internal_price %} {% settings_value 'PART_SHOW_RELATED' as show_related %} -{% trans "Details" as text %} -{% include "sidebar_item.html" with label="part-details" text=text icon="fa-shapes" %} {% trans "Parameters" as text %} {% include "sidebar_item.html" with label="part-parameters" text=text icon="fa-th-list" %} {% if part.is_template %} diff --git a/InvenTree/templates/page_base.html b/InvenTree/templates/page_base.html index 506120972a..4e805142d2 100644 --- a/InvenTree/templates/page_base.html +++ b/InvenTree/templates/page_base.html @@ -24,6 +24,8 @@ {% block page_info %}
+ {% block details_above %} + {% endblock details_above %}
@@ -31,23 +33,25 @@
{% block thumbnail %} - {% endblock %} + {% endblock thumbnail %}
{% block details %} - {% endblock %} + {% endblock details %}
- {% endblock %} + {% endblock details_left %}
{% block details_right %} block details_right - {% endblock %} + {% endblock details_right %}
+ {% block details_below %} + {% endblock details_below %}
{% endblock %} From a2d912d3744e1da68dc0c4f1470c66978c101abc Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 30 Nov 2021 19:45:37 +1100 Subject: [PATCH 11/33] Bootstrappy collapse --- InvenTree/part/templates/part/part_base.html | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index 4e85853e69..8c72557d27 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -146,8 +146,7 @@
{% include "spacer.html" %} -
@@ -255,7 +254,7 @@ {% block details_below %} -
+
@@ -563,4 +562,12 @@ }); {% endif %} + $('#collapse-part-details').on('show.bs.collapse', function() { + $('#toggle-details-button').html('{% trans "Hide Part Details" %}'); + }); + + $('#collapse-part-details').on('hide.bs.collapse', function() { + $('#toggle-details-button').html('{% trans "Show Part Details" %}'); + }); + {% endblock %} \ No newline at end of file From 5049f17d0b026dc03e592b330062f7306ca614ae Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 30 Nov 2021 19:49:04 +1100 Subject: [PATCH 12/33] Save toggle state to session --- InvenTree/part/templates/part/part_base.html | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index 8c72557d27..9619a55b38 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -562,12 +562,20 @@ }); {% endif %} + // Callback function when the "part details" panel is shown $('#collapse-part-details').on('show.bs.collapse', function() { $('#toggle-details-button').html('{% trans "Hide Part Details" %}'); + inventreeSave('show-part-details', true); }); + // Callback function when the "part details" panel is hidden $('#collapse-part-details').on('hide.bs.collapse', function() { $('#toggle-details-button').html('{% trans "Show Part Details" %}'); + inventreeSave('show-part-details', false); }); + if (inventreeLoad('show-part-details', false).toString() == 'true') { + $('#collapse-part-details').collapse('show'); + } + {% endblock %} \ No newline at end of file From 3aad2eb13d680473b8714e0a34c3f7c75c8bea8b Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 30 Nov 2021 19:57:07 +1100 Subject: [PATCH 13/33] Refactor title card for "location" view --- InvenTree/stock/templates/stock/location.html | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index 18b78b2290..c956508d76 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -11,7 +11,7 @@ {% if location %} {% trans "Stock Location" %}: {{ location.name }} {% else %} -{% trans "Stock" %} +{% trans "Stock Location" %} {% endif %} {% endblock %} @@ -80,12 +80,32 @@ {% endblock %} {% block details_left %} -{% if location %} -

{{ location.description }}

-{% else %} -

{% trans "Top level stock location" %}

-{% endif %} + + + {% if location %} + {% if location.description %} + + + + + + {% endif %} + + + + + + {% else %} + + + + + + {% endif %} +
{% trans "Description" %}{{ location.description }}
{% trans "Location Path" %}{{ location.pathstring }}
{% trans "Location Path" %}{% trans "Top level stock location" %}
+{% endblock details_left %} +{% block details_below %} {% setting_object 'STOCK_OWNERSHIP_CONTROL' as owner_control %} {% if owner_control.value == "True" %} {% authorized_owners location.owner as owners %} @@ -97,17 +117,12 @@ {% endif %} {% endif %} -{% endblock %} +{% endblock details_below %} {% block details_right %} {% if location %} - - - - - @@ -134,7 +149,7 @@
{% trans "Description" %}{{ location.description }}
{% trans "Sublocations" %}
{% endif %} -{% endblock %} +{% endblock details_right %} {% block page_content %} From 440436c70d0b16856cf6609049eed358a24cf96a Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 30 Nov 2021 20:00:26 +1100 Subject: [PATCH 14/33] Refactor display for "part category" --- InvenTree/part/templates/part/category.html | 43 +++++++++++-------- InvenTree/stock/templates/stock/location.html | 2 +- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/InvenTree/part/templates/part/category.html b/InvenTree/part/templates/part/category.html index bc8a99a3dd..9e6a923dda 100644 --- a/InvenTree/part/templates/part/category.html +++ b/InvenTree/part/templates/part/category.html @@ -61,29 +61,36 @@ {% endblock %} {% block details_left %} -{% if category %} -

{{ category.description }}

-{% else %} -

{% trans "Top level part category" %}

-{% endif %} - -{% endblock %} + + + {% if category %} + {% if category.description %} + + + + + + {% endif %} + + + + + + {% else %} + + + + + + {% endif %} +
{% trans "Description" %}{{ category.description }}
{% trans "Category Path" %}{{ category.pathstring }}
{% trans "Category Path" %}{% trans "Top level part category" %}
+{% endblock details_left %} {% block details_right %} {% if category %} - - - - - - - - - - {% if category.default_location %} @@ -124,7 +131,7 @@
{% trans "Category Path" %}{{ category.pathstring }}
{% trans "Category Description" %}{{ category.description }}
{% endif %} -{% endblock %} +{% endblock details_right %} {% block page_content %} diff --git a/InvenTree/stock/templates/stock/location.html b/InvenTree/stock/templates/stock/location.html index c956508d76..6a201e610c 100644 --- a/InvenTree/stock/templates/stock/location.html +++ b/InvenTree/stock/templates/stock/location.html @@ -11,7 +11,7 @@ {% if location %} {% trans "Stock Location" %}: {{ location.name }} {% else %} -{% trans "Stock Location" %} +{% trans "Stock" %} {% endif %} {% endblock %} From 64abe1e889ea7123dc385fad191aa0224d5e4717 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 30 Nov 2021 20:31:05 +1100 Subject: [PATCH 15/33] Refactoring "company" view --- .../templates/company/company_base.html | 40 ++++--- InvenTree/part/templates/part/category.html | 14 +-- InvenTree/part/templates/part/part_base.html | 108 +++++++++--------- .../stock/templates/stock/item_base.html | 2 - 4 files changed, 86 insertions(+), 78 deletions(-) diff --git a/InvenTree/company/templates/company/company_base.html b/InvenTree/company/templates/company/company_base.html index b9cd650395..e19e8e4e37 100644 --- a/InvenTree/company/templates/company/company_base.html +++ b/InvenTree/company/templates/company/company_base.html @@ -56,7 +56,29 @@ {% endblock %} {% block details %} -

{{ company.description }}

+ + + + + + + + + + + + + + + + + + + + + + +
{% trans "Description" %}{{ company.description }}
{%trans "Manufacturer" %}{% include "yesnolabel.html" with value=company.is_manufacturer %}
{% trans "Supplier" %}{% include 'yesnolabel.html' with value=company.is_supplier %}
{% trans "Customer" %}{% include 'yesnolabel.html' with value=company.is_customer %}
{% endblock %} @@ -110,22 +132,6 @@ {{ company.contact }}{% include "clip.html"%} {% endif %} - - - - {%trans "Manufacturer" %} - {% include "yesnolabel.html" with value=company.is_manufacturer %} - - - - {% trans "Supplier" %} - {% include 'yesnolabel.html' with value=company.is_supplier %} - - - - {% trans "Customer" %} - {% include 'yesnolabel.html' with value=company.is_customer %} - {% endblock %} diff --git a/InvenTree/part/templates/part/category.html b/InvenTree/part/templates/part/category.html index 9e6a923dda..4797571fda 100644 --- a/InvenTree/part/templates/part/category.html +++ b/InvenTree/part/templates/part/category.html @@ -76,6 +76,13 @@ {% trans "Category Path" %} {{ category.pathstring }} + {% if category.default_keywords %} + + + {% trans "Keywords" %} + {{ category.default_keywords }} + + {% endif %} {% else %} @@ -98,13 +105,6 @@ {{ category.default_location.pathstring }} {% endif %} - {% if category.default_keywords %} - - - {% trans "Keywords" %} - {{ category.default_keywords }} - - {% endif %} {% trans "Subcategories" %} diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index 9619a55b38..581b796352 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -100,60 +100,64 @@ {% block details %} -

-
-
- {% if part.is_template %} -   - - {% endif %} - {% if part.assembly %} -   - - {% endif %} - {% if part.component %} -   - - {% endif %} - {% if part.trackable %} -   - - {% endif %} - {% if part.purchaseable %} -   - - {% endif %} - {% if part.salable %} -   - - {% endif %} - - {% if not part.active %} -   -
- - {% trans 'Inactive' %} -
- {% endif %} - - {% if part.virtual and part.active %} -   -
- - {% trans 'Virtual' %} -
- {% endif %} -
- - {% include "spacer.html" %} - -
-

- + + + diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index 111007cd71..37ff88073b 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -148,8 +148,6 @@ {% endif %} - -
{% setting_object 'STOCK_OWNERSHIP_CONTROL' as owner_control %} From 7b43e3e585ab5ae1f9a8a74acda7fde7148ac8c6 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 30 Nov 2021 20:33:41 +1100 Subject: [PATCH 16/33] Refactor sales order page --- .../templates/order/sales_order_base.html | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/InvenTree/order/templates/order/sales_order_base.html b/InvenTree/order/templates/order/sales_order_base.html index 368c3a2e47..12c0eec8f7 100644 --- a/InvenTree/order/templates/order/sales_order_base.html +++ b/InvenTree/order/templates/order/sales_order_base.html @@ -72,13 +72,19 @@ src="{% static 'img/blank_image.png' %}" {% block details %} -

- {% sales_order_status_label order.status large=True %} - {% if order.is_overdue %} - {% trans "Overdue" %} - {% endif %} -

-

{{ order.description }}{% include "clip.html"%}

+
+
+
+
+ {% if part.is_template %} +   + + {% endif %} + {% if part.assembly %} +   + + {% endif %} + {% if part.component %} +   + + {% endif %} + {% if part.trackable %} +   + + {% endif %} + {% if part.purchaseable %} +   + + {% endif %} + {% if part.salable %} +   + + {% endif %} + + {% if not part.active %} +   +
+ + {% trans 'Inactive' %} +
+ {% endif %} + + {% if part.virtual and part.active %} +   +
+ + {% trans 'Virtual' %} +
+ {% endif %} +
+
+ + {% include "spacer.html" %} + + +
+
{% trans "Part Name" %}
+ + + + + + + + + + + +
{% trans "Order Reference" %}{% settings_value 'SALESORDER_REFERENCE_PREFIX' %}{{ order.reference }}{% include "clip.html"%}
{% trans "Order Description" %}{{ order.description }}{% include "clip.html" %}
{% if order.status == SalesOrderStatus.PENDING and not order.is_fully_allocated %} @@ -93,11 +99,6 @@ src="{% static 'img/blank_image.png' %}" {% block details_right %} - - - - - From fd021978515e149d1b3c15eda78b2803f9e43148 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 30 Nov 2021 20:39:28 +1100 Subject: [PATCH 17/33] Refactor purchase order page --- .../order/templates/order/order_base.html | 38 ++++++++++--------- .../order/purchase_order_detail.html | 2 +- .../templates/order/sales_order_base.html | 22 +++++------ 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/InvenTree/order/templates/order/order_base.html b/InvenTree/order/templates/order/order_base.html index 42733d1178..da78b83561 100644 --- a/InvenTree/order/templates/order/order_base.html +++ b/InvenTree/order/templates/order/order_base.html @@ -53,15 +53,17 @@ {% elif order.status == PurchaseOrderStatus.PLACED %} - - {% endif %} {% endif %} -{% endblock %} +{% endblock actions %} {% block thumbnail %} - {% purchase_order_status_label order.status large=True %} - {% if order.is_overdue %} - {% trans "Overdue" %} - {% endif %} - -

{{ order.description }}{% include "clip.html"%}

- -{% endblock %} - -{% block details_right %} -
{% trans "Order Reference" %}{% settings_value 'SALESORDER_REFERENCE_PREFIX' %}{{ order.reference }}{% include "clip.html"%}
{% trans "Order Status" %}
+
+ + + + + @@ -103,6 +99,14 @@ src="{% static 'img/blank_image.png' %}" {% endif %} + +
{% trans "Order Reference" %} {% settings_value 'PURCHASEORDER_REFERENCE_PREFIX' %}{{ order.reference }}{% include "clip.html"%}
{% trans "Order Description" %}{{ order.description }}{% include "clip.html" %}
{% trans "Order Status" %}
+ +{% endblock %} + +{% block details_right %} + + diff --git a/InvenTree/order/templates/order/purchase_order_detail.html b/InvenTree/order/templates/order/purchase_order_detail.html index 3a6ea090d5..90a105caf1 100644 --- a/InvenTree/order/templates/order/purchase_order_detail.html +++ b/InvenTree/order/templates/order/purchase_order_detail.html @@ -27,7 +27,7 @@ {% trans "Add Line Item" %} {% elif order.status == PurchaseOrderStatus.PLACED %} - {% endif %} diff --git a/InvenTree/order/templates/order/sales_order_base.html b/InvenTree/order/templates/order/sales_order_base.html index 12c0eec8f7..2a5a79a161 100644 --- a/InvenTree/order/templates/order/sales_order_base.html +++ b/InvenTree/order/templates/order/sales_order_base.html @@ -68,7 +68,7 @@ src="{% static 'img/blank_image.png' %}" {% endif %} {% endif %} -{% endblock %} +{% endblock actions %} {% block details %} @@ -84,6 +84,16 @@ src="{% static 'img/blank_image.png' %}" + + + + +
{% trans "Supplier" %}{% trans "Order Description" %} {{ order.description }}{% include "clip.html" %}
{% trans "Order Status" %} + {% sales_order_status_label order.status %} + {% if order.is_overdue %} + {% trans "Overdue" %} + {% endif %} +
@@ -99,16 +109,6 @@ src="{% static 'img/blank_image.png' %}" {% block details_right %} - - - - - {% if order.customer %} From defe80e2af39792cbcae5a36f14ad0d92a8eb690 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 30 Nov 2021 20:45:18 +1100 Subject: [PATCH 18/33] Refactor build order display --- .../build/templates/build/build_base.html | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/InvenTree/build/templates/build/build_base.html b/InvenTree/build/templates/build/build_base.html index 22a126fcdf..428e40649f 100644 --- a/InvenTree/build/templates/build/build_base.html +++ b/InvenTree/build/templates/build/build_base.html @@ -12,7 +12,7 @@ {% block breadcrumbs %} -{% endblock %} +{% endblock breadcrumbs %} {% block thumbnail %} -{% endblock %} +{% endblock thumbnail %} {% block heading %} {% trans "Build Order" %} {{ build }} @@ -66,11 +66,23 @@ src="{% static 'img/blank_image.png' %}" {% endif %} {% endif %} -{% endblock %} +{% endblock actions %} {% block details %} -

{{ build.title }}

+
{% trans "Order Status" %} - {% sales_order_status_label order.status %} - {% if order.is_overdue %} - {% trans "Overdue" %} - {% endif %} -
+ + + + + + + + + + + +
{% trans "Part" %}{{ build.part.full_name }}
{% trans "Build Description" %}{{ build.title }}
{% if build.sales_order %} @@ -114,11 +126,7 @@ src="{% static 'img/blank_image.png' %}" {% block details_right %} - - - - - + From 1ce1710c5095969e2ecff732158e4e7264abb444 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 30 Nov 2021 20:49:52 +1100 Subject: [PATCH 19/33] Refactor manufacturer part display --- .../templates/company/manufacturer_part.html | 84 ++++++++++--------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/InvenTree/company/templates/company/manufacturer_part.html b/InvenTree/company/templates/company/manufacturer_part.html index fcfa22ee2d..84e8016a59 100644 --- a/InvenTree/company/templates/company/manufacturer_part.html +++ b/InvenTree/company/templates/company/manufacturer_part.html @@ -8,7 +8,7 @@ InvenTree | {% trans "Manufacturer Part" %} {% block sidebar %} {% include "company/manufacturer_part_sidebar.html" %} -{% endblock %} +{% endblock sidebar %} {% block breadcrumbs %} @@ -16,13 +16,13 @@ InvenTree | {% trans "Manufacturer Part" %} {% endif %} -{% endblock %} +{% endblock breadcrumbs %} {% block heading %}

{% trans "Manufacturer Part" %}: {{ part.part.full_name }}

-{% endblock %} +{% endblock heading %} {% block actions %} {% if user.is_staff and perms.company.change_company %} @@ -46,7 +46,7 @@ InvenTree | {% trans "Manufacturer Part" %} {% endif %} {% endif %} -{% endblock %} +{% endblock actions %} {% block thumbnail %} -{% endblock %} +{% endblock thumbnail %} {% block details %} -{% endblock %} +
{% trans "Part" %}{{ build.part.full_name }}
{% trans "Quantity" %}
+ + + + + + + {% if part.description %} + + + + + + {% endif %} +
{% trans "Internal Part" %} + {% if part.part %} + {{ part.part.full_name }}{% include "clip.html"%} + {% endif %} +
{% trans "Description" %}{{ part.description }}{% include "clip.html"%}
+ +{% endblock details %} {% block details_right %} - - - - - - {% if part.description %} - - - - - - {% endif %} - {% if part.link %} - - - - - - {% endif %} - - - - - - - - - + + + + + + + + + + + + {% if part.link %} + + + + + + {% endif %}
{% trans "Internal Part" %} - {% if part.part %} - {{ part.part.full_name }}{% include "clip.html"%} - {% endif %} -
{% trans "Description" %}{{ part.description }}{% include "clip.html"%}
{% trans "External Link" %}{{ part.link }}{% include "clip.html"%}
{% trans "Manufacturer" %}{{ part.manufacturer.name }}{% include "clip.html"%}
{% trans "MPN" %}{{ part.MPN }}{% include "clip.html"%}
{% trans "Manufacturer" %}{{ part.manufacturer.name }}{% include "clip.html"%}
{% trans "MPN" %}{{ part.MPN }}{% include "clip.html"%}
{% trans "External Link" %}{{ part.link }}{% include "clip.html"%}
-{% endblock %} +{% endblock details_right %} {% block page_content %} From e88ea8d15723accd2505346802c0b5fbe600a409 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 30 Nov 2021 20:53:01 +1100 Subject: [PATCH 20/33] Refactor supplier part display --- .../templates/company/supplier_part.html | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/InvenTree/company/templates/company/supplier_part.html b/InvenTree/company/templates/company/supplier_part.html index 276a9f7ebc..89e8f91493 100644 --- a/InvenTree/company/templates/company/supplier_part.html +++ b/InvenTree/company/templates/company/supplier_part.html @@ -5,11 +5,11 @@ {% block page_title %} {% inventree_title %} | {% trans "Supplier Part" %} -{% endblock %} +{% endblock page_title %} {% block sidebar %} {% include "company/supplier_part_sidebar.html" %} -{% endblock %} +{% endblock sidebar %} {% block breadcrumbs %} @@ -17,13 +17,13 @@ {% endif %} -{% endblock %} +{% endblock breadcrumbs %} {% block heading %}

{% trans "Supplier Part" %}: {{ part.SKU }}

-{% endblock %} +{% endblock heading %} {% block actions %} {% if user.is_staff and perms.company.change_company %} @@ -43,7 +43,7 @@ {% endif %} -{% endblock %} +{% endblock actions %} {% block thumbnail %} - {{ part.part.full_name }} -

+ + + + + + + + {% if part.description %} + + + + + + {% endif %} +
{% trans "Internal Part" %} + {% if part.part %} + {{ part.part.full_name }}{% include "clip.html"%} + {% endif %} +
{% trans "Description" %}{{ part.description }}{% include "clip.html"%}
-{% endblock %} +{% endblock details %} {% block details_right %} - - - - - - {% if part.description %} - - - - - - {% endif %} - {% if part.link %} - - - - - - {% endif %} @@ -127,6 +120,13 @@ src="{% static 'img/blank_image.png' %}" {% endif %} + {% if part.link %} + + + + + + {% endif %}
{% trans "Internal Part" %} - {% if part.part %} - {{ part.part.full_name }}{% include "clip.html"%} - {% endif %} -
{% trans "Description" %}{{ part.description }}{% include "clip.html"%}
{% trans "External Link" %}{{ part.link }}{% include "clip.html"%}
{% trans "Supplier" %}{{ part.note }}{% include "clip.html"%}
{% trans "External Link" %}{{ part.link }}{% include "clip.html"%}
{% endblock %} From 91c8d9fee35d8d75733d1007449c129adf04a414 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 30 Nov 2021 20:59:37 +1100 Subject: [PATCH 21/33] Refactor stock item view --- .../stock/templates/stock/item_base.html | 174 ++++++++---------- 1 file changed, 81 insertions(+), 93 deletions(-) diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index 37ff88073b..e969ac482f 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -14,7 +14,7 @@ {% block heading %} {% trans "Stock Item" %}: {{ item.part.full_name}} -{% endblock %} +{% endblock heading %} {% block actions %} @@ -118,36 +118,94 @@
{% endif %} {% endif %} -{% endblock %} +{% endblock actions %} {% block thumbnail %} -{% endblock %} +{% endblock thumbnail %} {% block details %} + + + + + + + + {% if item.serialized %} + + + + + + {% else %} + + + + + + {% endif %} + + + + + + {% if item.expiry_date %} + + + + + + {% endif %} + + + + + + + + + {% if item.stocktake_date %} + + {% else %} + + {% endif %} + +
{% trans "Base Part" %} + {% if roles.part.view %} + + {% endif %} + {{ item.part.full_name }} + {% if roles.part.view %} + + {% endif %} +
{% trans "Serial Number" %} + {% if previous %} + + {{ previous.serial }} ‹ + + {% endif %} + {{ item.serial }} + {% if next %} + + › {{ next.serial }} + + {% endif %} +
{% trans "Quantity" %}{% decimal item.quantity %} {% if item.part.units %}{{ item.part.units }}{% endif %}
{% trans "Status" %}{% stock_status_label item.status %}
{% trans "Expiry Date" %} + {{ item.expiry_date }} + {% if item.is_expired %} + {% trans "Expired" %} + {% elif item.is_stale %} + {% trans "Stale" %} + {% endif %} +
{% trans "Last Updated" %}{{ item.updated }}
{% trans "Last Stocktake" %}{{ item.stocktake_date }} {{ item.stocktake_user }}{% trans "No stocktake performed" %}
+ {% setting_object 'STOCK_OWNERSHIP_CONTROL' as owner_control %} {% if owner_control.value == "True" %} {% authorized_owners item.owner as owners %} {% endif %} -

- {% if item.is_expired %} - {% trans "Expired" %} - {% else %} - {% if roles.stock.change %} - - {% endif %} - {% stock_status_label item.status large=True %} - {% if roles.stock.change %} - - {% endif %} - {% if item.is_stale %} - {% trans "Stale" %} - {% endif %} - {% endif %} -

-
{% setting_object 'STOCK_OWNERSHIP_CONTROL' as owner_control %} @@ -212,49 +270,12 @@ {% endif %}
-{% endblock %} +{% endblock details %} {% block details_right %} - +
- - - - - - {% if item.serialized %} - - - - - - {% else %} - - - - - - {% endif %} + {% if item.customer %} @@ -374,39 +395,6 @@ {% endif %} - {% if item.expiry_date %} - - - - - - {% endif %} - - - - - - - - - {% if item.stocktake_date %} - - {% else %} - - {% endif %} - - - - - - {% if item.hasRequiredTests %} From c01c0b0e25f29e62f539c613751238bc1ee8fc94 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 30 Nov 2021 21:13:55 +1100 Subject: [PATCH 22/33] Refactor company buttons --- .../templates/company/company_base.html | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/InvenTree/company/templates/company/company_base.html b/InvenTree/company/templates/company/company_base.html index e19e8e4e37..3903dba685 100644 --- a/InvenTree/company/templates/company/company_base.html +++ b/InvenTree/company/templates/company/company_base.html @@ -19,21 +19,26 @@ {% include "admin_button.html" with url=url %} {% endif %} {% if company.is_supplier and roles.purchase_order.add %} - {% endif %} -{% if perms.company.change_company %} - -{% endif %} -{% if perms.company.delete_company %} - -{% endif %} -{% endblock %} + +{% endblock actions %} {% block thumbnail %}
From a2a436ea693708368dce2bb205ecb29cc719ec94 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 1 Dec 2021 08:05:30 +1100 Subject: [PATCH 23/33] Column improvements --- InvenTree/part/templates/part/part_base.html | 5 --- .../stock/templates/stock/item_base.html | 4 +- InvenTree/templates/page_base.html | 44 ++++++++++--------- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index 581b796352..994eefe94e 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -158,11 +158,6 @@
- - - - - diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index e969ac482f..5f22076d9a 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -100,7 +100,9 @@ {% if roles.stock.change and not item.is_building %}
- +
{% else %} From 98bbee81597fc00baafa854c683ae936dfd0dafc Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 2 Dec 2021 15:55:00 +1100 Subject: [PATCH 32/33] Adds function to lookup stock item by serial number --- InvenTree/InvenTree/version.py | 6 +- InvenTree/stock/api.py | 14 +++- .../stock/templates/stock/item_base.html | 4 + InvenTree/templates/js/translated/stock.js | 82 +++++++++++++++++++ 4 files changed, 104 insertions(+), 2 deletions(-) diff --git a/InvenTree/InvenTree/version.py b/InvenTree/InvenTree/version.py index e0e64f5525..bbf0174453 100644 --- a/InvenTree/InvenTree/version.py +++ b/InvenTree/InvenTree/version.py @@ -12,11 +12,15 @@ import common.models INVENTREE_SW_VERSION = "0.6.0 dev" # InvenTree API version -INVENTREE_API_VERSION = 18 +INVENTREE_API_VERSION = 19 """ Increment this API version number whenever there is a significant change to the API that any clients need to know about +v19 -> 2021-12-02 + - Adds the ability to filter the StockItem API by "part_tree" + - Returns only stock items which match a particular part.tree_id field + v18 -> 2021-11-15 - Adds the ability to filter BomItem API by "uses" field - This returns a list of all BomItems which "use" the specified part diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index fcfa58d01a..8385041209 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -313,7 +313,7 @@ class StockFilter(rest_filters.FilterSet): # Serial number filtering serial_gte = rest_filters.NumberFilter(label='Serial number GTE', field_name='serial', lookup_expr='gte') serial_lte = rest_filters.NumberFilter(label='Serial number LTE', field_name='serial', lookup_expr='lte') - serial = rest_filters.NumberFilter(label='Serial number', field_name='serial', lookup_expr='exact') + serial = rest_filters.CharFilter(label='Serial number', field_name='serial', lookup_expr='exact') serialized = rest_filters.BooleanFilter(label='Has serial number', method='filter_serialized') @@ -703,6 +703,18 @@ class StockList(generics.ListCreateAPIView): except (ValueError, StockItem.DoesNotExist): pass + # Filter by "part tree" - only allow parts within a given variant tree + part_tree = params.get('part_tree', None) + + if part_tree is not None: + try: + part = Part.objects.get(pk=part_tree) + + if part.tree_id is not None: + queryset = queryset.filter(part__tree_id=part.tree_id) + except: + pass + # Filter by 'allocated' parts? allocated = params.get('allocated', None) diff --git a/InvenTree/stock/templates/stock/item_base.html b/InvenTree/stock/templates/stock/item_base.html index ac6753e565..0d5ab272d6 100644 --- a/InvenTree/stock/templates/stock/item_base.html +++ b/InvenTree/stock/templates/stock/item_base.html @@ -599,4 +599,8 @@ $("#stock-return-from-customer").click(function() { {% endif %} +$('#serial-number-search').click(function() { + findStockItemBySerialNumber({{ item.part.pk }}); +}); + {% endblock %} diff --git a/InvenTree/templates/js/translated/stock.js b/InvenTree/templates/js/translated/stock.js index 5e92299f03..02ea3c2c3b 100644 --- a/InvenTree/templates/js/translated/stock.js +++ b/InvenTree/templates/js/translated/stock.js @@ -44,6 +44,7 @@ editStockItem, editStockLocation, exportStock, + findStockItemBySerialNumber, loadInstalledInTable, loadStockLocationTable, loadStockTable, @@ -394,6 +395,87 @@ function createNewStockItem(options={}) { constructForm(url, options); } +/* + * Launch a modal form to find a particular stock item by serial number. + * Arguments: + * - part: ID (PK) of the part in question + */ + +function findStockItemBySerialNumber(part_id) { + + constructFormBody({}, { + title: '{% trans "Find Serial Number" %}', + fields: { + serial: { + label: '{% trans "Serial Number" %}', + help_text: '{% trans "Enter serial number" %}', + placeholder: '{% trans "Enter serial number" %}', + required: true, + type: 'string', + value: '', + } + }, + onSubmit: function(fields, opts) { + + var serial = getFormFieldValue('serial', fields['serial'], opts); + + serial = serial.toString().trim(); + + if (!serial) { + handleFormErrors( + { + 'serial': [ + '{% trans "Enter a serial number" %}', + ] + }, fields, opts + ); + return; + } + + inventreeGet( + '{% url "api-stock-list" %}', + { + part_tree: part_id, + serial: serial, + }, + { + success: function(response) { + if (response.length == 0) { + // No results! + handleFormErrors( + { + 'serial': [ + '{% trans "No matching serial number" %}', + ] + }, fields, opts + ); + } else if (response.length > 1) { + // Too many results! + handleFormErrors( + { + 'serial': [ + '{% trans "More than one matching result found" %}', + ] + }, fields, opts + ); + } else { + $(opts.modal).modal('hide'); + + // Redirect + var pk = response[0].pk; + location.href = `/stock/item/${pk}/`; + } + }, + error: function(xhr) { + showApiError(xhr, opts.url); + $(opts.modal).modal('hide'); + } + } + ); + } + }); +} + /* Stock API functions * Requires api.js to be loaded first From e96ff7fbbaaa3c086493aacb3d300c2dcd3ebf0c Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 2 Dec 2021 16:01:28 +1100 Subject: [PATCH 33/33] Add lookup-by-sn on part page, too --- InvenTree/part/templates/part/part_base.html | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index 994eefe94e..d2505a57f7 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -322,7 +322,14 @@ - + {% endif %} {% if part.default_location %} @@ -577,4 +584,8 @@ $('#collapse-part-details').collapse('show'); } + $('#serial-number-search').click(function() { + findStockItemBySerialNumber({{ part.pk }}); + }); + {% endblock %} \ No newline at end of file
{% trans "Base Part" %} - {% if roles.part.view %} - - {% endif %} - {{ item.part.full_name }} - {% if roles.part.view %} - - {% endif %} -
{% trans "Serial Number" %} - {% if previous %} - - {{ previous.serial }} ‹ - - {% endif %} - {{ item.serial }} - {% if next %} - - › {{ next.serial }} - - {% endif %} -
{% trans "Quantity" %}{% decimal item.quantity %} {% if item.part.units %}{{ item.part.units }}{% endif %}
{{ item.supplier_part.SKU }}
{% trans "Expiry Date" %} - {{ item.expiry_date }} - {% if item.is_expired %} - {% trans "Expired" %} - {% elif item.is_stale %} - {% trans "Stale" %} - {% endif %} -
{% trans "Last Updated" %}{{ item.updated }}
{% trans "Last Stocktake" %}{{ item.stocktake_date }} {{ item.stocktake_user }}{% trans "No stocktake performed" %}
{% trans "Status" %}{% stock_status_label item.status %}
{% trans "Part Name" %}{{ part.full_name }}{% include "clip.html"%}
{% trans "Description" %} {% trans "Serial Number" %} - {% if previous %} - - {{ previous.serial }} ‹ - - {% endif %} - {{ item.serial }} - {% if next %} - - › {{ next.serial }} - - {% endif %} + {{ item.serial }} +
+ {% if previous %} + + + {{ previous.serial }} + + {% endif %} + + + + {% if next %} + + {{ next.serial }} + + + {% endif %} +
{% trans "Latest Serial Number" %}{{ part.getLatestSerialNumber }}{% include "clip.html"%} + {{ part.getLatestSerialNumber }} +
+ + + +
+