From ad977d4d26df8e9d8cacd35585113735f2fa13d2 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 8 Aug 2020 16:54:09 +1000 Subject: [PATCH 01/13] Add default ordering for Company model - Now will sort by "name" in choice fields, etc --- InvenTree/company/models.py | 3 +++ InvenTree/part/models.py | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/InvenTree/company/models.py b/InvenTree/company/models.py index 2179897263..7c059782fb 100644 --- a/InvenTree/company/models.py +++ b/InvenTree/company/models.py @@ -79,6 +79,9 @@ class Company(models.Model): is_manufacturer: boolean value, is this company a manufacturer """ + class Meta: + ordering = ['name',] + name = models.CharField(max_length=100, blank=False, unique=True, help_text=_('Company name'), verbose_name=_('Company name')) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 01768b4bb3..6ec3f2cfea 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -71,8 +71,8 @@ class PartCategory(InvenTreeTree): return reverse('category-detail', kwargs={'pk': self.id}) class Meta: - verbose_name = "Part Category" - verbose_name_plural = "Part Categories" + verbose_name = _("Part Category") + verbose_name_plural = _("Part Categories") def get_parts(self, cascade=True): """ Return a queryset for all parts under this category. @@ -239,6 +239,7 @@ class Part(MPTTModel): class Meta: verbose_name = _("Part") verbose_name_plural = _("Parts") + ordering = ['name',] class MPTTMeta: # For legacy reasons the 'variant_of' field is used to indicate the MPTT parent @@ -1490,7 +1491,7 @@ class BomItem(models.Model): pass class Meta: - verbose_name = "BOM Item" + verbose_name = _("BOM Item") # Prevent duplication of parent/child rows unique_together = ('part', 'sub_part') From a7ee3230350fe724520d0d0f683d14ec2c9f11b5 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 8 Aug 2020 16:59:48 +1000 Subject: [PATCH 02/13] PEP fix --- InvenTree/company/models.py | 2 +- InvenTree/part/models.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/InvenTree/company/models.py b/InvenTree/company/models.py index 7c059782fb..a06ddd94bf 100644 --- a/InvenTree/company/models.py +++ b/InvenTree/company/models.py @@ -80,7 +80,7 @@ class Company(models.Model): """ class Meta: - ordering = ['name',] + ordering = ['name', ] name = models.CharField(max_length=100, blank=False, unique=True, help_text=_('Company name'), diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 6ec3f2cfea..308808fbdd 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -239,7 +239,7 @@ class Part(MPTTModel): class Meta: verbose_name = _("Part") verbose_name_plural = _("Parts") - ordering = ['name',] + ordering = ['name', ] class MPTTMeta: # For legacy reasons the 'variant_of' field is used to indicate the MPTT parent From 732405f738789638ee01ff8f95853b53277bb81b Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 8 Aug 2020 17:01:29 +1000 Subject: [PATCH 03/13] Cannot edit quantity for serialized stock when adjusting --- InvenTree/stock/templates/stock/stock_adjust.html | 1 + 1 file changed, 1 insertion(+) diff --git a/InvenTree/stock/templates/stock/stock_adjust.html b/InvenTree/stock/templates/stock/stock_adjust.html index a72407f735..8385fb5039 100644 --- a/InvenTree/stock/templates/stock/stock_adjust.html +++ b/InvenTree/stock/templates/stock/stock_adjust.html @@ -32,6 +32,7 @@ {% if item.error %}
{{ item.error }} From 402301e165e7a4a5911994547513383609cdc503 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 8 Aug 2020 17:06:22 +1000 Subject: [PATCH 04/13] Add ability to filter stock items by "depleted" status --- InvenTree/stock/api.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 018b588c1f..023b0c6c4e 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -539,10 +539,21 @@ class StockList(generics.ListCreateAPIView): active = str2bool(active) queryset = queryset.filter(part__active=active) + # Filter by 'depleted' status + depleted = params.get('depleted', None) + + if depleted is not None: + depleted = str2bool(depleted) + + if depleted: + queryset = queryset.filter(quantity__lte=0) + else: + queryset = queryset.exclude(quantity__lte=0) + # Filter by internal part number IPN = params.get('IPN', None) - if IPN: + if IPN is not None: queryset = queryset.filter(part__IPN=IPN) # Does the client wish to filter by the Part ID? From 099f56e7798db12a45907ac286bdb959d400f854 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 8 Aug 2020 17:08:18 +1000 Subject: [PATCH 05/13] Add "depleted" table filter --- InvenTree/templates/js/table_filters.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/InvenTree/templates/js/table_filters.html b/InvenTree/templates/js/table_filters.html index e2138ef6b3..affb97c1c5 100644 --- a/InvenTree/templates/js/table_filters.html +++ b/InvenTree/templates/js/table_filters.html @@ -47,6 +47,11 @@ function getAvailableTableFilters(tableKey) { title: '{% trans "Active parts" %}', description: '{% trans "Show stock for active parts" %}', }, + depleted: { + type: 'bool', + title: '{% trans "Depleted" %}', + description: '{% trans "Show stock items which are depleted" %}', + }, status: { options: stockCodes, title: '{% trans "Stock status" %}', From 96a3f2920df03252ed54d611498ab4d8f6065915 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 8 Aug 2020 17:09:22 +1000 Subject: [PATCH 06/13] Stock table filters now arranged in alphabetical order --- InvenTree/templates/js/table_filters.html | 32 +++++++++++------------ 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/InvenTree/templates/js/table_filters.html b/InvenTree/templates/js/table_filters.html index affb97c1c5..aef430bf36 100644 --- a/InvenTree/templates/js/table_filters.html +++ b/InvenTree/templates/js/table_filters.html @@ -32,35 +32,30 @@ function getAvailableTableFilters(tableKey) { // Filters for the "Stock" table if (tableKey == 'stock') { return { - in_stock: { + active: { type: 'bool', - title: '{% trans "In Stock" %}', - description: '{% trans "Show items which are in stock" %}', + title: '{% trans "Active parts" %}', + description: '{% trans "Show stock for active parts" %}', + }, + allocated: { + type: 'bool', + title: '{% trans "Is allocated" %}', + description: '{% trans "Item has been alloacted" %}', }, cascade: { type: 'bool', title: '{% trans "Include sublocations" %}', description: '{% trans "Include stock in sublocations" %}', }, - active: { - type: 'bool', - title: '{% trans "Active parts" %}', - description: '{% trans "Show stock for active parts" %}', - }, depleted: { type: 'bool', title: '{% trans "Depleted" %}', description: '{% trans "Show stock items which are depleted" %}', }, - status: { - options: stockCodes, - title: '{% trans "Stock status" %}', - description: '{% trans "Stock status" %}', - }, - allocated: { + in_stock: { type: 'bool', - title: '{% trans "Is allocated" %}', - description: '{% trans "Item has been alloacted" %}', + title: '{% trans "In Stock" %}', + description: '{% trans "Show items which are in stock" %}', }, serialized: { type: 'bool', @@ -74,6 +69,11 @@ function getAvailableTableFilters(tableKey) { title: "{% trans "Serial number LTE" %}", description: "{% trans "Serial number less than or equal to" %}", }, + status: { + options: stockCodes, + title: '{% trans "Stock status" %}', + description: '{% trans "Stock status" %}', + }, }; } From bc3fda71a436dac7129d5f739f4ab0d31bcea627 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 8 Aug 2020 17:11:50 +1000 Subject: [PATCH 07/13] Display "depleted" label next to depleted stock --- InvenTree/templates/js/stock.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/InvenTree/templates/js/stock.html b/InvenTree/templates/js/stock.html index adaf07b4f6..f06615f2f5 100644 --- a/InvenTree/templates/js/stock.html +++ b/InvenTree/templates/js/stock.html @@ -468,6 +468,10 @@ function loadStockTable(table, options) { html += ``; } + if (row.quantity <= 0) { + html += `{% trans "Depleted" %}`; + } + return html; } }, From ad116813696cba9e2de486d903bdc1f05ce6288b Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 8 Aug 2020 17:15:08 +1000 Subject: [PATCH 08/13] Custom filter tag for company stock listing --- InvenTree/company/templates/company/detail_stock.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/InvenTree/company/templates/company/detail_stock.html b/InvenTree/company/templates/company/detail_stock.html index c33179d454..e994d5834b 100644 --- a/InvenTree/company/templates/company/detail_stock.html +++ b/InvenTree/company/templates/company/detail_stock.html @@ -26,7 +26,8 @@ }, buttons: [ '#stock-options', - ] + ], + filterKey: "companystock", }); $("#stock-export").click(function() { From 19c036f50abdc887eef25e569dd0664da9502c7c Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sat, 8 Aug 2020 17:16:04 +1000 Subject: [PATCH 09/13] Add migration files --- .../migrations/0023_auto_20200808_0715.py | 17 +++++++++++++++++ .../part/migrations/0047_auto_20200808_0715.py | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 InvenTree/company/migrations/0023_auto_20200808_0715.py create mode 100644 InvenTree/part/migrations/0047_auto_20200808_0715.py diff --git a/InvenTree/company/migrations/0023_auto_20200808_0715.py b/InvenTree/company/migrations/0023_auto_20200808_0715.py new file mode 100644 index 0000000000..22097e8e2b --- /dev/null +++ b/InvenTree/company/migrations/0023_auto_20200808_0715.py @@ -0,0 +1,17 @@ +# Generated by Django 3.0.7 on 2020-08-08 07:15 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('company', '0022_auto_20200613_1045'), + ] + + operations = [ + migrations.AlterModelOptions( + name='company', + options={'ordering': ['name']}, + ), + ] diff --git a/InvenTree/part/migrations/0047_auto_20200808_0715.py b/InvenTree/part/migrations/0047_auto_20200808_0715.py new file mode 100644 index 0000000000..4fc3d5a7d9 --- /dev/null +++ b/InvenTree/part/migrations/0047_auto_20200808_0715.py @@ -0,0 +1,17 @@ +# Generated by Django 3.0.7 on 2020-08-08 07:15 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('part', '0046_auto_20200804_0107'), + ] + + operations = [ + migrations.AlterModelOptions( + name='part', + options={'ordering': ['name'], 'verbose_name': 'Part', 'verbose_name_plural': 'Parts'}, + ), + ] From 502702b3bc0e538d5ff5a57e0d0f20efb74cf1ca Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 9 Aug 2020 21:04:41 +1000 Subject: [PATCH 10/13] Add some more visual tags to the stock list --- InvenTree/templates/js/stock.html | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/InvenTree/templates/js/stock.html b/InvenTree/templates/js/stock.html index f06615f2f5..11cf6a94e3 100644 --- a/InvenTree/templates/js/stock.html +++ b/InvenTree/templates/js/stock.html @@ -1,4 +1,5 @@ {% load i18n %} +{% load status_codes %} /* Stock API functions * Requires api.js to be loaded first @@ -460,12 +461,26 @@ function loadStockTable(table, options) { var html = renderLink(val, `/stock/item/${row.pk}/`); if (row.allocated) { - html += ``; + html += ``; } + if (row.customer) { + html += ``; + } else if (row.build_order) { + html += ``; + } else if (row.sales_order) { + html += ``; + } + + // Special stock status codes + + // 65 = "REJECTED" + if (row.status == 65) { + html += ``; + } // 70 = "LOST" - if (row.status == 70) { - html += ``; + else if (row.status == 70) { + html += ``; } if (row.quantity <= 0) { From 0da9e0f8341575975123fef6c0ca196a8d574c02 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 9 Aug 2020 21:10:21 +1000 Subject: [PATCH 11/13] Add "sent_to_customer" filter --- InvenTree/stock/api.py | 11 +++++++++++ InvenTree/templates/js/table_filters.html | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index 023b0c6c4e..b291a2cb5c 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -477,6 +477,17 @@ class StockList(generics.ListCreateAPIView): if customer: queryset = queryset.filter(customer=customer) + # Filter if items have been sent to a customer (any customer) + sent_to_customer = params.get('sent_to_customer', None) + + if sent_to_customer is not None: + sent_to_customer = str2bool(sent_to_customer) + + if sent_to_customer: + queryset = queryset.exclude(customer=None) + else: + queryset = queryset.filter(customer=None) + # Filter by "serialized" status? serialized = params.get('serialized', None) diff --git a/InvenTree/templates/js/table_filters.html b/InvenTree/templates/js/table_filters.html index aef430bf36..9050edba6f 100644 --- a/InvenTree/templates/js/table_filters.html +++ b/InvenTree/templates/js/table_filters.html @@ -57,6 +57,11 @@ function getAvailableTableFilters(tableKey) { title: '{% trans "In Stock" %}', description: '{% trans "Show items which are in stock" %}', }, + sent_to_customer: { + type: 'bool', + title: '{% trans "Sent to customer" %}', + description: '{% trans "Show items which have been assigned to a customer" %}', + }, serialized: { type: 'bool', title: '{% trans "Is Serialized" %}', From 3336eb9f45ad20e4247a36d2b4323c4b1000a3d6 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 9 Aug 2020 21:12:49 +1000 Subject: [PATCH 12/13] Default stock list behaviour is to only show in_stock items --- InvenTree/stock/api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index b291a2cb5c..a10262ce9c 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -518,7 +518,8 @@ class StockList(generics.ListCreateAPIView): if serial_number_lte is not None: queryset = queryset.filter(serial__lte=serial_number_lte) - in_stock = params.get('in_stock', None) + # Filter by "in_stock" status (default behaviour is "True") + in_stock = params.get('in_stock', True) if in_stock is not None: in_stock = str2bool(in_stock) From cebba6909c7271b8e7524a032441f3e4d16eb48a Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 9 Aug 2020 21:21:12 +1000 Subject: [PATCH 13/13] Revert thing --- InvenTree/stock/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/InvenTree/stock/api.py b/InvenTree/stock/api.py index a10262ce9c..7284f8d5cd 100644 --- a/InvenTree/stock/api.py +++ b/InvenTree/stock/api.py @@ -518,8 +518,8 @@ class StockList(generics.ListCreateAPIView): if serial_number_lte is not None: queryset = queryset.filter(serial__lte=serial_number_lte) - # Filter by "in_stock" status (default behaviour is "True") - in_stock = params.get('in_stock', True) + # Filter by "in_stock" status + in_stock = params.get('in_stock', None) if in_stock is not None: in_stock = str2bool(in_stock)