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 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..495ea2d333 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( + "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: 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, ) diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index b91ff53118..847baf8ab5 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,12 +503,13 @@ }); {% endif %} - {% if not part.active and roles.part.delete %} + {% if roles.part.delete %} $("#part-delete").click(function() { 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 %}, } ); }); 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 diff --git a/InvenTree/templates/InvenTree/search.html b/InvenTree/templates/InvenTree/search.html index af0711bc35..bc1eb013bf 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, @@ -126,24 +126,10 @@ addItem('category', '{% trans "Part Categories" %}', 'fa-sitemap'); - $("#table-category").inventreeTable({ - url: "{% url 'api-part-category-list' %}", - queryParams: { - 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" %}', - }, - ], + loadPartCategoryTable($("#table-category"), { + params: { + original_search: "{{ query }}", + } }); addItem('manufacturer-part', '{% trans "Manufacturer Parts" %}', 'fa-toolbox'); @@ -153,7 +139,7 @@ "{% url 'api-manufacturer-part-list' %}", { params: { - search: "{{ query }}", + original_search: "{{ query }}", part_detail: true, supplier_detail: true, manufacturer_detail: true @@ -168,7 +154,7 @@ "{% url 'api-supplier-part-list' %}", { params: { - search: "{{ query }}", + original_search: "{{ query }}", part_detail: true, supplier_detail: true, manufacturer_detail: true @@ -186,7 +172,7 @@ loadBuildTable('#table-build-order', { params: { - search: '{{ query }}', + original_search: '{{ query }}', } }); @@ -197,105 +183,23 @@ addItem('stock', '{% trans "Stock Items" %}', 'fa-boxes'); - $('#table-stock').inventreeTable({ + loadStockTable($('#table-stock'), { + filterKey: 'stocksearch', url: "{% url 'api-stock-list' %}", - queryParams: { - search: "{{ query }}", + 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: { - search: "{{ query }}", + 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 %} @@ -307,7 +211,7 @@ loadCompanyTable('#table-manufacturer', "{% url 'api-company-list' %}", { params: { - search: "{{ query }}", + original_search: "{{ query }}", is_manufacturer: "true", } }); @@ -317,7 +221,7 @@ loadCompanyTable('#table-supplier', "{% url 'api-company-list' %}", { params: { - search: "{{ query }}", + original_search: "{{ query }}", is_supplier: "true", } }); @@ -326,7 +230,7 @@ loadPurchaseOrderTable('#table-purchase-order', { params: { - search: '{{ query }}', + original_search: '{{ query }}', } }); @@ -337,7 +241,7 @@ loadCompanyTable('#table-customer', "{% url 'api-company-list' %}", { params: { - search: "{{ query }}", + original_search: "{{ query }}", is_customer: "true", } }); @@ -346,7 +250,7 @@ loadSalesOrderTable('#table-sales-orders', { params: { - search: '{{ query }}', + original_search: '{{ query }}', } }); diff --git a/InvenTree/templates/js/dynamic/inventree.js b/InvenTree/templates/js/dynamic/inventree.js index 990d056e59..3fad6f1c01 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 }; diff --git a/InvenTree/templates/js/translated/company.js b/InvenTree/templates/js/translated/company.js index c014139e1b..68b3079c3e 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`); } }); } @@ -469,6 +469,7 @@ function loadManufacturerPartTable(table, url, options) { method: 'get', original: params, queryParams: filters, + sidePagination: 'server', name: 'manufacturerparts', groupBy: false, formatNoMatches: function() { @@ -724,6 +725,7 @@ function loadSupplierPartTable(table, url, options) { url: url, method: 'get', original: params, + sidePagination: 'server', queryParams: filters, name: 'supplierparts', groupBy: false, 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; } 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.