From d2b9993e96eb6658be2060490630033bb89a4404 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 24 Sep 2021 12:04:25 +1000 Subject: [PATCH 01/24] Fix form filters for "default_supplier" --- InvenTree/templates/js/translated/part.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/InvenTree/templates/js/translated/part.js b/InvenTree/templates/js/translated/part.js index 9abbd2a0b9..e74b6fd743 100644 --- a/InvenTree/templates/js/translated/part.js +++ b/InvenTree/templates/js/translated/part.js @@ -94,7 +94,12 @@ function partFields(options={}) { }, default_location: { }, - default_supplier: {}, + default_supplier: { + filters: { + part_detail: true, + supplier_detail: true, + } + }, default_expiry: { icon: 'fa-calendar-alt', }, @@ -315,6 +320,9 @@ function editPart(pk) { edit: true }); + // Filter supplied parts by the Part ID + fields.default_supplier.filters.part = pk; + var groups = partGroups({}); constructForm(url, { From f53aac0784f158ce2508e1810b20262abf09f6f5 Mon Sep 17 00:00:00 2001 From: Oliver Date: Fri, 24 Sep 2021 12:04:36 +1000 Subject: [PATCH 02/24] Remove "default_supplier" field when duplicating a part --- InvenTree/templates/js/translated/part.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/InvenTree/templates/js/translated/part.js b/InvenTree/templates/js/translated/part.js index e74b6fd743..6e8c02c0b1 100644 --- a/InvenTree/templates/js/translated/part.js +++ b/InvenTree/templates/js/translated/part.js @@ -346,6 +346,9 @@ function duplicatePart(pk, options={}) { duplicate: pk, }); + // Remove "default_supplier" field + delete fields['default_supplier']; + // If we are making a "variant" part if (options.variant) { From beaa93f9b577515b8fd876d8e8e7d72a0d12eb1a Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 27 Sep 2021 11:41:24 +1000 Subject: [PATCH 03/24] Fix ?display= URLs for part stock view --- InvenTree/templates/js/translated/bom.js | 2 +- InvenTree/templates/js/translated/part.js | 2 +- InvenTree/templates/js/translated/stock.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/InvenTree/templates/js/translated/bom.js b/InvenTree/templates/js/translated/bom.js index bcfa7ef5ff..8f571df02e 100644 --- a/InvenTree/templates/js/translated/bom.js +++ b/InvenTree/templates/js/translated/bom.js @@ -271,7 +271,7 @@ function loadBomTable(table, options) { sortable: true, formatter: function(value, row) { - var url = `/part/${row.sub_part_detail.pk}/?display=stock`; + var url = `/part/${row.sub_part_detail.pk}/?display=part-stock`; var text = value; if (value == null || value <= 0) { diff --git a/InvenTree/templates/js/translated/part.js b/InvenTree/templates/js/translated/part.js index 6e8c02c0b1..afd1b4def8 100644 --- a/InvenTree/templates/js/translated/part.js +++ b/InvenTree/templates/js/translated/part.js @@ -539,7 +539,7 @@ function loadPartVariantTable(table, partId, options={}) { field: 'in_stock', title: '{% trans "Stock" %}', formatter: function(value, row) { - return renderLink(value, `/part/${row.pk}/?display=stock`); + return renderLink(value, `/part/${row.pk}/?display=part-stock`); } } ]; diff --git a/InvenTree/templates/js/translated/stock.js b/InvenTree/templates/js/translated/stock.js index e35831624e..17c2598d1b 100644 --- a/InvenTree/templates/js/translated/stock.js +++ b/InvenTree/templates/js/translated/stock.js @@ -1019,7 +1019,7 @@ function loadStockTable(table, options) { return '-'; } - var link = `/supplier-part/${row.supplier_part}/?display=stock`; + var link = `/supplier-part/${row.supplier_part}/?display=part-stock`; var text = ''; From ef01bdff07e818fca2d386b790461d78cad82ce6 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 27 Sep 2021 11:42:47 +1000 Subject: [PATCH 04/24] Fix links in part table --- InvenTree/templates/js/translated/part.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/InvenTree/templates/js/translated/part.js b/InvenTree/templates/js/translated/part.js index afd1b4def8..aba3c46330 100644 --- a/InvenTree/templates/js/translated/part.js +++ b/InvenTree/templates/js/translated/part.js @@ -945,7 +945,7 @@ function loadPartTable(table, url, options={}) { title: '{% trans "Stock" %}', searchable: false, formatter: function(value, row) { - var link = 'stock'; + var link = '?display=part-stock'; if (value) { // There IS stock available for this part @@ -958,17 +958,17 @@ function loadPartTable(table, url, options={}) { } else if (row.on_order) { // There is no stock available, but stock is on order value = `0{% trans "On Order" %}: ${row.on_order}`; - link = 'orders'; + link = '?display=purchase-orders'; } else if (row.building) { // There is no stock available, but stock is being built value = `0{% trans "Building" %}: ${row.building}`; - link = 'builds'; + link = '?display=build-orders'; } else { // There is no stock available value = `0{% trans "No Stock" %}`; } - return renderLink(value, `/part/${row.pk}/${link}/`); + return renderLink(value, `/part/${row.pk}/${link}`); } }; From 26e3dbd9d0ce56ff32a520b40fe93eaa083de394 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 27 Sep 2021 11:46:14 +1000 Subject: [PATCH 05/24] Remove debug message --- InvenTree/InvenTree/version.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/InvenTree/InvenTree/version.py b/InvenTree/InvenTree/version.py index 33a4aa3c0e..f302c84d6f 100644 --- a/InvenTree/InvenTree/version.py +++ b/InvenTree/InvenTree/version.py @@ -88,9 +88,6 @@ def isInvenTreeDevelopmentVersion(): """ Return True if current InvenTree version is a "development" version """ - - print("is dev?", inventreeVersion()) - return inventreeVersion().endswith('dev') From eb48c6ebdb48e64e98e1bf93283798e2128fd0f9 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 28 Sep 2021 09:29:14 +1000 Subject: [PATCH 06/24] Delete app_issue.md --- .github/ISSUE_TEMPLATE/app_issue.md | 30 ----------------------------- 1 file changed, 30 deletions(-) delete mode 100644 .github/ISSUE_TEMPLATE/app_issue.md diff --git a/.github/ISSUE_TEMPLATE/app_issue.md b/.github/ISSUE_TEMPLATE/app_issue.md deleted file mode 100644 index e71861394c..0000000000 --- a/.github/ISSUE_TEMPLATE/app_issue.md +++ /dev/null @@ -1,30 +0,0 @@ ---- -name: App issue -about: Report a bug or issue with the InvenTree app -title: "[APP] Enter bug description" -labels: bug, app -assignees: '' - ---- - -**Describe the bug** -A clear and concise description of the bug or issue - -**To Reproduce** -Steps to reproduce the behavior: - -1. Go to ... -2. Select ... -3. ... - -**Expected Behavior** -A clear and concise description of what you expected to happen - -**Screenshots** -If applicable, add screenshots to help explain your problem - -**Version Information** - -- App platform: *Select iOS or Android* -- App version: *Enter app version* -- Server version: *Enter server version* From 16e00962f5f5b46cc09910ff0be2a5a5ee4ebf1e Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 28 Sep 2021 10:14:25 +1000 Subject: [PATCH 07/24] Override the "delete" behaviour for StockItem API - Mark for deletion instead of calling database delete - Returns (almost) instantly instead of hanging - Much better UI experience when performing bulk delete operations --- InvenTree/stock/api.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 017457f600..eaa65dd763 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -109,6 +109,17 @@ class StockDetail(generics.RetrieveUpdateDestroyAPIView): return super().update(request, *args, **kwargs) + def perform_destroy(self, instance): + """ + Instead of "deleting" the StockItem + (which may take a long time) + we instead schedule it for deletion at a later date. + + The background worker will delete these in the future + """ + + instance.mark_for_deletion() + class StockAdjust(APIView): """ From 2d9ca7c1b654062d804c7ddcda52b6ac08c09cf5 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 28 Sep 2021 10:36:01 +1000 Subject: [PATCH 08/24] Do not rebuild the entire StockItem tree every time a single StockItem is deleted! --- InvenTree/stock/models.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 3344dec0eb..1372e63406 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -1650,9 +1650,6 @@ def before_delete_stock_item(sender, instance, using, **kwargs): child.parent = instance.parent child.save() - # Rebuild the MPTT tree - StockItem.objects.rebuild() - class StockItemAttachment(InvenTreeAttachment): """ From d9704f4123e1cbe5f840bd7964ec8eb12cd7854a Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 28 Sep 2021 10:41:03 +1000 Subject: [PATCH 09/24] Add unit test for deleting stock items via the API --- InvenTree/stock/test_api.py | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/InvenTree/stock/test_api.py b/InvenTree/stock/test_api.py index 619b4444d7..3b6facc9a6 100644 --- a/InvenTree/stock/test_api.py +++ b/InvenTree/stock/test_api.py @@ -18,6 +18,7 @@ from InvenTree.api_tester import InvenTreeAPITestCase from common.models import InvenTreeSetting from .models import StockItem, StockLocation +from .tasks import delete_old_stock_items class StockAPITestCase(InvenTreeAPITestCase): @@ -37,6 +38,7 @@ class StockAPITestCase(InvenTreeAPITestCase): 'stock.add', 'stock_location.change', 'stock_location.add', + 'stock.delete', ] def setUp(self): @@ -591,6 +593,61 @@ class StocktakeTest(StockAPITestCase): self.assertContains(response, 'Valid location must be specified', status_code=status.HTTP_400_BAD_REQUEST) +class StockItemDeletionTest(StockAPITestCase): + """ + Tests for stock item deletion via the API + """ + + def test_delete(self): + + # Check there are no stock items scheduled for deletion + self.assertEqual( + StockItem.objects.filter(scheduled_for_deletion=True).count(), + 0 + ) + + # Create and then delete a bunch of stock items + for idx in range(10): + + # Create new StockItem via the API + response = self.post( + reverse('api-stock-list'), + { + 'part': 1, + 'location': 1, + 'quantity': idx, + }, + expected_code=201 + ) + + pk = response.data['pk'] + + item = StockItem.objects.get(pk=pk) + + self.assertFalse(item.scheduled_for_deletion) + + url = reverse('api-stock-detail', kwargs={'pk': pk}) + + # Request deletion via the API + self.delete( + reverse('api-stock-detail', kwargs={'pk': pk}), + expected_code=204 + ) + + # There should be 100x StockItem objects marked for deletion + self.assertEqual( + StockItem.objects.filter(scheduled_for_deletion=True).count(), + 10 + ) + + # Perform the actual delete (will take some time) + delete_old_stock_items() + + self.assertEqual( + StockItem.objects.filter(scheduled_for_deletion=True).count(), + 0 + ) + class StockTestResultTest(StockAPITestCase): def get_url(self): From 62e62af5fc08cde8bd7b9102d6685c5a2194e80e Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 28 Sep 2021 10:41:30 +1000 Subject: [PATCH 10/24] PEP style fixes --- InvenTree/stock/test_api.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/InvenTree/stock/test_api.py b/InvenTree/stock/test_api.py index 3b6facc9a6..21c355fae2 100644 --- a/InvenTree/stock/test_api.py +++ b/InvenTree/stock/test_api.py @@ -626,8 +626,6 @@ class StockItemDeletionTest(StockAPITestCase): self.assertFalse(item.scheduled_for_deletion) - url = reverse('api-stock-detail', kwargs={'pk': pk}) - # Request deletion via the API self.delete( reverse('api-stock-detail', kwargs={'pk': pk}), @@ -648,6 +646,7 @@ class StockItemDeletionTest(StockAPITestCase): 0 ) + class StockTestResultTest(StockAPITestCase): def get_url(self): From b1730914c32ae38a8f8c7d04520d0c79d1e77959 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 29 Sep 2021 22:12:20 +1000 Subject: [PATCH 11/24] Display "full_name" rather than "name" in quick search bar --- InvenTree/templates/js/dynamic/inventree.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/templates/js/dynamic/inventree.js b/InvenTree/templates/js/dynamic/inventree.js index 7d608c1886..5cd7bfcb80 100644 --- a/InvenTree/templates/js/dynamic/inventree.js +++ b/InvenTree/templates/js/dynamic/inventree.js @@ -116,7 +116,7 @@ function inventreeDocReady() { success: function(data) { var transformed = $.map(data.results, function(el) { return { - label: el.name, + label: el.full_name, id: el.pk, thumbnail: el.thumbnail }; From 1e9ae927d43c45b76a5f14bcdc5ccd3e0d96b462 Mon Sep 17 00:00:00 2001 From: eeintech Date: Wed, 29 Sep 2021 11:48:27 -0400 Subject: [PATCH 12/24] Show part delete button when part still active --- InvenTree/part/templates/part/part_base.html | 4 ++-- .../part/templates/part/partial_delete.html | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index b91ff53118..0228c4df66 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -130,7 +130,7 @@ {% if roles.part.change %}
  • {% trans "Edit part" %}
  • {% endif %} - {% if not part.active and roles.part.delete %} + {% if roles.part.delete %}
  • {% trans "Delete part" %}
  • {% endif %} @@ -503,7 +503,7 @@ }); {% endif %} - {% if not part.active and roles.part.delete %} + {% if roles.part.delete %} $("#part-delete").click(function() { launchModalForm( "{% url 'part-delete' part.id %}", diff --git a/InvenTree/part/templates/part/partial_delete.html b/InvenTree/part/templates/part/partial_delete.html index 993d7a418c..eb23fbee09 100644 --- a/InvenTree/part/templates/part/partial_delete.html +++ b/InvenTree/part/templates/part/partial_delete.html @@ -3,6 +3,16 @@ {% block pre_form_content %} +{% if part.active %} + +
    + {% blocktrans with full_name=part.full_name %}Part '{{full_name}}' cannot be deleted as it is still marked as active. +
    Disable the "Active" part attribute and re-try. + {% endblocktrans %} +
    + +{% else %} +
    {% blocktrans with full_name=part.full_name %}Are you sure you want to delete part '{{full_name}}'?{% endblocktrans %}
    @@ -55,4 +65,12 @@

    {% blocktrans with count=part.serials.all|length full_name=part.full_name %}There are {{count}} unique parts tracked for '{{full_name}}'. Deleting this part will permanently remove this tracking information.{% endblocktrans %}

    {% endif %} +{% endif %} + +{% endblock %} + +{% block form %} +{% if not part.active %} +{{ block.super }} +{% endif %} {% endblock %} \ No newline at end of file From b3422e592d45d6fb88248469647c941e7d62daab Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 30 Sep 2021 10:46:22 +1000 Subject: [PATCH 13/24] Update README.md --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index e0b21f7e61..a8d429c249 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,6 @@ However, powerful business logic works in the background to ensure that stock tr # Docker [![Docker Pulls](https://img.shields.io/docker/pulls/inventree/inventree)](https://hub.docker.com/r/inventree/inventree) -![Docker Build](https://github.com/inventree/inventree/actions/workflows/docker_build.yaml/badge.svg) InvenTree is [available via Docker](https://hub.docker.com/r/inventree/inventree). Read the [docker guide](https://inventree.readthedocs.io/en/latest/start/docker/) for full details. From 6cf144c61f3d7e169aa20ca2d0918c52432dcfc2 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 30 Sep 2021 17:53:14 +1000 Subject: [PATCH 14/24] Retain "original" search parameter in query --- InvenTree/templates/js/translated/tables.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/InvenTree/templates/js/translated/tables.js b/InvenTree/templates/js/translated/tables.js index 6e719563ae..3138c1e73d 100644 --- a/InvenTree/templates/js/translated/tables.js +++ b/InvenTree/templates/js/translated/tables.js @@ -181,6 +181,15 @@ function convertQueryParameters(params, filters) { if ('sortable' in params) { delete params['sortable']; } + + // If "original_search" parameter is provided, add it to the "search" + if ('original_search' in params) { + var search = params['search'] || ''; + + params['search'] = search + ' ' + params['original_search']; + + delete params['original_search']; + } return params; } From 4ced13466a64e27f29678c23552445e000923365 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 30 Sep 2021 17:57:19 +1000 Subject: [PATCH 15/24] Use "original_search" rather than "search" --- InvenTree/templates/InvenTree/search.html | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/InvenTree/templates/InvenTree/search.html b/InvenTree/templates/InvenTree/search.html index af0711bc35..0fba0add0d 100644 --- a/InvenTree/templates/InvenTree/search.html +++ b/InvenTree/templates/InvenTree/search.html @@ -117,7 +117,7 @@ "{% url 'api-part-list' %}", { params: { - search: "{{ query }}", + original_search: "{{ query }}", }, checkbox: false, disableFilters: true, @@ -129,7 +129,7 @@ $("#table-category").inventreeTable({ url: "{% url 'api-part-category-list' %}", queryParams: { - search: "{{ query }}", + original_search: "{{ query }}", }, columns: [ { @@ -153,7 +153,7 @@ "{% url 'api-manufacturer-part-list' %}", { params: { - search: "{{ query }}", + original_search: "{{ query }}", part_detail: true, supplier_detail: true, manufacturer_detail: true @@ -168,7 +168,7 @@ "{% url 'api-supplier-part-list' %}", { params: { - search: "{{ query }}", + original_search: "{{ query }}", part_detail: true, supplier_detail: true, manufacturer_detail: true @@ -186,7 +186,7 @@ loadBuildTable('#table-build-order', { params: { - search: '{{ query }}', + original_search: '{{ query }}', } }); @@ -200,7 +200,7 @@ $('#table-stock').inventreeTable({ url: "{% url 'api-stock-list' %}", queryParams: { - search: "{{ query }}", + original_search: "{{ query }}", part_detail: true, location_detail: true, }, @@ -281,7 +281,7 @@ $("#table-location").inventreeTable({ url: "{% url 'api-location-list' %}", queryParams: { - search: "{{ query }}", + original_search: "{{ query }}", }, columns: [ { @@ -307,7 +307,7 @@ loadCompanyTable('#table-manufacturer', "{% url 'api-company-list' %}", { params: { - search: "{{ query }}", + original_search: "{{ query }}", is_manufacturer: "true", } }); @@ -317,7 +317,7 @@ loadCompanyTable('#table-supplier', "{% url 'api-company-list' %}", { params: { - search: "{{ query }}", + original_search: "{{ query }}", is_supplier: "true", } }); @@ -326,7 +326,7 @@ loadPurchaseOrderTable('#table-purchase-order', { params: { - search: '{{ query }}', + original_search: '{{ query }}', } }); @@ -337,7 +337,7 @@ loadCompanyTable('#table-customer', "{% url 'api-company-list' %}", { params: { - search: "{{ query }}", + original_search: "{{ query }}", is_customer: "true", } }); @@ -346,7 +346,7 @@ loadSalesOrderTable('#table-sales-orders', { params: { - search: '{{ query }}', + original_search: '{{ query }}', } }); From 15d96a3288610f2e4420d4a527dd4a1706ec8e01 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 30 Sep 2021 19:50:16 +1000 Subject: [PATCH 16/24] Fix for URL in supplier parts table --- InvenTree/templates/js/translated/company.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/InvenTree/templates/js/translated/company.js b/InvenTree/templates/js/translated/company.js index c014139e1b..3b0153072e 100644 --- a/InvenTree/templates/js/translated/company.js +++ b/InvenTree/templates/js/translated/company.js @@ -361,7 +361,7 @@ function loadCompanyTable(table, url, options={}) { field: 'parts_supplied', title: '{% trans "Parts Supplied" %}', formatter: function(value, row) { - return renderLink(value, `/company/${row.pk}/parts/`); + return renderLink(value, `/company/${row.pk}/?display=supplier-parts`); } }); } else if (options.pagetype == 'manufacturers') { @@ -370,7 +370,7 @@ function loadCompanyTable(table, url, options={}) { field: 'parts_manufactured', title: '{% trans "Parts Manufactured" %}', formatter: function(value, row) { - return renderLink(value, `/company/${row.pk}/parts/`); + return renderLink(value, `/company/${row.pk}/?display=manufacturer-parts`); } }); } From b9c8e46e1cf72af8815472a0331e7f2c9ffbd1d6 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 30 Sep 2021 20:12:27 +1000 Subject: [PATCH 17/24] Fixes for supplierpart table - Paginate on server side --- InvenTree/templates/js/translated/company.js | 1 + 1 file changed, 1 insertion(+) diff --git a/InvenTree/templates/js/translated/company.js b/InvenTree/templates/js/translated/company.js index 3b0153072e..764f65eda6 100644 --- a/InvenTree/templates/js/translated/company.js +++ b/InvenTree/templates/js/translated/company.js @@ -724,6 +724,7 @@ function loadSupplierPartTable(table, url, options) { url: url, method: 'get', original: params, + sidePagination: 'server', queryParams: filters, name: 'supplierparts', groupBy: false, From e36039b03fd8b662fb4d16eee7a10e13f91fbd18 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 30 Sep 2021 20:15:54 +1000 Subject: [PATCH 18/24] Server-side pagination for part category search results --- InvenTree/templates/InvenTree/search.html | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/InvenTree/templates/InvenTree/search.html b/InvenTree/templates/InvenTree/search.html index 0fba0add0d..483a9a4e0f 100644 --- a/InvenTree/templates/InvenTree/search.html +++ b/InvenTree/templates/InvenTree/search.html @@ -126,24 +126,10 @@ addItem('category', '{% trans "Part Categories" %}', 'fa-sitemap'); - $("#table-category").inventreeTable({ - url: "{% url 'api-part-category-list' %}", - queryParams: { + loadPartCategoryTable($("#table-category"), { + params: { original_search: "{{ query }}", - }, - columns: [ - { - field: 'name', - title: '{% trans "Name" %}', - formatter: function(value, row, index, field) { - return renderLink(value, '/part/category/' + row.pk + '/'); - }, - }, - { - field: 'description', - title: '{% trans "Description" %}', - }, - ], + } }); addItem('manufacturer-part', '{% trans "Manufacturer Parts" %}', 'fa-toolbox'); From ab9d24753169ee4d5111683561a7930cca94b1f5 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 30 Sep 2021 20:17:10 +1000 Subject: [PATCH 19/24] server-side pagination for manufacturer part table --- InvenTree/templates/js/translated/company.js | 1 + 1 file changed, 1 insertion(+) diff --git a/InvenTree/templates/js/translated/company.js b/InvenTree/templates/js/translated/company.js index 764f65eda6..68b3079c3e 100644 --- a/InvenTree/templates/js/translated/company.js +++ b/InvenTree/templates/js/translated/company.js @@ -469,6 +469,7 @@ function loadManufacturerPartTable(table, url, options) { method: 'get', original: params, queryParams: filters, + sidePagination: 'server', name: 'manufacturerparts', groupBy: false, formatNoMatches: function() { From 7e81f419d74130bedff97553243addfa9311b933 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 30 Sep 2021 20:23:41 +1000 Subject: [PATCH 20/24] Refactor search results for stock items and locations --- InvenTree/templates/InvenTree/search.html | 98 ++--------------------- 1 file changed, 8 insertions(+), 90 deletions(-) diff --git a/InvenTree/templates/InvenTree/search.html b/InvenTree/templates/InvenTree/search.html index 483a9a4e0f..bc1eb013bf 100644 --- a/InvenTree/templates/InvenTree/search.html +++ b/InvenTree/templates/InvenTree/search.html @@ -183,105 +183,23 @@ addItem('stock', '{% trans "Stock Items" %}', 'fa-boxes'); - $('#table-stock').inventreeTable({ + loadStockTable($('#table-stock'), { + filterKey: 'stocksearch', url: "{% url 'api-stock-list' %}", - queryParams: { + params: { original_search: "{{ query }}", part_detail: true, - location_detail: true, - }, - columns: [ - { - field: 'part', - title: "{% trans "Part" %}", - sortable: true, - formatter: function(value, row) { - var url = `/stock/item/${row.pk}/`; - var thumb = row.part_detail.thumbnail; - var name = row.part_detail.full_name; - - html = imageHoverIcon(thumb) + renderLink(name, url); - - return html; - } - }, - { - field: 'part_description', - title: '{% trans "Description" %}', - sortable: true, - formatter: function(value, row, index, field) { - return row.part_detail.description; - } - }, - { - field: 'quantity', - title: '{% trans "Stock" %}', - sortable: true, - formatter: function(value, row, index, field) { - - var val = parseFloat(value); - - // If there is a single unit with a serial number, use the serial number - if (row.serial && row.quantity == 1) { - val = '# ' + row.serial; - } else { - val = +val.toFixed(5); - } - - var html = renderLink(val, `/stock/item/${row.pk}/`); - - return html; - } - }, - { - field: 'status', - title: '{% trans "Status" %}', - sortable: 'true', - formatter: function(value, row, index, field) { - return stockStatusDisplay(value); - }, - }, - { - field: 'location_detail.pathstring', - title: '{% trans "Location" %}', - sortable: true, - formatter: function(value, row, index, field) { - if (value) { - return renderLink(value, `/stock/location/${row.location}/`); - } - else { - if (row.customer) { - var text = "{% trans "Shipped to customer" %}"; - return renderLink(text, `/company/${row.customer}/assigned-stock/`); - } else { - return '{% trans "No stock location set" %}'; - } - } - } - }, - ] + location_detail: true + } }); addItem('location', '{% trans "Stock Locations" %}', 'fa-map-marker-alt'); - $("#table-location").inventreeTable({ - url: "{% url 'api-location-list' %}", - queryParams: { + loadStockLocationTable($("#table-location"), { + filterKey: 'locationsearch', + params: { original_search: "{{ query }}", }, - columns: [ - { - field: 'name', - title: '{% trans "Name" %}', - formatter: function(value, row, index, field) { - return renderLink(row.pathstring, '/stock/location/' + row.pk + '/'); - }, - }, - { - field: 'description', - title: '{% trans "Description" %}', - }, - ], }); {% endif %} From 480ff5e6cbcd5aae4c349c827e64bbe993816103 Mon Sep 17 00:00:00 2001 From: eeintech Date: Thu, 30 Sep 2021 09:58:23 -0400 Subject: [PATCH 21/24] Hide submit button in modal when part is still active --- InvenTree/part/templates/part/part_base.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index 0228c4df66..847baf8ab5 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -508,7 +508,8 @@ launchModalForm( "{% url 'part-delete' part.id %}", { - redirect: {% if part.category %}"{% url 'category-detail' part.category.id %}"{% else %}"{% url 'part-index' %}"{% endif %} + redirect: {% if part.category %}"{% url 'category-detail' part.category.id %}"{% else %}"{% url 'part-index' %}"{% endif %}, + no_post: {% if part.active %}true{% else %}false{% endif %}, } ); }); From 6d448d84753f2ac065c6240dc0ce140332fc6910 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 3 Oct 2021 00:21:06 +1000 Subject: [PATCH 22/24] Handle internal django errors when receiving purchase order items via the API (cherry picked from commit 9355c68024acf47ee4f200b6b9689ca37959dc3b) --- InvenTree/order/api.py | 20 ++++++++++++++------ InvenTree/order/models.py | 16 ++++++++++++---- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/InvenTree/order/api.py b/InvenTree/order/api.py index d97da75b73..ab6c4d7c0b 100644 --- a/InvenTree/order/api.py +++ b/InvenTree/order/api.py @@ -8,11 +8,13 @@ from __future__ import unicode_literals from django.utils.translation import ugettext_lazy as _ from django.conf.urls import url, include from django.db import transaction +from django.core.exceptions import ValidationError as DjangoValidationError from django_filters import rest_framework as rest_filters from rest_framework import generics from rest_framework import filters, status from rest_framework.response import Response +from rest_framework import serializers from rest_framework.serializers import ValidationError @@ -243,11 +245,12 @@ class POReceive(generics.CreateAPIView): pk = self.kwargs.get('pk', None) - if pk is None: - return None - else: - order = PurchaseOrder.objects.get(pk=self.kwargs['pk']) - return order + try: + order = PurchaseOrder.objects.get(pk=pk) + except (PurchaseOrder.DoesNotExist, ValueError): + raise ValidationError(_("Matching purchase order does not exist")) + + return order def create(self, request, *args, **kwargs): @@ -259,9 +262,14 @@ class POReceive(generics.CreateAPIView): serializer.is_valid(raise_exception=True) # Receive the line items - self.receive_items(serializer) + try: + self.receive_items(serializer) + except DjangoValidationError as exc: + # Re-throw a django error as a DRF error + raise ValidationError(detail=serializers.as_serializer_error(exc)) headers = self.get_success_headers(serializer.data) + return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers) @transaction.atomic diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index a069cf126f..061286367c 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -418,16 +418,24 @@ class PurchaseOrder(Order): barcode = '' if not self.status == PurchaseOrderStatus.PLACED: - raise ValidationError({"status": _("Lines can only be received against an order marked as 'Placed'")}) + raise ValidationError({ + "status": _("Lines can only be received against an order marked as 'Placed'") + }) try: if not (quantity % 1 == 0): - raise ValidationError({"quantity": _("Quantity must be an integer")}) + raise ValidationError({ + "quantity": _("Quantity must be an integer") + }) if quantity < 0: - raise ValidationError({"quantity": _("Quantity must be a positive number")}) + raise ValidationError({ + "quantity": _("Quantity must be a positive number") + }) quantity = int(quantity) except (ValueError, TypeError): - raise ValidationError({"quantity": _("Invalid quantity provided")}) + raise ValidationError({ + "quantity": _("Invalid quantity provided") + }) # Create a new stock item if line.part and quantity > 0: From 8c78d3b8ea6ae4beba99629d79761bc9e68726c6 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 3 Oct 2021 01:03:40 +1000 Subject: [PATCH 23/24] Add unit test --- InvenTree/order/models.py | 6 ++--- InvenTree/order/test_api.py | 52 +++++++++++++++++++++++++------------ 2 files changed, 39 insertions(+), 19 deletions(-) diff --git a/InvenTree/order/models.py b/InvenTree/order/models.py index 061286367c..495ea2d333 100644 --- a/InvenTree/order/models.py +++ b/InvenTree/order/models.py @@ -418,9 +418,9 @@ class PurchaseOrder(Order): barcode = '' if not self.status == PurchaseOrderStatus.PLACED: - raise ValidationError({ - "status": _("Lines can only be received against an order marked as 'Placed'") - }) + raise ValidationError( + "Lines can only be received against an order marked as 'PLACED'" + ) try: if not (quantity % 1 == 0): diff --git a/InvenTree/order/test_api.py b/InvenTree/order/test_api.py index 8476a9c668..765c58cc3d 100644 --- a/InvenTree/order/test_api.py +++ b/InvenTree/order/test_api.py @@ -401,25 +401,45 @@ class PurchaseOrderReceiveTest(OrderTest): self.assertEqual(line_1.received, 0) self.assertEqual(line_2.received, 50) + valid_data = { + 'items': [ + { + 'line_item': 1, + 'quantity': 50, + 'barcode': 'MY-UNIQUE-BARCODE-123', + }, + { + 'line_item': 2, + 'quantity': 200, + 'location': 2, # Explicit location + 'barcode': 'MY-UNIQUE-BARCODE-456', + } + ], + 'location': 1, # Default location + } + + # Before posting "valid" data, we will mark the purchase order as "pending" + # In this case we do expect an error! + order = PurchaseOrder.objects.get(pk=1) + order.status = PurchaseOrderStatus.PENDING + order.save() + + response = self.post( + self.url, + valid_data, + expected_code=400 + ) + + self.assertIn('can only be received against', str(response.data)) + + # Now, set the PO back to "PLACED" so the items can be received + order.status = PurchaseOrderStatus.PLACED + order.save() + # Receive two separate line items against this order self.post( self.url, - { - 'items': [ - { - 'line_item': 1, - 'quantity': 50, - 'barcode': 'MY-UNIQUE-BARCODE-123', - }, - { - 'line_item': 2, - 'quantity': 200, - 'location': 2, # Explicit location - 'barcode': 'MY-UNIQUE-BARCODE-456', - } - ], - 'location': 1, # Default location - }, + valid_data, expected_code=201, ) From dfdbb4f7d19b23eac1dac3b61da6e6289b6e1f37 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 4 Oct 2021 09:35:21 +1100 Subject: [PATCH 24/24] Update version.py Bumped version number for dev branch --- InvenTree/InvenTree/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/InvenTree/version.py b/InvenTree/InvenTree/version.py index f302c84d6f..f309f85e66 100644 --- a/InvenTree/InvenTree/version.py +++ b/InvenTree/InvenTree/version.py @@ -8,7 +8,7 @@ import re import common.models -INVENTREE_SW_VERSION = "0.5.0 dev" +INVENTREE_SW_VERSION = "0.6.0 dev" INVENTREE_API_VERSION = 12