mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
PEP fixes
This commit is contained in:
parent
40f1ccf9f8
commit
dd4db6442e
@ -7,13 +7,10 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from django.db import transaction
|
|
||||||
from django.conf.urls import url, include
|
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.serializers import ValidationError
|
||||||
from rest_framework.response import Response
|
|
||||||
|
|
||||||
from django_filters.rest_framework import DjangoFilterBackend
|
from django_filters.rest_framework import DjangoFilterBackend
|
||||||
from django_filters import rest_framework as rest_filters
|
from django_filters import rest_framework as rest_filters
|
||||||
|
@ -585,86 +585,6 @@ class Build(MPTTModel):
|
|||||||
self.status = BuildStatus.CANCELLED
|
self.status = BuildStatus.CANCELLED
|
||||||
self.save()
|
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
|
@transaction.atomic
|
||||||
def unallocateOutput(self, output, part=None):
|
def unallocateOutput(self, output, part=None):
|
||||||
"""
|
"""
|
||||||
@ -804,37 +724,6 @@ class Build(MPTTModel):
|
|||||||
# Remove the build output from the database
|
# Remove the build output from the database
|
||||||
output.delete()
|
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
|
@transaction.atomic
|
||||||
def subtractUntrackedStock(self, user):
|
def subtractUntrackedStock(self, user):
|
||||||
"""
|
"""
|
||||||
|
@ -23,7 +23,7 @@ import InvenTree.helpers
|
|||||||
from stock.models import StockItem
|
from stock.models import StockItem
|
||||||
from stock.serializers import StockItemSerializerBrief, LocationSerializer
|
from stock.serializers import StockItemSerializerBrief, LocationSerializer
|
||||||
|
|
||||||
from part.models import Part, BomItem
|
from part.models import BomItem
|
||||||
from part.serializers import PartSerializer, PartBriefSerializer
|
from part.serializers import PartSerializer, PartBriefSerializer
|
||||||
from users.serializers import OwnerSerializer
|
from users.serializers import OwnerSerializer
|
||||||
|
|
||||||
@ -197,7 +197,7 @@ class BuildAllocationItemSerializer(serializers.Serializer):
|
|||||||
quantity = data['quantity']
|
quantity = data['quantity']
|
||||||
output = data.get('output', None)
|
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"
|
# 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!
|
# Note: Because of allow_variants options, it may not be a direct match!
|
||||||
@ -271,7 +271,7 @@ class BuildAllocationSerializer(serializers.Serializer):
|
|||||||
output = item.get('output', None)
|
output = item.get('output', None)
|
||||||
|
|
||||||
# Create a new BuildItem to allocate stock
|
# Create a new BuildItem to allocate stock
|
||||||
build_item = BuildItem.objects.create(
|
BuildItem.objects.create(
|
||||||
build=build,
|
build=build,
|
||||||
bom_item=bom_item,
|
bom_item=bom_item,
|
||||||
stock_item=stock_item,
|
stock_item=stock_item,
|
||||||
|
@ -418,10 +418,14 @@ function reloadTable() {
|
|||||||
|
|
||||||
{% if build.active %}
|
{% if build.active %}
|
||||||
$("#btn-auto-allocate").on('click', function() {
|
$("#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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@ -76,7 +76,6 @@ class BuildAllocationTest(BuildAPITest):
|
|||||||
# No items yet allocated to this build
|
# No items yet allocated to this build
|
||||||
self.assertEqual(self.build.allocated_stock.count(), 0)
|
self.assertEqual(self.build.allocated_stock.count(), 0)
|
||||||
|
|
||||||
|
|
||||||
def test_get(self):
|
def test_get(self):
|
||||||
"""
|
"""
|
||||||
A GET request to the endpoint should return an error
|
A GET request to the endpoint should return an error
|
||||||
@ -200,7 +199,7 @@ class BuildAllocationTest(BuildAPITest):
|
|||||||
This should result in creation of a new BuildItem object
|
This should result in creation of a new BuildItem object
|
||||||
"""
|
"""
|
||||||
|
|
||||||
data = self.post(
|
self.post(
|
||||||
self.url,
|
self.url,
|
||||||
{
|
{
|
||||||
"items": [
|
"items": [
|
||||||
@ -212,7 +211,7 @@ class BuildAllocationTest(BuildAPITest):
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
expected_code=201
|
expected_code=201
|
||||||
).data
|
)
|
||||||
|
|
||||||
# A new BuildItem should have been created
|
# A new BuildItem should have been created
|
||||||
self.assertEqual(self.n + 1, BuildItem.objects.count())
|
self.assertEqual(self.n + 1, BuildItem.objects.count())
|
||||||
|
@ -567,7 +567,6 @@ class BuildDelete(AjaxDeleteView):
|
|||||||
ajax_form_title = _('Delete Build Order')
|
ajax_form_title = _('Delete Build Order')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BuildItemCreate(AjaxCreateView):
|
class BuildItemCreate(AjaxCreateView):
|
||||||
"""
|
"""
|
||||||
View for allocating a StockItem to a build output.
|
View for allocating a StockItem to a build output.
|
||||||
|
Loading…
Reference in New Issue
Block a user