From dd4db6442e99682ecc2b8152e2ff9e8e472f62d9 Mon Sep 17 00:00:00 2001 From: Oliver Date: Tue, 5 Oct 2021 00:45:49 +1100 Subject: [PATCH] PEP fixes --- InvenTree/build/api.py | 7 +- InvenTree/build/models.py | 111 -------------------- InvenTree/build/serializers.py | 8 +- InvenTree/build/templates/build/detail.html | 10 +- InvenTree/build/test_api.py | 7 +- InvenTree/build/views.py | 1 - InvenTree/order/serializers.py | 2 +- 7 files changed, 17 insertions(+), 129 deletions(-) diff --git a/InvenTree/build/api.py b/InvenTree/build/api.py index 5735a66f62..3973272944 100644 --- a/InvenTree/build/api.py +++ b/InvenTree/build/api.py @@ -7,13 +7,10 @@ from __future__ import unicode_literals from django.utils.translation import ugettext_lazy as _ -from django.db import transaction from django.conf.urls import url, include -from django.core.exceptions import ValidationError as DjangoValidationError -from rest_framework import filters, generics, serializers, status +from rest_framework import filters, generics from rest_framework.serializers import ValidationError -from rest_framework.response import Response from django_filters.rest_framework import DjangoFilterBackend from django_filters import rest_framework as rest_filters @@ -195,7 +192,7 @@ class BuildAllocate(generics.CreateAPIView): - Items to allocate are specified as a list called "items" with the following options: - bom_item: pk value of a given BomItem object (must match the part associated with this build) - stock_item: pk value of a given StockItem object - - quantity: quantity to allocate + - quantity: quantity to allocate - output: StockItem (build order output) to allocate stock against (optional) """ diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index 4bd4d2e757..feddd01112 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -585,86 +585,6 @@ class Build(MPTTModel): self.status = BuildStatus.CANCELLED self.save() - def getAutoAllocations(self): - """ - Return a list of StockItem objects which will be allocated - using the 'AutoAllocate' function. - - For each item in the BOM for the attached Part, - the following tests must *all* evaluate to True, - for the part to be auto-allocated: - - - The sub_item in the BOM line must *not* be trackable - - There is only a single stock item available (which has not already been allocated to this build) - - The stock item has an availability greater than zero - - Returns: - A list object containing the StockItem objects to be allocated (and the quantities). - Each item in the list is a dict as follows: - { - 'stock_item': stock_item, - 'quantity': stock_quantity, - } - """ - - allocations = [] - - """ - Iterate through each item in the BOM - """ - - for bom_item in self.bom_items: - - part = bom_item.sub_part - - # If the part is "trackable" it cannot be auto-allocated - if part.trackable: - continue - - # Skip any parts which are already fully allocated - if self.isPartFullyAllocated(part, None): - continue - - # How many parts are required to complete the output? - required = self.unallocatedQuantity(part, None) - - # Grab a list of stock items which are available - stock_items = self.availableStockItems(part, None) - - # Ensure that the available stock items are in the correct location - if self.take_from is not None: - # Filter for stock that is located downstream of the designated location - stock_items = stock_items.filter(location__in=[loc for loc in self.take_from.getUniqueChildren()]) - - # Only one StockItem to choose from? Default to that one! - if stock_items.count() == 1: - stock_item = stock_items[0] - - # Double check that we have not already allocated this stock-item against this build - build_items = BuildItem.objects.filter( - build=self, - stock_item=stock_item, - ) - - if len(build_items) > 0: - continue - - # How many items are actually available? - if stock_item.quantity > 0: - - # Only take as many as are available - if stock_item.quantity < required: - required = stock_item.quantity - - allocation = { - 'stock_item': stock_item, - 'quantity': required, - } - - allocations.append(allocation) - - return allocations - @transaction.atomic def unallocateOutput(self, output, part=None): """ @@ -804,37 +724,6 @@ class Build(MPTTModel): # Remove the build output from the database output.delete() - @transaction.atomic - def autoAllocate(self): - """ - Run auto-allocation routine to allocate StockItems to this Build. - - Args: - output: If specified, only auto-allocate against the given built output - - Returns a list of dict objects with keys like: - - { - 'stock_item': item, - 'quantity': quantity, - } - - See: getAutoAllocations() - """ - - allocations = self.getAutoAllocations() - - for item in allocations: - # Create a new allocation - build_item = BuildItem( - build=self, - stock_item=item['stock_item'], - quantity=item['quantity'], - install_into=None - ) - - build_item.save() - @transaction.atomic def subtractUntrackedStock(self, user): """ diff --git a/InvenTree/build/serializers.py b/InvenTree/build/serializers.py index c15856d44e..7dc8b7b9d0 100644 --- a/InvenTree/build/serializers.py +++ b/InvenTree/build/serializers.py @@ -23,7 +23,7 @@ import InvenTree.helpers from stock.models import StockItem from stock.serializers import StockItemSerializerBrief, LocationSerializer -from part.models import Part, BomItem +from part.models import BomItem from part.serializers import PartSerializer, PartBriefSerializer from users.serializers import OwnerSerializer @@ -197,7 +197,7 @@ class BuildAllocationItemSerializer(serializers.Serializer): quantity = data['quantity'] output = data.get('output', None) - build = self.context['build'] + # build = self.context['build'] # TODO: Check that the "stock item" is valid for the referenced "sub_part" # Note: Because of allow_variants options, it may not be a direct match! @@ -224,7 +224,7 @@ class BuildAllocationItemSerializer(serializers.Serializer): raise ValidationError({ 'output': _('Build output cannot be specified for allocation of untracked parts') - }) + }) return data @@ -271,7 +271,7 @@ class BuildAllocationSerializer(serializers.Serializer): output = item.get('output', None) # Create a new BuildItem to allocate stock - build_item = BuildItem.objects.create( + BuildItem.objects.create( build=build, bom_item=bom_item, stock_item=stock_item, diff --git a/InvenTree/build/templates/build/detail.html b/InvenTree/build/templates/build/detail.html index cfe5e548c0..c062e01b9d 100644 --- a/InvenTree/build/templates/build/detail.html +++ b/InvenTree/build/templates/build/detail.html @@ -418,10 +418,14 @@ function reloadTable() { {% if build.active %} $("#btn-auto-allocate").on('click', function() { - launchModalForm( - "{% url 'build-auto-allocate' build.id %}", + + allocateStockToBuild( + {{ build.pk }}, + {{ build.part.pk }}, { - success: reloadTable, + success: function(data) { + $('#allocation-table-untracked').bootstrapTable('refresh'); + } } ); }); diff --git a/InvenTree/build/test_api.py b/InvenTree/build/test_api.py index 549df80d87..4b5b04fca9 100644 --- a/InvenTree/build/test_api.py +++ b/InvenTree/build/test_api.py @@ -76,7 +76,6 @@ class BuildAllocationTest(BuildAPITest): # No items yet allocated to this build self.assertEqual(self.build.allocated_stock.count(), 0) - def test_get(self): """ A GET request to the endpoint should return an error @@ -120,7 +119,7 @@ class BuildAllocationTest(BuildAPITest): def test_missing(self): """ Test with missing data - """ + """ # Missing quantity data = self.post( @@ -200,7 +199,7 @@ class BuildAllocationTest(BuildAPITest): This should result in creation of a new BuildItem object """ - data = self.post( + self.post( self.url, { "items": [ @@ -212,7 +211,7 @@ class BuildAllocationTest(BuildAPITest): ] }, expected_code=201 - ).data + ) # A new BuildItem should have been created self.assertEqual(self.n + 1, BuildItem.objects.count()) diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py index a66c38d62b..82f9f3586b 100644 --- a/InvenTree/build/views.py +++ b/InvenTree/build/views.py @@ -567,7 +567,6 @@ class BuildDelete(AjaxDeleteView): ajax_form_title = _('Delete Build Order') - class BuildItemCreate(AjaxCreateView): """ View for allocating a StockItem to a build output. diff --git a/InvenTree/order/serializers.py b/InvenTree/order/serializers.py index 91460e5961..0a93510c6f 100644 --- a/InvenTree/order/serializers.py +++ b/InvenTree/order/serializers.py @@ -276,7 +276,7 @@ class POReceiveSerializer(serializers.Serializer): help_text=_('Select destination location for received items'), ) - def validate(self, data): + def validate(self, data): super().validate(data)