mirror of
https://github.com/inventree/InvenTree.git
synced 2025-12-17 12:25:04 -06:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1187c5c09 | ||
|
|
1597f6dda4 | ||
|
|
f7b91f55e0 | ||
|
|
e37097d62a | ||
|
|
4800b2bf21 | ||
|
|
d1cca52ece | ||
|
|
86b0b50195 | ||
|
|
b9850bc9cb | ||
|
|
a4b8821f2c | ||
|
|
faa2044904 | ||
|
|
950d185a82 | ||
|
|
2c8dbb8308 | ||
|
|
78d277d3fc | ||
|
|
436a33c5de | ||
|
|
718e729059 | ||
|
|
451702f018 | ||
|
|
a8047921df |
@@ -133,7 +133,7 @@ class ReferenceIndexingMixin(models.Model):
|
||||
reference_int = models.BigIntegerField(default=0)
|
||||
|
||||
|
||||
def extract_int(reference):
|
||||
def extract_int(reference, clip=0x7fffffff):
|
||||
# Default value if we cannot convert to an integer
|
||||
ref_int = 0
|
||||
|
||||
@@ -146,6 +146,15 @@ def extract_int(reference):
|
||||
ref_int = int(ref)
|
||||
except:
|
||||
ref_int = 0
|
||||
|
||||
# Ensure that the returned values are within the range that can be stored in an IntegerField
|
||||
# Note: This will result in large values being "clipped"
|
||||
if clip is not None:
|
||||
if ref_int > clip:
|
||||
ref_int = clip
|
||||
elif ref_int < -clip:
|
||||
ref_int = -clip
|
||||
|
||||
return ref_int
|
||||
|
||||
|
||||
|
||||
@@ -535,11 +535,19 @@ if "sqlite" in db_engine:
|
||||
# Provide OPTIONS dict back to the database configuration dict
|
||||
db_config['OPTIONS'] = db_options
|
||||
|
||||
# Set testing options for the database
|
||||
db_config['TEST'] = {
|
||||
'CHARSET': 'utf8',
|
||||
}
|
||||
|
||||
# Set collation option for mysql test database
|
||||
if 'mysql' in db_engine:
|
||||
db_config['TEST']['COLLATION'] = 'utf8_general_ci'
|
||||
|
||||
DATABASES = {
|
||||
'default': db_config
|
||||
}
|
||||
|
||||
|
||||
_cache_config = CONFIG.get("cache", {})
|
||||
_cache_host = _cache_config.get("host", os.getenv("INVENTREE_CACHE_HOST"))
|
||||
_cache_port = _cache_config.get(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*! jQuery UI - v1.12.1 - 2021-07-18
|
||||
/*! jQuery UI - v1.13.0 - 2021-10-07
|
||||
* http://jqueryui.com
|
||||
* Includes: widget.js, position.js, disable-selection.js, keycode.js, unique-id.js, widgets/resizable.js, widgets/autocomplete.js, widgets/menu.js, widgets/mouse.js
|
||||
* Copyright jQuery Foundation and other contributors; Licensed MIT */
|
||||
@@ -17,11 +17,11 @@
|
||||
|
||||
$.ui = $.ui || {};
|
||||
|
||||
var version = $.ui.version = "1.12.1";
|
||||
var version = $.ui.version = "1.13.1";
|
||||
|
||||
|
||||
/*!
|
||||
* jQuery UI Widget 1.12.1
|
||||
* jQuery UI Widget 1.13.0
|
||||
* http://jqueryui.com
|
||||
*
|
||||
* Copyright jQuery Foundation and other contributors
|
||||
@@ -744,7 +744,7 @@ var widget = $.widget;
|
||||
|
||||
|
||||
/*!
|
||||
* jQuery UI Position 1.12.1
|
||||
* jQuery UI Position 1.13.1
|
||||
* http://jqueryui.com
|
||||
*
|
||||
* Copyright jQuery Foundation and other contributors
|
||||
@@ -1232,7 +1232,7 @@ var position = $.ui.position;
|
||||
|
||||
|
||||
/*!
|
||||
* jQuery UI Disable Selection 1.12.1
|
||||
* jQuery UI Disable Selection 1.13.0
|
||||
* http://jqueryui.com
|
||||
*
|
||||
* Copyright jQuery Foundation and other contributors
|
||||
@@ -1268,7 +1268,7 @@ var disableSelection = $.fn.extend( {
|
||||
|
||||
|
||||
/*!
|
||||
* jQuery UI Keycode 1.12.1
|
||||
* jQuery UI Keycode 1.13.0
|
||||
* http://jqueryui.com
|
||||
*
|
||||
* Copyright jQuery Foundation and other contributors
|
||||
@@ -1303,7 +1303,7 @@ var keycode = $.ui.keyCode = {
|
||||
|
||||
|
||||
/*!
|
||||
* jQuery UI Unique ID 1.12.1
|
||||
* jQuery UI Unique ID 1.13.0
|
||||
* http://jqueryui.com
|
||||
*
|
||||
* Copyright jQuery Foundation and other contributors
|
||||
@@ -1347,7 +1347,7 @@ var uniqueId = $.fn.extend( {
|
||||
var ie = $.ui.ie = !!/msie [\w.]+/.exec( navigator.userAgent.toLowerCase() );
|
||||
|
||||
/*!
|
||||
* jQuery UI Mouse 1.12.1
|
||||
* jQuery UI Mouse 1.13.0
|
||||
* http://jqueryui.com
|
||||
*
|
||||
* Copyright jQuery Foundation and other contributors
|
||||
@@ -1368,7 +1368,7 @@ $( document ).on( "mouseup", function() {
|
||||
} );
|
||||
|
||||
var widgetsMouse = $.widget( "ui.mouse", {
|
||||
version: "1.12.1",
|
||||
version: "1.13.0",
|
||||
options: {
|
||||
cancel: "input, textarea, button, select, option",
|
||||
distance: 1,
|
||||
@@ -1592,7 +1592,7 @@ var plugin = $.ui.plugin = {
|
||||
|
||||
|
||||
/*!
|
||||
* jQuery UI Resizable 1.12.1
|
||||
* jQuery UI Resizable 1.13.0
|
||||
* http://jqueryui.com
|
||||
*
|
||||
* Copyright jQuery Foundation and other contributors
|
||||
@@ -1612,7 +1612,7 @@ var plugin = $.ui.plugin = {
|
||||
|
||||
|
||||
$.widget( "ui.resizable", $.ui.mouse, {
|
||||
version: "1.12.1",
|
||||
version: "1.13.0",
|
||||
widgetEventPrefix: "resize",
|
||||
options: {
|
||||
alsoResize: false,
|
||||
@@ -2806,7 +2806,7 @@ var safeActiveElement = $.ui.safeActiveElement = function( document ) {
|
||||
|
||||
|
||||
/*!
|
||||
* jQuery UI Menu 1.12.1
|
||||
* jQuery UI Menu 1.13.0
|
||||
* http://jqueryui.com
|
||||
*
|
||||
* Copyright jQuery Foundation and other contributors
|
||||
@@ -2826,7 +2826,7 @@ var safeActiveElement = $.ui.safeActiveElement = function( document ) {
|
||||
|
||||
|
||||
var widgetsMenu = $.widget( "ui.menu", {
|
||||
version: "1.12.1",
|
||||
version: "1.13.0",
|
||||
defaultElement: "<ul>",
|
||||
delay: 300,
|
||||
options: {
|
||||
@@ -3461,7 +3461,7 @@ var widgetsMenu = $.widget( "ui.menu", {
|
||||
|
||||
|
||||
/*!
|
||||
* jQuery UI Autocomplete 1.12.1
|
||||
* jQuery UI Autocomplete 1.13.0
|
||||
* http://jqueryui.com
|
||||
*
|
||||
* Copyright jQuery Foundation and other contributors
|
||||
@@ -3481,7 +3481,7 @@ var widgetsMenu = $.widget( "ui.menu", {
|
||||
|
||||
|
||||
$.widget( "ui.autocomplete", {
|
||||
version: "1.12.1",
|
||||
version: "1.13.0",
|
||||
defaultElement: "<input>",
|
||||
options: {
|
||||
appendTo: null,
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -2,7 +2,7 @@
|
||||
"name": "jquery-ui",
|
||||
"title": "jQuery UI",
|
||||
"description": "A curated set of user interface interactions, effects, widgets, and themes built on top of the jQuery JavaScript Library.",
|
||||
"version": "1.12.1",
|
||||
"version": "1.13.0",
|
||||
"homepage": "http://jqueryui.com",
|
||||
"author": {
|
||||
"name": "jQuery Foundation and other contributors",
|
||||
|
||||
@@ -9,7 +9,7 @@ import re
|
||||
import common.models
|
||||
|
||||
# InvenTree software version
|
||||
INVENTREE_SW_VERSION = "0.6.1"
|
||||
INVENTREE_SW_VERSION = "0.6.4"
|
||||
|
||||
# InvenTree API version
|
||||
INVENTREE_API_VERSION = 26
|
||||
|
||||
@@ -12,6 +12,7 @@ from rest_framework.views import APIView
|
||||
from stock.models import StockItem
|
||||
from stock.serializers import StockItemSerializer
|
||||
|
||||
from barcodes.plugins.inventree_barcode import InvenTreeBarcodePlugin
|
||||
from barcodes.barcode import hash_barcode
|
||||
from plugin import registry
|
||||
|
||||
@@ -57,6 +58,9 @@ class BarcodeScan(APIView):
|
||||
|
||||
barcode_data = data.get('barcode')
|
||||
|
||||
# Ensure that the default barcode handler is installed
|
||||
plugins.append(InvenTreeBarcodePlugin())
|
||||
|
||||
# Look for a barcode plugin which knows how to deal with this barcode
|
||||
plugin = None
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ class InvenTreeBarcodePlugin(BarcodePlugin):
|
||||
# If any of the following keys are in the JSON data,
|
||||
# let's go ahead and assume that the code is a valid InvenTree one...
|
||||
|
||||
for key in ['tool', 'version', 'InvenTree', 'stockitem', 'location', 'part']:
|
||||
for key in ['tool', 'version', 'InvenTree', 'stockitem', 'stocklocation', 'part']:
|
||||
if key in self.data.keys():
|
||||
return True
|
||||
|
||||
|
||||
@@ -56,6 +56,66 @@ class BarcodeAPITest(APITestCase):
|
||||
self.assertIn('plugin', data)
|
||||
self.assertIsNone(data['plugin'])
|
||||
|
||||
def test_find_part(self):
|
||||
"""
|
||||
Test that we can lookup a part based on ID
|
||||
"""
|
||||
|
||||
response = self.client.post(
|
||||
self.scan_url,
|
||||
{
|
||||
'barcode': {
|
||||
'part': 1,
|
||||
},
|
||||
},
|
||||
format='json',
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertIn('part', response.data)
|
||||
self.assertIn('barcode_data', response.data)
|
||||
self.assertEqual(response.data['part']['pk'], 1)
|
||||
|
||||
def test_find_stock_item(self):
|
||||
"""
|
||||
Test that we can lookup a stock item based on ID
|
||||
"""
|
||||
|
||||
response = self.client.post(
|
||||
self.scan_url,
|
||||
{
|
||||
'barcode': {
|
||||
'stockitem': 1,
|
||||
}
|
||||
},
|
||||
format='json',
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertIn('stockitem', response.data)
|
||||
self.assertIn('barcode_data', response.data)
|
||||
self.assertEqual(response.data['stockitem']['pk'], 1)
|
||||
|
||||
def test_find_location(self):
|
||||
"""
|
||||
Test that we can lookup a stock location based on ID
|
||||
"""
|
||||
|
||||
response = self.client.post(
|
||||
self.scan_url,
|
||||
{
|
||||
'barcode': {
|
||||
'stocklocation': 1,
|
||||
},
|
||||
},
|
||||
format='json'
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||
self.assertIn('stocklocation', response.data)
|
||||
self.assertIn('barcode_data', response.data)
|
||||
self.assertEqual(response.data['stocklocation']['pk'], 1)
|
||||
|
||||
def test_integer_barcode(self):
|
||||
|
||||
response = self.postBarcode(self.scan_url, '123456789')
|
||||
|
||||
@@ -860,9 +860,17 @@ class SOAllocationList(generics.ListAPIView):
|
||||
outstanding = str2bool(outstanding)
|
||||
|
||||
if outstanding:
|
||||
queryset = queryset.filter(line__order__status__in=SalesOrderStatus.OPEN)
|
||||
# Filter only "open" orders
|
||||
# Filter only allocations which have *not* shipped
|
||||
queryset = queryset.filter(
|
||||
line__order__status__in=SalesOrderStatus.OPEN,
|
||||
shipment__shipment_date=None,
|
||||
)
|
||||
else:
|
||||
queryset = queryset.exclude(line__order__status__in=SalesOrderStatus.OPEN)
|
||||
queryset = queryset.exclude(
|
||||
line__order__status__in=SalesOrderStatus.OPEN,
|
||||
shipment__shipment_date=None
|
||||
)
|
||||
|
||||
return queryset
|
||||
|
||||
@@ -1002,7 +1010,7 @@ order_api_urls = [
|
||||
url(r'^.*$', POLineItemList.as_view(), name='api-po-line-list'),
|
||||
])),
|
||||
|
||||
# API endpoints for sales ordesr
|
||||
# API endpoints for sales orders
|
||||
url(r'^so/', include([
|
||||
url(r'attachment/', include([
|
||||
url(r'^(?P<pk>\d+)/$', SOAttachmentDetail.as_view(), name='api-so-attachment-detail'),
|
||||
|
||||
@@ -11,10 +11,14 @@
|
||||
|
||||
{% block page_content %}
|
||||
{% trans "Upload File for Purchase Order" as header_text %}
|
||||
{% order.status == PurchaseOrderStatus.PENDING and roles.purchase_order.change as upload_go_ahead %}
|
||||
{% trans "Order is already processed. Files cannot be uploaded." as error_text %}
|
||||
{% "panel-upload-file" as panel_id %}
|
||||
{% include "patterns/wizard/upload.html" with header_text=header_text upload_go_ahead=upload_go_ahead error_text=error_text panel_id=panel_id %}
|
||||
{% with "panel-upload-file" as panel_id %}
|
||||
{% if order.status == PurchaseOrderStatus.PENDING and roles.purchase_order.change %}
|
||||
{% include "patterns/wizard/upload.html" with header_text=header_text upload_go_ahead=True error_text=error_text panel_id=panel_id %}
|
||||
{% else %}
|
||||
{% include "patterns/wizard/upload.html" with header_text=header_text upload_go_ahead=False error_text=error_text panel_id=panel_id %}
|
||||
{% endif %}
|
||||
{% endwith %}
|
||||
{% endblock %}
|
||||
|
||||
{% block js_ready %}
|
||||
|
||||
@@ -112,17 +112,16 @@ class PurchaseOrderTest(OrderTest):
|
||||
self.assignRole('purchase_order.add')
|
||||
|
||||
url = reverse('api-po-list')
|
||||
huge_numer = 9223372036854775808
|
||||
huge_number = 9223372036854775808
|
||||
|
||||
# too big
|
||||
self.post(
|
||||
url,
|
||||
{
|
||||
'supplier': 1,
|
||||
'reference': huge_numer,
|
||||
'reference': huge_number,
|
||||
'description': 'PO not created via the API',
|
||||
},
|
||||
expected_code=400
|
||||
expected_code=201,
|
||||
)
|
||||
|
||||
def test_po_attachments(self):
|
||||
|
||||
@@ -20,7 +20,7 @@ from django.db.models.functions import Coalesce
|
||||
from django.core.validators import MinValueValidator
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.db.models.signals import pre_delete, post_save
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
|
||||
from jinja2 import Template
|
||||
@@ -76,6 +76,35 @@ class PartCategory(InvenTreeTree):
|
||||
default_keywords: Default keywords for parts created in this category
|
||||
"""
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
"""
|
||||
Custom model deletion routine, which updates any child categories or parts.
|
||||
This must be handled within a transaction.atomic(), otherwise the tree structure is damaged
|
||||
"""
|
||||
|
||||
with transaction.atomic():
|
||||
|
||||
parent = self.parent
|
||||
tree_id = self.tree_id
|
||||
|
||||
# Update each part in this category to point to the parent category
|
||||
for part in self.parts.all():
|
||||
part.category = self.parent
|
||||
part.save()
|
||||
|
||||
# Update each child category
|
||||
for child in self.children.all():
|
||||
child.parent = self.parent
|
||||
child.save()
|
||||
|
||||
super().delete(*args, **kwargs)
|
||||
|
||||
if parent is not None:
|
||||
# Partially rebuild the tree (cheaper than a complete rebuild)
|
||||
PartCategory.objects.partial_rebuild(tree_id)
|
||||
else:
|
||||
PartCategory.objects.rebuild()
|
||||
|
||||
default_location = TreeForeignKey(
|
||||
'stock.StockLocation', related_name="default_categories",
|
||||
null=True, blank=True,
|
||||
@@ -260,27 +289,6 @@ class PartCategory(InvenTreeTree):
|
||||
).delete()
|
||||
|
||||
|
||||
@receiver(pre_delete, sender=PartCategory, dispatch_uid='partcategory_delete_log')
|
||||
def before_delete_part_category(sender, instance, using, **kwargs):
|
||||
""" Receives before_delete signal for PartCategory object
|
||||
|
||||
Before deleting, update child Part and PartCategory objects:
|
||||
|
||||
- For each child category, set the parent to the parent of *this* category
|
||||
- For each part, set the 'category' to the parent of *this* category
|
||||
"""
|
||||
|
||||
# Update each part in this category to point to the parent category
|
||||
for part in instance.parts.all():
|
||||
part.category = instance.parent
|
||||
part.save()
|
||||
|
||||
# Update each child category
|
||||
for child in instance.children.all():
|
||||
child.parent = instance.parent
|
||||
child.save()
|
||||
|
||||
|
||||
def rename_part_image(instance, filename):
|
||||
""" Function for renaming a part image file
|
||||
|
||||
@@ -409,7 +417,7 @@ class Part(MPTTModel):
|
||||
context['allocated_build_order_quantity'] = self.build_order_allocation_count()
|
||||
|
||||
context['required_sales_order_quantity'] = self.required_sales_order_quantity()
|
||||
context['allocated_sales_order_quantity'] = self.sales_order_allocation_count()
|
||||
context['allocated_sales_order_quantity'] = self.sales_order_allocation_count(pending=True)
|
||||
|
||||
context['available'] = self.available_stock
|
||||
context['on_order'] = self.on_order
|
||||
@@ -769,7 +777,8 @@ class Part(MPTTModel):
|
||||
# User can decide whether duplicate IPN (Internal Part Number) values are allowed
|
||||
allow_duplicate_ipn = common.models.InvenTreeSetting.get_setting('PART_ALLOW_DUPLICATE_IPN')
|
||||
|
||||
if self.IPN is not None and not allow_duplicate_ipn:
|
||||
# Raise an error if an IPN is set, and it is a duplicate
|
||||
if self.IPN and not allow_duplicate_ipn:
|
||||
parts = Part.objects.filter(IPN__iexact=self.IPN)
|
||||
parts = parts.exclude(pk=self.pk)
|
||||
|
||||
@@ -790,6 +799,10 @@ class Part(MPTTModel):
|
||||
|
||||
super().clean()
|
||||
|
||||
# Strip IPN field
|
||||
if type(self.IPN) is str:
|
||||
self.IPN = self.IPN.strip()
|
||||
|
||||
if self.trackable:
|
||||
for part in self.get_used_in().all():
|
||||
|
||||
@@ -1110,7 +1123,9 @@ class Part(MPTTModel):
|
||||
quantity = 0
|
||||
|
||||
for line in open_lines:
|
||||
quantity += line.quantity
|
||||
# Determine the quantity "remaining" to be shipped out
|
||||
remaining = max(line.quantity - line.shipped, 0)
|
||||
quantity += remaining
|
||||
|
||||
return quantity
|
||||
|
||||
@@ -1328,19 +1343,36 @@ class Part(MPTTModel):
|
||||
|
||||
return query['total']
|
||||
|
||||
def sales_order_allocations(self):
|
||||
def sales_order_allocations(self, **kwargs):
|
||||
"""
|
||||
Return all sales-order-allocation objects which allocate this part to a SalesOrder
|
||||
"""
|
||||
|
||||
return OrderModels.SalesOrderAllocation.objects.filter(item__part__id=self.id)
|
||||
queryset = OrderModels.SalesOrderAllocation.objects.filter(item__part__id=self.id)
|
||||
|
||||
def sales_order_allocation_count(self):
|
||||
pending = kwargs.get('pending', None)
|
||||
|
||||
if pending is True:
|
||||
# Look only for 'open' orders which have not shipped
|
||||
queryset = queryset.filter(
|
||||
line__order__status__in=SalesOrderStatus.OPEN,
|
||||
shipment__shipment_date=None,
|
||||
)
|
||||
elif pending is False:
|
||||
# Look only for 'closed' orders or orders which have shipped
|
||||
queryset = queryset.exclude(
|
||||
line__order__status__in=SalesOrderStatus.OPEN,
|
||||
shipment__shipment_date=None,
|
||||
)
|
||||
|
||||
return queryset
|
||||
|
||||
def sales_order_allocation_count(self, **kwargs):
|
||||
"""
|
||||
Return the tutal quantity of this part allocated to sales orders
|
||||
Return the total quantity of this part allocated to sales orders
|
||||
"""
|
||||
|
||||
query = self.sales_order_allocations().aggregate(
|
||||
query = self.sales_order_allocations(**kwargs).aggregate(
|
||||
total=Coalesce(
|
||||
Sum(
|
||||
'quantity',
|
||||
|
||||
@@ -11,9 +11,8 @@
|
||||
|
||||
{% block content %}
|
||||
{% trans "Import Parts from File" as header_text %}
|
||||
{% roles.part.change as upload_go_ahead %}
|
||||
{% trans "Unsuffitient privileges." as error_text %}
|
||||
{% include "patterns/wizard/upload.html" with header_text=header_text upload_go_ahead=upload_go_ahead error_text=error_text %}
|
||||
{% include "patterns/wizard/upload.html" with header_text=header_text upload_go_ahead=roles.part.change error_text=error_text %}
|
||||
{% endblock %}
|
||||
|
||||
{% block js_ready %}
|
||||
|
||||
@@ -204,44 +204,60 @@
|
||||
<td>{% decimal on_order %}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if part.component %}
|
||||
{% if required_build_order_quantity > 0 %}
|
||||
<tr>
|
||||
<td><span class='fas fa-clipboard-list'></span></td>
|
||||
<td>{% trans "Required for Build Orders" %}</td>
|
||||
<td>{% decimal required_build_order_quantity %}
|
||||
<td>{% decimal required_build_order_quantity %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><span class='fas fa-dolly'></span></td>
|
||||
<td>{% trans "Allocated to Build Orders" %}</td>
|
||||
<td>
|
||||
{% decimal allocated_build_order_quantity %}
|
||||
{% if allocated_build_order_quantity < required_build_order_quantity %}
|
||||
<span class='fas fa-times-circle icon-red float-right' title='{% trans "Required quantity has not been allocated" %}'></span>
|
||||
{% else %}
|
||||
<span class='fas fa-check-circle icon-green float-right' title='{% trans "Required quantity has been allocated" %}'></span>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if part.salable %}
|
||||
{% if required_sales_order_quantity > 0 %}
|
||||
<tr>
|
||||
<td><span class='fas fa-clipboard-list'></span></td>
|
||||
<td>{% trans "Required for Sales Orders" %}</td>
|
||||
<td>{% decimal required_sales_order_quantity %}
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if allocated > 0 %}
|
||||
<tr>
|
||||
<td><span class='fas fa-dolly'></span></td>
|
||||
<td>{% trans "Allocated to Orders" %}</td>
|
||||
<td>{% decimal allocated %}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
|
||||
{% if not part.is_template %}
|
||||
{% if part.assembly %}
|
||||
<tr>
|
||||
<td><h5><span class='fas fa-tools'></span></h5></td>
|
||||
<td colspan='2'>
|
||||
<h5>{% trans "Build Status" %}</h5>
|
||||
<td>
|
||||
{% decimal required_sales_order_quantity %}
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td></td>
|
||||
<td><span class='fas fa-dolly'></span></td>
|
||||
<td>{% trans "Allocated to Sales Orders" %}</td>
|
||||
<td>
|
||||
{% decimal allocated_sales_order_quantity %}
|
||||
{% if allocated_sales_order_quantity < required_sales_order_quantity %}
|
||||
<span class='fas fa-times-circle icon-red float-right' title='{% trans "Required quantity has not been allocated" %}'></span>
|
||||
{% else %}
|
||||
<span class='fas fa-check-circle icon-green float-right' title='{% trans "Required quantity has been allocated" %}'></span>
|
||||
{% endif %}
|
||||
</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
{% if not part.is_template %}
|
||||
{% if part.assembly %}
|
||||
<tr>
|
||||
<td><span class='fas fa-tools'></span></td>
|
||||
<td>{% trans "Can Build" %}</td>
|
||||
<td>{% decimal part.can_build %}</td>
|
||||
</tr>
|
||||
{% if quantity_being_built > 0 %}
|
||||
<tr>
|
||||
<td></td>
|
||||
<td><span class='fas fa-tools'></span></td>
|
||||
<td>{% trans "Building" %}</td>
|
||||
<td>{% decimal quantity_being_built %}</td>
|
||||
</tr>
|
||||
|
||||
@@ -17,7 +17,9 @@
|
||||
{% if part.assembly %}
|
||||
{% trans "Bill of Materials" as text %}
|
||||
{% include "sidebar_item.html" with label="bom" text=text icon="fa-list" %}
|
||||
{% endif %}
|
||||
{% if roles.build.view %}
|
||||
{% if part.assembly or part.component %}
|
||||
{% trans "Build Orders" as text %}
|
||||
{% include "sidebar_item.html" with label="build-orders" text=text icon="fa-tools" %}
|
||||
{% endif %}
|
||||
@@ -30,10 +32,6 @@
|
||||
{% trans "Pricing" as text %}
|
||||
{% include "sidebar_item.html" with label="pricing" text=text icon="fa-dollar-sign" %}
|
||||
{% endif %}
|
||||
{% if part.salable or part.component %}
|
||||
{% trans "Allocations" as text %}
|
||||
{% include "sidebar_item.html" with label="allocations" text=text icon="fa-bookmark" %}
|
||||
{% endif %}
|
||||
{% if part.purchaseable and roles.purchase_order.view %}
|
||||
{% trans "Suppliers" as text %}
|
||||
{% include "sidebar_item.html" with label="suppliers" text=text icon="fa-building" %}
|
||||
|
||||
@@ -172,3 +172,122 @@ class CategoryTest(TestCase):
|
||||
# And one part should have no default location at all
|
||||
w = Part.objects.get(name='Widget')
|
||||
self.assertIsNone(w.get_default_location())
|
||||
|
||||
def test_category_tree(self):
|
||||
"""
|
||||
Unit tests for the part category tree structure (MPTT)
|
||||
Ensure that the MPTT structure is rebuilt correctly,
|
||||
and the correct ancestor tree is observed.
|
||||
"""
|
||||
|
||||
# Clear out any existing parts
|
||||
Part.objects.all().delete()
|
||||
|
||||
# First, create a structured tree of part categories
|
||||
A = PartCategory.objects.create(
|
||||
name='A',
|
||||
description='Top level category',
|
||||
)
|
||||
|
||||
B1 = PartCategory.objects.create(name='B1', parent=A)
|
||||
B2 = PartCategory.objects.create(name='B2', parent=A)
|
||||
B3 = PartCategory.objects.create(name='B3', parent=A)
|
||||
|
||||
C11 = PartCategory.objects.create(name='C11', parent=B1)
|
||||
C12 = PartCategory.objects.create(name='C12', parent=B1)
|
||||
C13 = PartCategory.objects.create(name='C13', parent=B1)
|
||||
|
||||
C21 = PartCategory.objects.create(name='C21', parent=B2)
|
||||
C22 = PartCategory.objects.create(name='C22', parent=B2)
|
||||
C23 = PartCategory.objects.create(name='C23', parent=B2)
|
||||
|
||||
C31 = PartCategory.objects.create(name='C31', parent=B3)
|
||||
C32 = PartCategory.objects.create(name='C32', parent=B3)
|
||||
C33 = PartCategory.objects.create(name='C33', parent=B3)
|
||||
|
||||
# Check that the tree_id value is correct
|
||||
for cat in [B1, B2, B3, C11, C22, C33]:
|
||||
self.assertEqual(cat.tree_id, A.tree_id)
|
||||
self.assertEqual(cat.level, cat.parent.level + 1)
|
||||
self.assertEqual(cat.get_ancestors().count(), cat.level)
|
||||
|
||||
# Spot check for C31
|
||||
ancestors = C31.get_ancestors(include_self=True)
|
||||
|
||||
self.assertEqual(ancestors.count(), 3)
|
||||
self.assertEqual(ancestors[0], A)
|
||||
self.assertEqual(ancestors[1], B3)
|
||||
self.assertEqual(ancestors[2], C31)
|
||||
|
||||
# At this point, we are confident that the tree is correctly structured
|
||||
|
||||
# Add some parts to category B3
|
||||
|
||||
for i in range(10):
|
||||
Part.objects.create(
|
||||
name=f'Part {i}',
|
||||
description='A test part',
|
||||
category=B3,
|
||||
)
|
||||
|
||||
self.assertEqual(Part.objects.filter(category=B3).count(), 10)
|
||||
self.assertEqual(Part.objects.filter(category=A).count(), 0)
|
||||
|
||||
# Delete category B3
|
||||
B3.delete()
|
||||
|
||||
# Child parts have been moved to category A
|
||||
self.assertEqual(Part.objects.filter(category=A).count(), 10)
|
||||
|
||||
for cat in [C31, C32, C33]:
|
||||
# These categories should now be directly under A
|
||||
cat.refresh_from_db()
|
||||
|
||||
self.assertEqual(cat.parent, A)
|
||||
self.assertEqual(cat.level, 1)
|
||||
self.assertEqual(cat.get_ancestors().count(), 1)
|
||||
self.assertEqual(cat.get_ancestors()[0], A)
|
||||
|
||||
# Now, delete category A
|
||||
A.delete()
|
||||
|
||||
# Parts have now been moved to the top-level category
|
||||
self.assertEqual(Part.objects.filter(category=None).count(), 10)
|
||||
|
||||
for loc in [B1, B2, C31, C32, C33]:
|
||||
# These should now all be "top level" categories
|
||||
loc.refresh_from_db()
|
||||
|
||||
self.assertEqual(loc.level, 0)
|
||||
self.assertEqual(loc.parent, None)
|
||||
|
||||
# Check descendants for B1
|
||||
descendants = B1.get_descendants()
|
||||
self.assertEqual(descendants.count(), 3)
|
||||
|
||||
for loc in [C11, C12, C13]:
|
||||
self.assertTrue(loc in descendants)
|
||||
|
||||
# Check category C1x, should be B1 -> C1x
|
||||
for loc in [C11, C12, C13]:
|
||||
loc.refresh_from_db()
|
||||
|
||||
self.assertEqual(loc.level, 1)
|
||||
self.assertEqual(loc.parent, B1)
|
||||
ancestors = loc.get_ancestors(include_self=True)
|
||||
|
||||
self.assertEqual(ancestors.count(), 2)
|
||||
self.assertEqual(ancestors[0], B1)
|
||||
self.assertEqual(ancestors[1], loc)
|
||||
|
||||
# Check category C2x, should be B2 -> C2x
|
||||
for loc in [C21, C22, C23]:
|
||||
loc.refresh_from_db()
|
||||
|
||||
self.assertEqual(loc.level, 1)
|
||||
self.assertEqual(loc.parent, B2)
|
||||
ancestors = loc.get_ancestors(include_self=True)
|
||||
|
||||
self.assertEqual(ancestors.count(), 2)
|
||||
self.assertEqual(ancestors[0], B2)
|
||||
self.assertEqual(ancestors[1], loc)
|
||||
|
||||
@@ -348,6 +348,26 @@ class PartSettingsTest(TestCase):
|
||||
part = Part(name='Hello', description='A thing', IPN='IPN123', revision='C')
|
||||
part.full_clean()
|
||||
|
||||
# Any duplicate IPN should raise an error
|
||||
Part.objects.create(name='xyz', revision='1', description='A part', IPN='UNIQUE')
|
||||
|
||||
# Case insensitive, so variations on spelling should throw an error
|
||||
for ipn in ['UNiquE', 'uniQuE', 'unique']:
|
||||
with self.assertRaises(ValidationError):
|
||||
Part.objects.create(name='xyz', revision='2', description='A part', IPN=ipn)
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
Part.objects.create(name='zyx', description='A part', IPN='UNIQUE')
|
||||
|
||||
# However, *blank* / empty IPN values should be allowed, even if duplicates are not
|
||||
# Note that leading / trailling whitespace characters are trimmed, too
|
||||
Part.objects.create(name='abc', revision='1', description='A part', IPN=None)
|
||||
Part.objects.create(name='abc', revision='2', description='A part', IPN='')
|
||||
Part.objects.create(name='abc', revision='3', description='A part', IPN=None)
|
||||
Part.objects.create(name='abc', revision='4', description='A part', IPN=' ')
|
||||
Part.objects.create(name='abc', revision='5', description='A part', IPN=' ')
|
||||
Part.objects.create(name='abc', revision='6', description='A part', IPN=' ')
|
||||
|
||||
|
||||
class PartSubscriptionTests(TestCase):
|
||||
|
||||
|
||||
@@ -54,6 +54,35 @@ class StockLocation(InvenTreeTree):
|
||||
Stock locations can be heirarchical as required
|
||||
"""
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
"""
|
||||
Custom model deletion routine, which updates any child locations or items.
|
||||
This must be handled within a transaction.atomic(), otherwise the tree structure is damaged
|
||||
"""
|
||||
|
||||
with transaction.atomic():
|
||||
|
||||
parent = self.parent
|
||||
tree_id = self.tree_id
|
||||
|
||||
# Update each stock item in the stock location
|
||||
for item in self.stock_items.all():
|
||||
item.location = self.parent
|
||||
item.save()
|
||||
|
||||
# Update each child category
|
||||
for child in self.children.all():
|
||||
child.parent = self.parent
|
||||
child.save()
|
||||
|
||||
super().delete(*args, **kwargs)
|
||||
|
||||
if parent is not None:
|
||||
# Partially rebuild the tree (cheaper than a complete rebuild)
|
||||
StockLocation.objects.partial_rebuild(tree_id)
|
||||
else:
|
||||
StockLocation.objects.rebuild()
|
||||
|
||||
@staticmethod
|
||||
def get_api_url():
|
||||
return reverse('api-location-list')
|
||||
@@ -159,20 +188,6 @@ class StockLocation(InvenTreeTree):
|
||||
return self.stock_item_count()
|
||||
|
||||
|
||||
@receiver(pre_delete, sender=StockLocation, dispatch_uid='stocklocation_delete_log')
|
||||
def before_delete_stock_location(sender, instance, using, **kwargs):
|
||||
|
||||
# Update each part in the stock location
|
||||
for item in instance.stock_items.all():
|
||||
item.location = instance.parent
|
||||
item.save()
|
||||
|
||||
# Update each child category
|
||||
for child in instance.children.all():
|
||||
child.parent = instance.parent
|
||||
child.save()
|
||||
|
||||
|
||||
class StockItemManager(TreeManager):
|
||||
"""
|
||||
Custom database manager for the StockItem class.
|
||||
@@ -269,10 +284,62 @@ class StockItem(MPTTModel):
|
||||
serial_int = 0
|
||||
|
||||
if serial is not None:
|
||||
serial_int = extract_int(str(serial))
|
||||
|
||||
serial = str(serial).strip()
|
||||
|
||||
serial_int = extract_int(serial)
|
||||
|
||||
self.serial_int = serial_int
|
||||
|
||||
def get_next_serialized_item(self, include_variants=True, reverse=False):
|
||||
"""
|
||||
Get the "next" serial number for the part this stock item references.
|
||||
|
||||
e.g. if this stock item has a serial number 100, we may return the stock item with serial number 101
|
||||
|
||||
Note that this only works for "serialized" stock items with integer values
|
||||
|
||||
Args:
|
||||
include_variants: True if we wish to include stock for variant parts
|
||||
reverse: True if we want to return the "previous" (lower) serial number
|
||||
|
||||
Returns:
|
||||
A StockItem object matching the requirements, or None
|
||||
|
||||
"""
|
||||
|
||||
if not self.serialized:
|
||||
return None
|
||||
|
||||
# Find only serialized stock items
|
||||
items = StockItem.objects.exclude(serial=None).exclude(serial='')
|
||||
|
||||
if include_variants:
|
||||
# Match against any part within the variant tree
|
||||
items = items.filter(part__tree_id=self.part.tree_id)
|
||||
else:
|
||||
# Match only against the specific part
|
||||
items = items.filter(part=self.part)
|
||||
|
||||
serial = self.serial_int
|
||||
|
||||
if reverse:
|
||||
# Select only stock items with lower serial numbers, in decreasing order
|
||||
items = items.filter(serial_int__lt=serial)
|
||||
items = items.order_by('-serial_int')
|
||||
else:
|
||||
# Select only stock items with higher serial numbers, in increasing order
|
||||
items = items.filter(serial_int__gt=serial)
|
||||
items = items.order_by('serial_int')
|
||||
|
||||
if items.count() > 0:
|
||||
item = items.first()
|
||||
|
||||
if item.serialized:
|
||||
return item
|
||||
|
||||
return None
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
"""
|
||||
Save this StockItem to the database. Performs a number of checks:
|
||||
@@ -350,7 +417,7 @@ class StockItem(MPTTModel):
|
||||
@property
|
||||
def serialized(self):
|
||||
""" Return True if this StockItem is serialized """
|
||||
return self.serial is not None and self.quantity == 1
|
||||
return self.serial is not None and len(str(self.serial).strip()) > 0 and self.quantity == 1
|
||||
|
||||
def validate_unique(self, exclude=None):
|
||||
"""
|
||||
@@ -386,6 +453,14 @@ class StockItem(MPTTModel):
|
||||
|
||||
super().clean()
|
||||
|
||||
# Strip serial number field
|
||||
if type(self.serial) is str:
|
||||
self.serial = self.serial.strip()
|
||||
|
||||
# Strip batch code field
|
||||
if type(self.batch) is str:
|
||||
self.batch = self.batch.strip()
|
||||
|
||||
try:
|
||||
if self.part.trackable:
|
||||
# Trackable parts must have integer values for quantity field!
|
||||
|
||||
@@ -37,19 +37,36 @@
|
||||
</div>
|
||||
|
||||
<div class='panel panel-hidden' id='panel-allocations'>
|
||||
|
||||
{% if item.part.component %}
|
||||
<div class='panel-heading'>
|
||||
<h4>{% trans "Stock Item Allocations" %}</h4>
|
||||
<h4>{% trans "Build Order Allocations" %}</h4>
|
||||
{% include "spacer.html" %}
|
||||
</div>
|
||||
<div class='panel-content'>
|
||||
<div id='allocations-button-toolbar'>
|
||||
<div id='build-order-allocations-toolbar'>
|
||||
<div class='btn-group' role='group'>
|
||||
{% include "filter_list.html" with id="allocations" %}
|
||||
{% include "filter_list.html" with id="buildorderallocation" %}
|
||||
</div>
|
||||
</div>
|
||||
<table class='table table-striped table-condensed' data-toolbar='#allocatoins-button-toolbar' id='stock-allocation-table'></table>
|
||||
<table class='table table-striped table-condensed' data-toolbar='#build-order-allocation-toolbar' id='build-order-allocation-table'></table>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if item.part.salable %}
|
||||
<div class='panel-heading'>
|
||||
<h4>{% trans "Sales Order Allocations" %}</h4>
|
||||
{% include "spacer.html" %}
|
||||
</div>
|
||||
<div class='panel-content'>
|
||||
<div id='sales-order-allocations-toolbar'>
|
||||
<div class='btn-group' role='group'>
|
||||
{% include "filter_list.html" with id="salesorderallocation" %}
|
||||
</div>
|
||||
</div>
|
||||
<table class='table table-striped table-condensed' data-toolbar='#sales-order-allocation-toolbar' id='sales-order-allocation-table'></table>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class='panel panel-hidden' id='panel-children'>
|
||||
@@ -164,14 +181,21 @@
|
||||
// Load the "allocations" tab
|
||||
onPanelLoad('allocations', function() {
|
||||
|
||||
loadStockAllocationTable(
|
||||
$("#stock-allocation-table"),
|
||||
{
|
||||
params: {
|
||||
stock_item: {{ item.pk }},
|
||||
},
|
||||
{% if item.part.component %}
|
||||
loadBuildOrderAllocationTable('#build-order-allocation-table', {
|
||||
params: {
|
||||
stock_item: {{ item.pk }},
|
||||
}
|
||||
);
|
||||
});
|
||||
{% endif %}
|
||||
|
||||
{% if item.part.salable %}
|
||||
loadSalesOrderAllocationTable('#sales-order-allocation-table', {
|
||||
params: {
|
||||
stock_item: {{ item.pk }},
|
||||
}
|
||||
});
|
||||
{% endif %}
|
||||
});
|
||||
|
||||
$('#stock-item-install').click(function() {
|
||||
|
||||
@@ -346,6 +346,118 @@ class StockTest(TestCase):
|
||||
with self.assertRaises(StockItem.DoesNotExist):
|
||||
w2 = StockItem.objects.get(pk=101)
|
||||
|
||||
def test_serials(self):
|
||||
"""
|
||||
Tests for stock serialization
|
||||
"""
|
||||
|
||||
p = Part.objects.create(
|
||||
name='trackable part',
|
||||
description='trackable part',
|
||||
trackable=True,
|
||||
)
|
||||
|
||||
item = StockItem.objects.create(
|
||||
part=p,
|
||||
quantity=1,
|
||||
)
|
||||
|
||||
self.assertFalse(item.serialized)
|
||||
|
||||
item.serial = None
|
||||
item.save()
|
||||
self.assertFalse(item.serialized)
|
||||
|
||||
item.serial = ' '
|
||||
item.save()
|
||||
self.assertFalse(item.serialized)
|
||||
|
||||
item.serial = ''
|
||||
item.save()
|
||||
self.assertFalse(item.serialized)
|
||||
|
||||
item.serial = '1'
|
||||
item.save()
|
||||
self.assertTrue(item.serialized)
|
||||
|
||||
def test_big_serials(self):
|
||||
"""
|
||||
Unit tests for "large" serial numbers which exceed integer encoding
|
||||
"""
|
||||
|
||||
p = Part.objects.create(
|
||||
name='trackable part',
|
||||
description='trackable part',
|
||||
trackable=True,
|
||||
)
|
||||
|
||||
item = StockItem.objects.create(
|
||||
part=p,
|
||||
quantity=1,
|
||||
)
|
||||
|
||||
for sn in [12345, '12345', ' 12345 ']:
|
||||
item.serial = sn
|
||||
item.save()
|
||||
|
||||
self.assertEqual(item.serial_int, 12345)
|
||||
|
||||
item.serial = "-123"
|
||||
item.save()
|
||||
|
||||
# Negative number should map to zero
|
||||
self.assertEqual(item.serial_int, 0)
|
||||
|
||||
# Test a very very large value
|
||||
item.serial = '99999999999999999999999999999999999999999999999999999'
|
||||
item.save()
|
||||
|
||||
self.assertEqual(item.serial_int, 0x7fffffff)
|
||||
|
||||
# Non-numeric values should encode to zero
|
||||
for sn in ['apple', 'banana', 'carrot']:
|
||||
item.serial = sn
|
||||
item.save()
|
||||
|
||||
self.assertEqual(item.serial_int, 0)
|
||||
|
||||
# Next, test for incremenet / decrement functionality
|
||||
item.serial = 100
|
||||
item.save()
|
||||
|
||||
item_next = StockItem.objects.create(
|
||||
part=p,
|
||||
serial=150,
|
||||
quantity=1
|
||||
)
|
||||
|
||||
self.assertEqual(item.get_next_serialized_item(), item_next)
|
||||
|
||||
item_prev = StockItem.objects.create(
|
||||
part=p,
|
||||
serial=' 57',
|
||||
quantity=1,
|
||||
)
|
||||
|
||||
self.assertEqual(item.get_next_serialized_item(reverse=True), item_prev)
|
||||
|
||||
# Create a number of serialized stock items around the current item
|
||||
for i in range(75, 125):
|
||||
try:
|
||||
StockItem.objects.create(
|
||||
part=p,
|
||||
serial=i,
|
||||
quantity=1,
|
||||
)
|
||||
except:
|
||||
pass
|
||||
|
||||
item_next = item.get_next_serialized_item()
|
||||
item_prev = item.get_next_serialized_item(reverse=True)
|
||||
|
||||
self.assertEqual(item_next.serial_int, 101)
|
||||
self.assertEqual(item_prev.serial_int, 99)
|
||||
|
||||
def test_serialize_stock_invalid(self):
|
||||
"""
|
||||
Test manual serialization of parts.
|
||||
@@ -412,6 +524,174 @@ class StockTest(TestCase):
|
||||
# Serialize the remainder of the stock
|
||||
item.serializeStock(2, [99, 100], self.user)
|
||||
|
||||
def test_location_tree(self):
|
||||
"""
|
||||
Unit tests for stock location tree structure (MPTT).
|
||||
Ensure that the MPTT structure is rebuilt correctly,
|
||||
and the corrent ancestor tree is observed.
|
||||
|
||||
Ref: https://github.com/inventree/InvenTree/issues/2636
|
||||
Ref: https://github.com/inventree/InvenTree/issues/2733
|
||||
"""
|
||||
|
||||
# First, we will create a stock location structure
|
||||
|
||||
A = StockLocation.objects.create(
|
||||
name='A',
|
||||
description='Top level location'
|
||||
)
|
||||
|
||||
B1 = StockLocation.objects.create(
|
||||
name='B1',
|
||||
parent=A
|
||||
)
|
||||
|
||||
B2 = StockLocation.objects.create(
|
||||
name='B2',
|
||||
parent=A
|
||||
)
|
||||
|
||||
B3 = StockLocation.objects.create(
|
||||
name='B3',
|
||||
parent=A
|
||||
)
|
||||
|
||||
C11 = StockLocation.objects.create(
|
||||
name='C11',
|
||||
parent=B1,
|
||||
)
|
||||
|
||||
C12 = StockLocation.objects.create(
|
||||
name='C12',
|
||||
parent=B1,
|
||||
)
|
||||
|
||||
C21 = StockLocation.objects.create(
|
||||
name='C21',
|
||||
parent=B2,
|
||||
)
|
||||
|
||||
C22 = StockLocation.objects.create(
|
||||
name='C22',
|
||||
parent=B2,
|
||||
)
|
||||
|
||||
C31 = StockLocation.objects.create(
|
||||
name='C31',
|
||||
parent=B3,
|
||||
)
|
||||
|
||||
C32 = StockLocation.objects.create(
|
||||
name='C32',
|
||||
parent=B3
|
||||
)
|
||||
|
||||
# Check that the tree_id is correct for each sublocation
|
||||
for loc in [B1, B2, B3, C11, C12, C21, C22, C31, C32]:
|
||||
self.assertEqual(loc.tree_id, A.tree_id)
|
||||
|
||||
# Check that the tree levels are correct for each node in the tree
|
||||
|
||||
self.assertEqual(A.level, 0)
|
||||
self.assertEqual(A.get_ancestors().count(), 0)
|
||||
|
||||
for loc in [B1, B2, B3]:
|
||||
self.assertEqual(loc.parent, A)
|
||||
self.assertEqual(loc.level, 1)
|
||||
self.assertEqual(loc.get_ancestors().count(), 1)
|
||||
|
||||
for loc in [C11, C12]:
|
||||
self.assertEqual(loc.parent, B1)
|
||||
self.assertEqual(loc.level, 2)
|
||||
self.assertEqual(loc.get_ancestors().count(), 2)
|
||||
|
||||
for loc in [C21, C22]:
|
||||
self.assertEqual(loc.parent, B2)
|
||||
self.assertEqual(loc.level, 2)
|
||||
self.assertEqual(loc.get_ancestors().count(), 2)
|
||||
|
||||
for loc in [C31, C32]:
|
||||
self.assertEqual(loc.parent, B3)
|
||||
self.assertEqual(loc.level, 2)
|
||||
self.assertEqual(loc.get_ancestors().count(), 2)
|
||||
|
||||
# Spot-check for C32
|
||||
ancestors = C32.get_ancestors(include_self=True)
|
||||
|
||||
self.assertEqual(ancestors[0], A)
|
||||
self.assertEqual(ancestors[1], B3)
|
||||
self.assertEqual(ancestors[2], C32)
|
||||
|
||||
# At this point, we are confident that the tree is correctly structured.
|
||||
|
||||
# Let's delete node B3 from the tree. We expect that:
|
||||
# - C31 should move directly under A
|
||||
# - C32 should move directly under A
|
||||
|
||||
# Add some stock items to B3
|
||||
for i in range(10):
|
||||
StockItem.objects.create(
|
||||
part=Part.objects.get(pk=1),
|
||||
quantity=10,
|
||||
location=B3
|
||||
)
|
||||
|
||||
self.assertEqual(StockItem.objects.filter(location=B3).count(), 10)
|
||||
self.assertEqual(StockItem.objects.filter(location=A).count(), 0)
|
||||
|
||||
B3.delete()
|
||||
|
||||
A.refresh_from_db()
|
||||
C31.refresh_from_db()
|
||||
C32.refresh_from_db()
|
||||
|
||||
# Stock items have been moved to A
|
||||
self.assertEqual(StockItem.objects.filter(location=A).count(), 10)
|
||||
|
||||
# Parent should be A
|
||||
self.assertEqual(C31.parent, A)
|
||||
self.assertEqual(C32.parent, A)
|
||||
|
||||
self.assertEqual(C31.tree_id, A.tree_id)
|
||||
self.assertEqual(C31.level, 1)
|
||||
|
||||
self.assertEqual(C32.tree_id, A.tree_id)
|
||||
self.assertEqual(C32.level, 1)
|
||||
|
||||
# Ancestor tree should be just A
|
||||
ancestors = C31.get_ancestors()
|
||||
self.assertEqual(ancestors.count(), 1)
|
||||
self.assertEqual(ancestors[0], A)
|
||||
|
||||
ancestors = C32.get_ancestors()
|
||||
self.assertEqual(ancestors.count(), 1)
|
||||
self.assertEqual(ancestors[0], A)
|
||||
|
||||
# Delete A
|
||||
A.delete()
|
||||
|
||||
# Stock items have been moved to top-level location
|
||||
self.assertEqual(StockItem.objects.filter(location=None).count(), 10)
|
||||
|
||||
for loc in [B1, B2, C11, C12, C21, C22]:
|
||||
loc.refresh_from_db()
|
||||
|
||||
self.assertEqual(B1.parent, None)
|
||||
self.assertEqual(B2.parent, None)
|
||||
|
||||
self.assertEqual(C11.parent, B1)
|
||||
self.assertEqual(C12.parent, B1)
|
||||
self.assertEqual(C11.get_ancestors().count(), 1)
|
||||
self.assertEqual(C12.get_ancestors().count(), 1)
|
||||
|
||||
self.assertEqual(C21.parent, B2)
|
||||
self.assertEqual(C22.parent, B2)
|
||||
|
||||
ancestors = C21.get_ancestors()
|
||||
|
||||
self.assertEqual(C21.get_ancestors().count(), 1)
|
||||
self.assertEqual(C22.get_ancestors().count(), 1)
|
||||
|
||||
|
||||
class VariantTest(StockTest):
|
||||
"""
|
||||
|
||||
@@ -103,43 +103,16 @@ class StockItemDetail(InvenTreeRoleMixin, DetailView):
|
||||
model = StockItem
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
""" add previous and next item """
|
||||
"""
|
||||
Add information on the "next" and "previous" StockItem objects,
|
||||
based on the serial numbers.
|
||||
"""
|
||||
|
||||
data = super().get_context_data(**kwargs)
|
||||
|
||||
if self.object.serialized:
|
||||
|
||||
serial_elem = {}
|
||||
|
||||
try:
|
||||
current = int(self.object.serial)
|
||||
|
||||
for item in self.object.part.stock_items.all():
|
||||
|
||||
if item.serialized:
|
||||
try:
|
||||
sn = int(item.serial)
|
||||
serial_elem[sn] = item
|
||||
except ValueError:
|
||||
# We only support integer serial number progression
|
||||
pass
|
||||
|
||||
serials = serial_elem.keys()
|
||||
|
||||
# previous
|
||||
for nbr in range(current - 1, min(serials), -1):
|
||||
if nbr in serials:
|
||||
data['previous'] = serial_elem.get(nbr, None)
|
||||
break
|
||||
|
||||
# next
|
||||
for nbr in range(current + 1, max(serials) + 1):
|
||||
if nbr in serials:
|
||||
data['next'] = serial_elem.get(nbr, None)
|
||||
break
|
||||
|
||||
except ValueError:
|
||||
# We only support integer serial number progression
|
||||
pass
|
||||
data['previous'] = self.object.get_next_serialized_item(reverse=True)
|
||||
data['next'] = self.object.get_next_serialized_item()
|
||||
|
||||
data['ownership_enabled'] = common.models.InvenTreeSetting.get_setting('STOCK_OWNERSHIP_CONTROL')
|
||||
data['item_owner'] = self.object.get_item_owner()
|
||||
|
||||
@@ -824,7 +824,7 @@ function loadPurchaseOrderTable(table, options) {
|
||||
sortable: true,
|
||||
sortName: 'supplier__name',
|
||||
formatter: function(value, row) {
|
||||
return imageHoverIcon(row.supplier_detail.image) + renderLink(row.supplier_detail.name, `/company/${row.supplier}/purchase-orders/`);
|
||||
return imageHoverIcon(row.supplier_detail.image) + renderLink(row.supplier_detail.name, `/company/${row.supplier}/?display=purchase-orders`);
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -1843,15 +1843,7 @@ function loadSalesOrderAllocationTable(table, options={}) {
|
||||
field: 'location',
|
||||
title: '{% trans "Location" %}',
|
||||
formatter: function(value, row) {
|
||||
|
||||
if (!value) {
|
||||
return '{% trans "Location not specified" %}';
|
||||
}
|
||||
|
||||
var link = `/stock/location/${value}`;
|
||||
var text = row.location_detail.description;
|
||||
|
||||
return renderLink(text, link);
|
||||
return locationDetail(row.item_detail, true);
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
@@ -48,7 +48,6 @@
|
||||
findStockItemBySerialNumber,
|
||||
installStockItem,
|
||||
loadInstalledInTable,
|
||||
loadStockAllocationTable,
|
||||
loadStockLocationTable,
|
||||
loadStockTable,
|
||||
loadStockTestResultsTable,
|
||||
@@ -2328,157 +2327,6 @@ function loadStockTable(table, options) {
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Display a table of allocated stock, for either a part or stock item
|
||||
* Allocations are displayed for:
|
||||
*
|
||||
* a) Sales Orders
|
||||
* b) Build Orders
|
||||
*/
|
||||
function loadStockAllocationTable(table, options={}) {
|
||||
|
||||
var params = options.params || {};
|
||||
|
||||
params.build_detail = true;
|
||||
|
||||
var filterListElement = options.filterList || '#filter-list-allocations';
|
||||
|
||||
var filters = {};
|
||||
|
||||
var filterKey = options.filterKey || options.name || 'allocations';
|
||||
|
||||
var original = {};
|
||||
|
||||
for (var k in params) {
|
||||
original[k] = params[k];
|
||||
filters[k] = params[k];
|
||||
}
|
||||
|
||||
setupFilterList(filterKey, table, filterListElement);
|
||||
|
||||
/*
|
||||
* We have two separate API queries to make here:
|
||||
* a) Build Order Allocations
|
||||
* b) Sales Order Allocations
|
||||
*
|
||||
* We will let the call to inventreeTable take care of build orders,
|
||||
* and then load sales orders after that.
|
||||
*/
|
||||
table.inventreeTable({
|
||||
url: '{% url "api-build-item-list" %}',
|
||||
name: 'allocations',
|
||||
original: original,
|
||||
method: 'get',
|
||||
queryParams: filters,
|
||||
sidePagination: 'client',
|
||||
showColumns: false,
|
||||
onLoadSuccess: function(tableData) {
|
||||
|
||||
var query_params = params;
|
||||
|
||||
query_params.customer_detail = true;
|
||||
query_params.order_detail = true;
|
||||
|
||||
delete query_params.build_detail;
|
||||
|
||||
// Load sales order allocation data
|
||||
inventreeGet('{% url "api-so-allocation-list" %}', query_params, {
|
||||
success: function(data) {
|
||||
// Update table to include sales order data
|
||||
$(table).bootstrapTable('append', data);
|
||||
}
|
||||
});
|
||||
},
|
||||
columns: [
|
||||
{
|
||||
field: 'order',
|
||||
title: '{% trans "Order" %}',
|
||||
formatter: function(value, row) {
|
||||
|
||||
var html = '';
|
||||
|
||||
if (row.build) {
|
||||
|
||||
// Add an icon for the part being built
|
||||
html += thumbnailImage(row.build_detail.part_detail.thumbnail, {
|
||||
title: row.build_detail.part_detail.full_name
|
||||
});
|
||||
|
||||
html += ' ';
|
||||
|
||||
html += renderLink(
|
||||
global_settings.BUILDORDER_REFERENCE_PREFIX + row.build_detail.reference,
|
||||
`/build/${row.build}/`
|
||||
);
|
||||
|
||||
html += makeIconBadge('fa-tools', '{% trans "Build Order" %}');
|
||||
} else if (row.order) {
|
||||
|
||||
// Add an icon for the customer
|
||||
html += thumbnailImage(row.customer_detail.thumbnail || row.customer_detail.image, {
|
||||
title: row.customer_detail.name,
|
||||
});
|
||||
|
||||
html += ' ';
|
||||
|
||||
html += renderLink(
|
||||
global_settings.SALESORDER_REFERENCE_PREFIX + row.order_detail.reference,
|
||||
`/order/sales-order/${row.order}/`
|
||||
);
|
||||
html += makeIconBadge('fa-truck', '{% trans "Sales Order" %}');
|
||||
} else {
|
||||
return '-';
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'description',
|
||||
title: '{% trans "Description" %}',
|
||||
formatter: function(value, row) {
|
||||
if (row.order_detail) {
|
||||
return row.order_detail.description;
|
||||
} else if (row.build_detail) {
|
||||
return row.build_detail.title;
|
||||
} else {
|
||||
return '-';
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'status',
|
||||
title: '{% trans "Order Status" %}',
|
||||
formatter: function(value, row) {
|
||||
if (row.build) {
|
||||
return buildStatusDisplay(row.build_detail.status);
|
||||
} else if (row.order) {
|
||||
return salesOrderStatusDisplay(row.order_detail.status);
|
||||
} else {
|
||||
return '-';
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'quantity',
|
||||
title: '{% trans "Allocated Quantity" %}',
|
||||
formatter: function(value, row) {
|
||||
var text = value;
|
||||
var pk = row.stock_item || row.item;
|
||||
|
||||
if (pk) {
|
||||
var url = `/stock/item/${pk}/`;
|
||||
return renderLink(text, url);
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
},
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Display a table of stock locations
|
||||
*/
|
||||
|
||||
@@ -341,6 +341,15 @@ function getAvailableTableFilters(tableKey) {
|
||||
};
|
||||
}
|
||||
|
||||
if (tableKey == 'salesorderallocation') {
|
||||
return {
|
||||
outstanding: {
|
||||
type: 'bool',
|
||||
title: '{% trans "Outstanding" %}',
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
if (tableKey == 'salesorder') {
|
||||
return {
|
||||
status: {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
{% load i18n %}
|
||||
|
||||
<div class='panel' id='{{ panel_id }}'>
|
||||
<div class='panel-heading'>
|
||||
<h4>
|
||||
|
||||
@@ -95,6 +95,9 @@ RUN echo "Downloading InvenTree from ${INVENTREE_GIT_REPO}"
|
||||
|
||||
RUN git clone --branch ${INVENTREE_GIT_BRANCH} --depth 1 ${INVENTREE_GIT_REPO} ${INVENTREE_HOME}
|
||||
|
||||
# Ref: https://github.blog/2022-04-12-git-security-vulnerability-announced/
|
||||
RUN git config --global --add safe.directory ${INVENTREE_HOME}
|
||||
|
||||
# Checkout against a particular git tag
|
||||
RUN if [ -n "${INVENTREE_GIT_TAG}" ] ; then cd ${INVENTREE_HOME} && git fetch --all --tags && git checkout tags/${INVENTREE_GIT_TAG} -b v${INVENTREE_GIT_TAG}-branch ; fi
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Base python requirements for docker containers
|
||||
|
||||
# Basic package requirements
|
||||
setuptools>=57.4.0
|
||||
setuptools>=57.4.0,<=60.1.0
|
||||
wheel>=0.37.0
|
||||
invoke>=1.4.0 # Invoke build tool
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# Please keep this list sorted
|
||||
Django==3.2.12 # Django package
|
||||
bleach==4.1.0 # HTML sanitization
|
||||
certifi # Certifi is (most likely) installed through one of the requirements above
|
||||
coreapi==2.3.0 # API documentation
|
||||
coverage==5.3 # Unit test coverage
|
||||
|
||||
Reference in New Issue
Block a user