mirror of
https://github.com/inventree/InvenTree.git
synced 2026-12-01 20:11:30 +00:00
small fixes (#13342)
* merge duplicate branches * fix type * remove impossible branches * fix types * make more tolerant * update queries * fix sec check
This commit is contained in:
1 parent
4dfbabe496
commit
629a411612
14 files changed
+103
-111
No files matched your search
@@ -34,15 +34,13 @@ class Command(BaseCommand):
|
|||||||
self.stdout.write('Database connection failed, retrying ...')
|
self.stdout.write('Database connection failed, retrying ...')
|
||||||
self.stdout.flush()
|
self.stdout.flush()
|
||||||
else:
|
else:
|
||||||
if not connection.is_usable():
|
if not connection.is_usable() and verbose:
|
||||||
if verbose:
|
self.stdout.write('Database configuration is not usable')
|
||||||
self.stdout.write('Database configuration is not usable')
|
|
||||||
self.stdout.flush()
|
|
||||||
|
|
||||||
if connected:
|
|
||||||
if verbose:
|
|
||||||
self.stdout.write('Database connection successful!')
|
|
||||||
self.stdout.flush()
|
self.stdout.flush()
|
||||||
|
|
||||||
|
if connected and verbose:
|
||||||
|
self.stdout.write('Database connection successful!')
|
||||||
|
self.stdout.flush()
|
||||||
else:
|
else:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
|||||||
@@ -145,11 +145,11 @@ class InvenTreeMetadata(SimpleMetadata):
|
|||||||
del actions[method]
|
del actions[method]
|
||||||
|
|
||||||
# Add a 'DELETE' action if we are allowed to delete
|
# Add a 'DELETE' action if we are allowed to delete
|
||||||
if 'DELETE' in view.allowed_methods:
|
if 'DELETE' in view.allowed_methods and (
|
||||||
if check_user_permission(user, self.model, 'delete') or (
|
check_user_permission(user, self.model, 'delete')
|
||||||
role_required and check_user_role(user, role_required, 'delete')
|
or (role_required and check_user_role(user, role_required, 'delete'))
|
||||||
):
|
):
|
||||||
actions['DELETE'] = {}
|
actions['DELETE'] = {}
|
||||||
|
|
||||||
metadata['actions'] = actions
|
metadata['actions'] = actions
|
||||||
|
|
||||||
|
|||||||
@@ -85,9 +85,9 @@ class FilterableSerializerMixin:
|
|||||||
This introduces overhead during initialization, so only use this mixin when necessary.
|
This introduces overhead during initialization, so only use this mixin when necessary.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
optional_filters: dict = None
|
optional_filters: Optional[dict[str, bool]] = None
|
||||||
fields_to_remove: set = None
|
fields_to_remove: Optional[set[str]] = None
|
||||||
optional_fields: set = None
|
optional_fields: Optional[set[str]] = None
|
||||||
filter_on_query: bool = True
|
filter_on_query: bool = True
|
||||||
|
|
||||||
# Keyword argument used to pass the requesting user to nested serializers
|
# Keyword argument used to pass the requesting user to nested serializers
|
||||||
@@ -113,8 +113,9 @@ class FilterableSerializerMixin:
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
# Ensure any fields we are *not* using are removed
|
# Ensure any fields we are *not* using are removed
|
||||||
for field_name in self.fields_to_remove:
|
if _fields := self.fields_to_remove:
|
||||||
self.fields.pop(field_name, None)
|
for field_name in _fields:
|
||||||
|
self.fields.pop(field_name, None)
|
||||||
|
|
||||||
def is_exporting(self) -> bool:
|
def is_exporting(self) -> bool:
|
||||||
"""Determine if we are exporting data."""
|
"""Determine if we are exporting data."""
|
||||||
@@ -152,8 +153,11 @@ class FilterableSerializerMixin:
|
|||||||
# This allows multiple optional fields to share the same filter value
|
# This allows multiple optional fields to share the same filter value
|
||||||
# Note: fields sharing a filter_ref may still embed different models, so the
|
# Note: fields sharing a filter_ref may still embed different models, so the
|
||||||
# permission gate is re-applied per-field even when the raw value is cached
|
# permission gate is re-applied per-field even when the raw value is cached
|
||||||
cached_value = self.optional_filters.get(field_ref, None)
|
cached_value = (
|
||||||
|
self.optional_filters.get(field_ref, None)
|
||||||
|
if self.optional_filters is not None
|
||||||
|
else None
|
||||||
|
)
|
||||||
if cached_value is not None:
|
if cached_value is not None:
|
||||||
return self.check_field_permission(field, cached_value)
|
return self.check_field_permission(field, cached_value)
|
||||||
|
|
||||||
@@ -165,7 +169,7 @@ class FilterableSerializerMixin:
|
|||||||
if InvenTree.ready.isGeneratingSchema():
|
if InvenTree.ready.isGeneratingSchema():
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if value is not None:
|
if value is not None and self.optional_filters is not None:
|
||||||
# Cache the value for future reference
|
# Cache the value for future reference
|
||||||
self.optional_filters[field_ref] = value
|
self.optional_filters[field_ref] = value
|
||||||
|
|
||||||
@@ -316,14 +320,16 @@ class FilterableSerializerMixin:
|
|||||||
field_names = list(super().get_field_names(declared_fields, info))
|
field_names = list(super().get_field_names(declared_fields, info))
|
||||||
|
|
||||||
# Add any optional fields which are included
|
# Add any optional fields which are included
|
||||||
for field_name in self.optional_fields:
|
if _fields := self.optional_fields:
|
||||||
if field_name not in field_names:
|
for field_name in _fields:
|
||||||
field_names.append(field_name)
|
if field_name not in field_names:
|
||||||
|
field_names.append(field_name)
|
||||||
|
|
||||||
# Remove any fields which are marked for removal
|
# Remove any fields which are marked for removal
|
||||||
for field_name in self.fields_to_remove:
|
if _fields := self.fields_to_remove:
|
||||||
if field_name in field_names:
|
for field_name in _fields:
|
||||||
field_names.remove(field_name)
|
if field_name in field_names:
|
||||||
|
field_names.remove(field_name)
|
||||||
|
|
||||||
return field_names
|
return field_names
|
||||||
|
|
||||||
@@ -358,17 +364,19 @@ class FilterableSerializerMixin:
|
|||||||
|
|
||||||
def build_relational_field(self, field_name, relation_info):
|
def build_relational_field(self, field_name, relation_info):
|
||||||
"""Handle a special case where an OptionalField shadows a model relation."""
|
"""Handle a special case where an OptionalField shadows a model relation."""
|
||||||
if field_name in self.optional_fields:
|
if _fields := self.optional_fields:
|
||||||
if field := self.build_optional_field(field_name):
|
if field_name in _fields:
|
||||||
return field
|
if field := self.build_optional_field(field_name):
|
||||||
|
return field
|
||||||
|
|
||||||
return super().build_relational_field(field_name, relation_info)
|
return super().build_relational_field(field_name, relation_info)
|
||||||
|
|
||||||
def build_property_field(self, field_name, model_class):
|
def build_property_field(self, field_name, model_class):
|
||||||
"""Handle a special case where an OptionalField shadows a model property."""
|
"""Handle a special case where an OptionalField shadows a model property."""
|
||||||
if field_name in self.optional_fields:
|
if _fields := self.optional_fields:
|
||||||
if field := self.build_optional_field(field_name):
|
if field_name in _fields:
|
||||||
return field
|
if field := self.build_optional_field(field_name):
|
||||||
|
return field
|
||||||
|
|
||||||
return super().build_property_field(field_name, model_class)
|
return super().build_property_field(field_name, model_class)
|
||||||
|
|
||||||
|
|||||||
@@ -2400,15 +2400,13 @@ class BuildItem(InvenTreeMetadataModel):
|
|||||||
iii) The Part referenced by the StockItem is a valid substitute for the BomItem
|
iii) The Part referenced by the StockItem is a valid substitute for the BomItem
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if self.build.part == self.bom_item.part:
|
if self.build.part == self.bom_item.part or (
|
||||||
|
self.bom_item.inherited
|
||||||
|
and self.build.part
|
||||||
|
in self.bom_item.part.get_descendants(include_self=False)
|
||||||
|
):
|
||||||
valid = self.bom_item.is_stock_item_valid(self.stock_item)
|
valid = self.bom_item.is_stock_item_valid(self.stock_item)
|
||||||
|
|
||||||
elif self.bom_item.inherited:
|
|
||||||
if self.build.part in self.bom_item.part.get_descendants(
|
|
||||||
include_self=False
|
|
||||||
):
|
|
||||||
valid = self.bom_item.is_stock_item_valid(self.stock_item)
|
|
||||||
|
|
||||||
# If the existing BomItem is *not* valid, try to find a match
|
# If the existing BomItem is *not* valid, try to find a match
|
||||||
if not valid and self.build and self.stock_item:
|
if not valid and self.build and self.stock_item:
|
||||||
ancestors = self.stock_item.part.get_ancestors(
|
ancestors = self.stock_item.part.get_ancestors(
|
||||||
|
|||||||
@@ -1830,13 +1830,12 @@ class SalesOrder(AuditedOrderMixin, TotalPriceMixin, Order):
|
|||||||
serials_not_exist.add(serial)
|
serials_not_exist.add(serial)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if get_global_setting('SALESORDER_BLOCK_INCOMPLETE_ITEM_TESTS'):
|
if get_global_setting('SALESORDER_BLOCK_INCOMPLETE_ITEM_TESTS') and (
|
||||||
if (
|
stock_item.hasRequiredTests()
|
||||||
stock_item.hasRequiredTests()
|
and not stock_item.passedAllRequiredTests()
|
||||||
and not stock_item.passedAllRequiredTests()
|
):
|
||||||
):
|
serials_unavailable.add(serial)
|
||||||
serials_unavailable.add(serial)
|
continue
|
||||||
continue
|
|
||||||
|
|
||||||
if not stock_item.in_stock:
|
if not stock_item.in_stock:
|
||||||
serials_unavailable.add(serial)
|
serials_unavailable.add(serial)
|
||||||
@@ -2628,11 +2627,10 @@ class SalesOrderLineItem(AuditedLineItemMixin, OrderLineItem):
|
|||||||
"""
|
"""
|
||||||
super().clean()
|
super().clean()
|
||||||
|
|
||||||
if self.part:
|
if self.part and not self.part.salable:
|
||||||
if not self.part.salable:
|
raise ValidationError({
|
||||||
raise ValidationError({
|
'part': _('Only salable parts can be assigned to a sales order')
|
||||||
'part': _('Only salable parts can be assigned to a sales order')
|
})
|
||||||
})
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""Render a string representation of a SalesOrderLineItem instance."""
|
"""Render a string representation of a SalesOrderLineItem instance."""
|
||||||
|
|||||||
@@ -1813,14 +1813,12 @@ class SalesOrderShipmentAllocationItemSerializer(serializers.Serializer):
|
|||||||
stock_item = data['stock_item']
|
stock_item = data['stock_item']
|
||||||
quantity = data['quantity']
|
quantity = data['quantity']
|
||||||
|
|
||||||
if get_global_setting('SALESORDER_BLOCK_INCOMPLETE_ITEM_TESTS'):
|
if get_global_setting('SALESORDER_BLOCK_INCOMPLETE_ITEM_TESTS') and (
|
||||||
if (
|
stock_item.hasRequiredTests() and not stock_item.passedAllRequiredTests()
|
||||||
stock_item.hasRequiredTests()
|
):
|
||||||
and not stock_item.passedAllRequiredTests()
|
raise ValidationError({
|
||||||
):
|
'stock_item': _('Stock item has not passed all required tests')
|
||||||
raise ValidationError({
|
})
|
||||||
'stock_item': _('Stock item has not passed all required tests')
|
|
||||||
})
|
|
||||||
|
|
||||||
if stock_item.serialized and quantity != 1:
|
if stock_item.serialized and quantity != 1:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
|
|||||||
@@ -685,11 +685,8 @@ class InvenTreePlugin(VersionMixin, MixinBase, MetaBase):
|
|||||||
|
|
||||||
full_path = str(Path(*self.get_static_path(), *file_path, file_name))
|
full_path = str(Path(*self.get_static_path(), *file_path, file_name))
|
||||||
|
|
||||||
if check_exists:
|
if check_exists and not storage.exists(full_path):
|
||||||
if not storage.exists(full_path):
|
logger.error(f"Static file not found for plugin '{self.SLUG}': {full_path}")
|
||||||
logger.error(
|
|
||||||
f"Static file not found for plugin '{self.SLUG}': {full_path}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Resolve the URL to the static file
|
# Resolve the URL to the static file
|
||||||
url = storage.url(full_path)
|
url = storage.url(full_path)
|
||||||
|
|||||||
@@ -951,10 +951,9 @@ class PluginsRegistry:
|
|||||||
package_name = getattr(plugin, 'package_name', None)
|
package_name = getattr(plugin, 'package_name', None)
|
||||||
|
|
||||||
# Auto-enable default builtin plugins
|
# Auto-enable default builtin plugins
|
||||||
if plg_db and plg_db.is_mandatory():
|
if plg_db and plg_db.is_mandatory() and not plg_db.active:
|
||||||
if not plg_db.active:
|
plg_db.active = True
|
||||||
plg_db.active = True
|
plg_db.save()
|
||||||
plg_db.save()
|
|
||||||
|
|
||||||
# Save the package_name attribute to the plugin
|
# Save the package_name attribute to the plugin
|
||||||
if plg_db and plg_db.package_name != package_name:
|
if plg_db and plg_db.package_name != package_name:
|
||||||
|
|||||||
@@ -66,7 +66,11 @@ class BarcodeView(CreateAPIView):
|
|||||||
from common.models import BarcodeScanResult
|
from common.models import BarcodeScanResult
|
||||||
|
|
||||||
# Extract context data from the request
|
# Extract context data from the request
|
||||||
context = {**request.GET.dict(), **request.POST.dict(), **request.data}
|
context: dict[str, str] = {
|
||||||
|
**request.GET.dict(),
|
||||||
|
**request.POST.dict(),
|
||||||
|
**request.data,
|
||||||
|
}
|
||||||
|
|
||||||
barcode = context.pop('barcode', '')
|
barcode = context.pop('barcode', '')
|
||||||
|
|
||||||
@@ -83,12 +87,7 @@ class BarcodeView(CreateAPIView):
|
|||||||
response = str(response)
|
response = str(response)
|
||||||
|
|
||||||
# Ensure that the context data is stringified first, otherwise cannot be JSON encoded
|
# Ensure that the context data is stringified first, otherwise cannot be JSON encoded
|
||||||
if isinstance(context, dict):
|
context = {key: str(value) for key, value in context.items()}
|
||||||
context = {key: str(value) for key, value in context.items()}
|
|
||||||
elif context is None:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
context = str(context)
|
|
||||||
|
|
||||||
# Ensure data is not too long
|
# Ensure data is not too long
|
||||||
if len(barcode) > BarcodeScanResult.BARCODE_SCAN_MAX_LEN:
|
if len(barcode) > BarcodeScanResult.BARCODE_SCAN_MAX_LEN:
|
||||||
|
|||||||
@@ -19,32 +19,30 @@ def get_plugin_urls():
|
|||||||
|
|
||||||
urls = []
|
urls = []
|
||||||
|
|
||||||
if registry.is_ready:
|
if registry.is_ready and (
|
||||||
if (
|
settings.PLUGIN_TESTING_SETUP or get_global_setting('ENABLE_PLUGINS_URL', False)
|
||||||
get_global_setting('ENABLE_PLUGINS_URL', False)
|
):
|
||||||
or settings.PLUGIN_TESTING_SETUP
|
for plugin in registry.with_mixin(PluginMixinEnum.URLS):
|
||||||
):
|
try:
|
||||||
for plugin in registry.with_mixin(PluginMixinEnum.URLS):
|
if plugin_urls := plugin.urlpatterns:
|
||||||
try:
|
# Check if the plugin has a custom URL pattern
|
||||||
if plugin_urls := plugin.urlpatterns:
|
for url in plugin_urls:
|
||||||
# Check if the plugin has a custom URL pattern
|
# Attempt to resolve against the URL pattern as a validation check
|
||||||
for url in plugin_urls:
|
try:
|
||||||
# Attempt to resolve against the URL pattern as a validation check
|
url.resolve('')
|
||||||
try:
|
except Resolver404:
|
||||||
url.resolve('')
|
pass
|
||||||
except Resolver404:
|
|
||||||
pass
|
|
||||||
|
|
||||||
urls.append(
|
urls.append(
|
||||||
re_path(
|
re_path(
|
||||||
f'^{plugin.slug}/',
|
f'^{plugin.slug}/',
|
||||||
include((plugin_urls, plugin.slug)),
|
include((plugin_urls, plugin.slug)),
|
||||||
name=plugin.slug,
|
name=plugin.slug,
|
||||||
)
|
|
||||||
)
|
)
|
||||||
except Exception:
|
)
|
||||||
log_error('get_plugin_urls', plugin=plugin.slug)
|
except Exception:
|
||||||
continue
|
log_error('get_plugin_urls', plugin=plugin.slug)
|
||||||
|
continue
|
||||||
|
|
||||||
# Redirect anything else to the root index
|
# Redirect anything else to the root index
|
||||||
urls.append(
|
urls.append(
|
||||||
|
|||||||
@@ -563,9 +563,8 @@ def part_image(part: Part, preview: bool = False, thumbnail: bool = False, **kwa
|
|||||||
|
|
||||||
image_filename = InvenTree.helpers.image2name(part.image, preview, thumbnail)
|
image_filename = InvenTree.helpers.image2name(part.image, preview, thumbnail)
|
||||||
|
|
||||||
if kwargs.get('check_exists'):
|
if kwargs.get('check_exists') and not media_file_exists(image_filename):
|
||||||
if not media_file_exists(image_filename):
|
raise FileNotFoundError(_('Image file not found') + f": '{image_filename}'")
|
||||||
raise FileNotFoundError(_('Image file not found') + f": '{image_filename}'")
|
|
||||||
|
|
||||||
return uploaded_image(
|
return uploaded_image(
|
||||||
InvenTree.helpers.image2name(part.image, preview, thumbnail), **kwargs
|
InvenTree.helpers.image2name(part.image, preview, thumbnail), **kwargs
|
||||||
|
|||||||
@@ -589,11 +589,12 @@ class StockItem(
|
|||||||
Arguments:
|
Arguments:
|
||||||
ignore_serial_check: If True, allow deletion of serialized stock items regardless of global setting
|
ignore_serial_check: If True, allow deletion of serialized stock items regardless of global setting
|
||||||
"""
|
"""
|
||||||
if not ignore_serial_check and not get_global_setting(
|
if (
|
||||||
'STOCK_ALLOW_DELETE_SERIALIZED', cache=False
|
not ignore_serial_check
|
||||||
|
and not get_global_setting('STOCK_ALLOW_DELETE_SERIALIZED', cache=False)
|
||||||
|
and self.serialized
|
||||||
):
|
):
|
||||||
if self.serialized:
|
raise ValidationError(_('Serialized stock items cannot be deleted'))
|
||||||
raise ValidationError(_('Serialized stock items cannot be deleted'))
|
|
||||||
|
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
# Re-link any child items to the parent of this item,
|
# Re-link any child items to the parent of this item,
|
||||||
|
|||||||
@@ -1971,9 +1971,8 @@ class StockAdjustmentItemSerializer(serializers.Serializer):
|
|||||||
check_status=False, check_quantity=False, check_in_production=False
|
check_status=False, check_quantity=False, check_in_production=False
|
||||||
):
|
):
|
||||||
raise ValidationError(_('Stock item is not in stock'))
|
raise ValidationError(_('Stock item is not in stock'))
|
||||||
elif self.require_in_stock == False:
|
elif self.require_in_stock == False and stock_item.is_in_stock():
|
||||||
if stock_item.is_in_stock():
|
raise ValidationError(_('Stock item is already in stock'))
|
||||||
raise ValidationError(_('Stock item is already in stock'))
|
|
||||||
|
|
||||||
return stock_item
|
return stock_item
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ def safe_value(fnc):
|
|||||||
try:
|
try:
|
||||||
return fnc()
|
return fnc()
|
||||||
except (ModuleNotFoundError, ImportError):
|
except (ModuleNotFoundError, ImportError):
|
||||||
return wrap_color('N/A', 93) # Yellow color for "Not Available"
|
return wrap_color('N/A', '93') # Yellow color for "Not Available"
|
||||||
|
|
||||||
|
|
||||||
def is_true(x):
|
def is_true(x):
|
||||||
|
|||||||
Reference in new issue
Block a user