mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-01 11:10:54 +00:00
refactor: remove blank lines after docstring (#5736)
There shouldn't be any blank lines after the function docstring. Remove the blank lines to fix this issue. Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
This commit is contained in:
@ -150,7 +150,6 @@ class StockItemResource(InvenTreeResource):
|
||||
|
||||
def dehydrate_purchase_price(self, item):
|
||||
"""Render purchase pric as float"""
|
||||
|
||||
if item.purchase_price is not None:
|
||||
return float(item.purchase_price.amount)
|
||||
|
||||
|
@ -234,7 +234,6 @@ class StockLocationFilter(rest_filters.FilterSet):
|
||||
|
||||
def filter_has_location_type(self, queryset, name, value):
|
||||
"""Filter by whether or not the location has a location type"""
|
||||
|
||||
if str2bool(value):
|
||||
return queryset.exclude(location_type=None)
|
||||
else:
|
||||
@ -256,7 +255,6 @@ class StockLocationList(APIDownloadMixin, ListCreateAPI):
|
||||
|
||||
def download_queryset(self, queryset, export_format):
|
||||
"""Download the filtered queryset as a data file"""
|
||||
|
||||
dataset = LocationResource().export(queryset=queryset)
|
||||
filedata = dataset.export(export_format)
|
||||
filename = f"InvenTree_Locations.{export_format}"
|
||||
@ -265,7 +263,6 @@ class StockLocationList(APIDownloadMixin, ListCreateAPI):
|
||||
|
||||
def get_queryset(self, *args, **kwargs):
|
||||
"""Return annotated queryset for the StockLocationList endpoint"""
|
||||
|
||||
queryset = super().get_queryset(*args, **kwargs)
|
||||
queryset = StockSerializers.LocationSerializer.annotate_queryset(queryset)
|
||||
return queryset
|
||||
@ -477,14 +474,12 @@ class StockFilter(rest_filters.FilterSet):
|
||||
|
||||
def filter_status(self, queryset, name, value):
|
||||
"""Filter by integer status code"""
|
||||
|
||||
return queryset.filter(status=value)
|
||||
|
||||
allocated = rest_filters.BooleanFilter(label='Is Allocated', method='filter_allocated')
|
||||
|
||||
def filter_allocated(self, queryset, name, value):
|
||||
"""Filter by whether or not the stock item is 'allocated'"""
|
||||
|
||||
if str2bool(value):
|
||||
# Filter StockItem with either build allocations or sales order allocations
|
||||
return queryset.filter(Q(sales_order_allocations__isnull=False) | Q(allocations__isnull=False))
|
||||
@ -496,7 +491,6 @@ class StockFilter(rest_filters.FilterSet):
|
||||
|
||||
def filter_expired(self, queryset, name, value):
|
||||
"""Filter by whether or not the stock item has expired"""
|
||||
|
||||
if not common.settings.stock_expiry_enabled():
|
||||
return queryset
|
||||
|
||||
@ -509,7 +503,6 @@ class StockFilter(rest_filters.FilterSet):
|
||||
|
||||
def filter_external(self, queryset, name, value):
|
||||
"""Filter by whether or not the stock item is located in an external location"""
|
||||
|
||||
if str2bool(value):
|
||||
return queryset.filter(location__external=True)
|
||||
else:
|
||||
@ -643,7 +636,6 @@ class StockFilter(rest_filters.FilterSet):
|
||||
|
||||
def filter_ancestor(self, queryset, name, ancestor):
|
||||
"""Filter based on ancestor stock item"""
|
||||
|
||||
return queryset.filter(
|
||||
parent__in=ancestor.get_descendants(include_self=True)
|
||||
)
|
||||
@ -1426,7 +1418,6 @@ class LocationDetail(CustomRetrieveUpdateDestroyAPI):
|
||||
|
||||
def get_serializer(self, *args, **kwargs):
|
||||
"""Add extra context to serializer based on provided query parameters"""
|
||||
|
||||
try:
|
||||
params = self.request.query_params
|
||||
|
||||
@ -1440,7 +1431,6 @@ class LocationDetail(CustomRetrieveUpdateDestroyAPI):
|
||||
|
||||
def get_queryset(self, *args, **kwargs):
|
||||
"""Return annotated queryset for the StockLocationList endpoint"""
|
||||
|
||||
queryset = super().get_queryset(*args, **kwargs)
|
||||
queryset = StockSerializers.LocationSerializer.annotate_queryset(queryset)
|
||||
return queryset
|
||||
|
@ -12,7 +12,6 @@ def annotate_location_items(filter: Q = None):
|
||||
- Includes items in subcategories also
|
||||
- Requires subquery to perform annotation
|
||||
"""
|
||||
|
||||
# Construct a subquery to provide all items in this location and any sublocations
|
||||
subquery = stock.models.StockItem.objects.exclude(location=None).filter(
|
||||
location__tree_id=OuterRef('tree_id'),
|
||||
|
@ -310,7 +310,6 @@ def generate_batch_code():
|
||||
Also, this function is exposed to the ValidationMixin plugin class,
|
||||
allowing custom plugins to be used to generate new batch code values
|
||||
"""
|
||||
|
||||
# First, check if any plugins can generate batch codes
|
||||
from plugin.registry import registry
|
||||
|
||||
@ -346,7 +345,6 @@ def default_delete_on_deplete():
|
||||
Prior to 2022-12-24, this field was set to True by default.
|
||||
Now, there is a user-configurable setting to govern default behaviour.
|
||||
"""
|
||||
|
||||
try:
|
||||
return common.models.InvenTreeSetting.get_setting('STOCK_DELETE_DEPLETED_DEFAULT', True)
|
||||
except (IntegrityError, OperationalError):
|
||||
@ -416,7 +414,6 @@ class StockItem(InvenTreeBarcodeMixin, InvenTreeNotesMixin, MetadataMixin, commo
|
||||
|
||||
This is used for efficient numerical sorting
|
||||
"""
|
||||
|
||||
serial = str(getattr(self, 'serial', '')).strip()
|
||||
|
||||
from plugin.registry import registry
|
||||
@ -505,7 +502,6 @@ class StockItem(InvenTreeBarcodeMixin, InvenTreeNotesMixin, MetadataMixin, commo
|
||||
- Unique serial number requirement
|
||||
- Adds a transaction note when the item is first created.
|
||||
"""
|
||||
|
||||
self.validate_unique()
|
||||
self.clean()
|
||||
|
||||
@ -601,7 +597,6 @@ class StockItem(InvenTreeBarcodeMixin, InvenTreeNotesMixin, MetadataMixin, commo
|
||||
- Validation is performed by custom plugins.
|
||||
- By default, no validation checks are performed
|
||||
"""
|
||||
|
||||
from plugin.registry import registry
|
||||
|
||||
for plugin in registry.with_mixin('validation'):
|
||||
@ -622,7 +617,6 @@ class StockItem(InvenTreeBarcodeMixin, InvenTreeNotesMixin, MetadataMixin, commo
|
||||
- The location is not structural
|
||||
- Quantity must be 1 if the StockItem has a serial number
|
||||
"""
|
||||
|
||||
if self.location is not None and self.location.structural:
|
||||
raise ValidationError(
|
||||
{'location': _("Stock items cannot be located into structural stock locations!")})
|
||||
@ -1167,7 +1161,6 @@ class StockItem(InvenTreeBarcodeMixin, InvenTreeNotesMixin, MetadataMixin, commo
|
||||
|
||||
def sales_order_allocation_count(self, active=True):
|
||||
"""Return the total quantity allocated to SalesOrders."""
|
||||
|
||||
query = self.get_sales_order_allocations(active=active)
|
||||
query = query.aggregate(q=Coalesce(Sum('quantity'), Decimal(0)))
|
||||
|
||||
|
@ -225,7 +225,6 @@ class StockItemSerializer(InvenTree.serializers.InvenTreeTagModelSerializer):
|
||||
|
||||
def validate_part(self, part):
|
||||
"""Ensure the provided Part instance is valid"""
|
||||
|
||||
if part.virtual:
|
||||
raise ValidationError(_("Stock item cannot be created for virtual parts"))
|
||||
|
||||
@ -240,7 +239,6 @@ class StockItemSerializer(InvenTree.serializers.InvenTreeTagModelSerializer):
|
||||
@staticmethod
|
||||
def annotate_queryset(queryset):
|
||||
"""Add some extra annotations to the queryset, performing database queries as efficiently as possible."""
|
||||
|
||||
queryset = queryset.prefetch_related(
|
||||
'location',
|
||||
'sales_order',
|
||||
@ -591,7 +589,6 @@ class ConvertStockItemSerializer(serializers.Serializer):
|
||||
|
||||
def validate_part(self, part):
|
||||
"""Ensure that the provided part is a valid option for the stock item"""
|
||||
|
||||
stock_item = self.context['item']
|
||||
valid_options = stock_item.part.get_conversion_options()
|
||||
|
||||
@ -605,7 +602,6 @@ class ConvertStockItemSerializer(serializers.Serializer):
|
||||
|
||||
- If a SupplierPart is assigned, we cannot convert!
|
||||
"""
|
||||
|
||||
data = super().validate(data)
|
||||
|
||||
stock_item = self.context['item']
|
||||
@ -653,7 +649,6 @@ class ReturnStockItemSerializer(serializers.Serializer):
|
||||
|
||||
def save(self):
|
||||
"""Save the serialzier to return the item into stock"""
|
||||
|
||||
item = self.context['item']
|
||||
request = self.context['request']
|
||||
|
||||
@ -691,7 +686,6 @@ class StockChangeStatusSerializer(serializers.Serializer):
|
||||
|
||||
def validate_items(self, items):
|
||||
"""Validate the selected stock items"""
|
||||
|
||||
if len(items) == 0:
|
||||
raise ValidationError(_("No stock items selected"))
|
||||
|
||||
@ -712,7 +706,6 @@ class StockChangeStatusSerializer(serializers.Serializer):
|
||||
@transaction.atomic
|
||||
def save(self):
|
||||
"""Save the serializer to change the status of the selected stock items"""
|
||||
|
||||
data = self.validated_data
|
||||
|
||||
items = data['items']
|
||||
@ -787,7 +780,6 @@ class StockLocationTypeSerializer(InvenTree.serializers.InvenTreeModelSerializer
|
||||
@staticmethod
|
||||
def annotate_queryset(queryset):
|
||||
"""Add location count to each location type."""
|
||||
|
||||
return queryset.annotate(
|
||||
location_count=Count("stock_locations")
|
||||
)
|
||||
@ -844,7 +836,6 @@ class LocationSerializer(InvenTree.serializers.InvenTreeTagModelSerializer):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Optionally add or remove extra fields"""
|
||||
|
||||
path_detail = kwargs.pop('path_detail', False)
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
@ -855,7 +846,6 @@ class LocationSerializer(InvenTree.serializers.InvenTreeTagModelSerializer):
|
||||
@staticmethod
|
||||
def annotate_queryset(queryset):
|
||||
"""Annotate extra information to the queryset"""
|
||||
|
||||
# Annotate the number of stock items which exist in this category (including subcategories)
|
||||
queryset = queryset.annotate(
|
||||
items=stock.filters.annotate_location_items()
|
||||
|
@ -240,7 +240,6 @@ class StockLocationTest(StockAPITestCase):
|
||||
- Stock items cannot be located to structural locations
|
||||
- Check that stock location change to structural fails if items located into it
|
||||
"""
|
||||
|
||||
# Create our structural stock location
|
||||
structural_location = StockLocation.objects.create(
|
||||
name='Structural stock location',
|
||||
@ -348,7 +347,6 @@ class StockLocationTypeTest(StockAPITestCase):
|
||||
|
||||
def test_list(self):
|
||||
"""Test that the list endpoint works as expected."""
|
||||
|
||||
location_types = [
|
||||
StockLocationType.objects.create(name="Type 1", description="Type 1 desc", icon="fas fa-box"),
|
||||
StockLocationType.objects.create(name="Type 2", description="Type 2 desc", icon="fas fa-box"),
|
||||
@ -397,7 +395,6 @@ class StockItemListTest(StockAPITestCase):
|
||||
|
||||
def test_top_level_filtering(self):
|
||||
"""Test filtering against "top level" stock location"""
|
||||
|
||||
# No filters, should return *all* items
|
||||
response = self.get(self.list_url, {}, expected_code=200)
|
||||
self.assertEqual(len(response.data), StockItem.objects.count())
|
||||
@ -789,7 +786,6 @@ class StockItemTest(StockAPITestCase):
|
||||
|
||||
def test_stock_item_create_withsupplierpart(self):
|
||||
"""Test creation of a StockItem via the API, including SupplierPart data."""
|
||||
|
||||
# POST with non-existent supplier part
|
||||
response = self.post(
|
||||
self.list_url,
|
||||
@ -1140,7 +1136,6 @@ class StockItemTest(StockAPITestCase):
|
||||
|
||||
def test_return_from_customer(self):
|
||||
"""Test that we can return a StockItem from a customer, via the API"""
|
||||
|
||||
# Assign item to customer
|
||||
item = StockItem.objects.get(pk=521)
|
||||
customer = company.models.Company.objects.get(pk=4)
|
||||
@ -1179,7 +1174,6 @@ class StockItemTest(StockAPITestCase):
|
||||
|
||||
def test_convert_to_variant(self):
|
||||
"""Test that we can convert a StockItem to a variant part via the API"""
|
||||
|
||||
category = part.models.PartCategory.objects.get(pk=3)
|
||||
|
||||
# First, construct a set of template / variant parts
|
||||
@ -1242,7 +1236,6 @@ class StockItemTest(StockAPITestCase):
|
||||
|
||||
def test_set_status(self):
|
||||
"""Test API endpoint for setting StockItem status"""
|
||||
|
||||
url = reverse('api-stock-change-status')
|
||||
|
||||
prt = Part.objects.first()
|
||||
@ -1512,7 +1505,6 @@ class StockTestResultTest(StockAPITestCase):
|
||||
|
||||
def test_bulk_delete(self):
|
||||
"""Test that the BulkDelete endpoint works for this model"""
|
||||
|
||||
n = StockItemTestResult.objects.count()
|
||||
|
||||
tests = []
|
||||
@ -1687,7 +1679,6 @@ class StockMergeTest(StockAPITestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
"""Setup for all tests."""
|
||||
|
||||
super().setUpTestData()
|
||||
|
||||
cls.part = part.models.Part.objects.get(pk=25)
|
||||
@ -1877,7 +1868,6 @@ class StockMetadataAPITest(InvenTreeAPITestCase):
|
||||
|
||||
def metatester(self, apikey, model):
|
||||
"""Generic tester"""
|
||||
|
||||
modeldata = model.objects.first()
|
||||
|
||||
# Useless test unless a model object is found
|
||||
@ -1906,7 +1896,6 @@ class StockMetadataAPITest(InvenTreeAPITestCase):
|
||||
|
||||
def test_metadata(self):
|
||||
"""Test all endpoints"""
|
||||
|
||||
for apikey, model in {
|
||||
'api-location-metadata': StockLocation,
|
||||
'api-stock-test-result-metadata': StockItemTestResult,
|
||||
|
@ -13,7 +13,6 @@ class TestSerialNumberMigration(MigratorTestCase):
|
||||
|
||||
def prepare(self):
|
||||
"""Create initial data for this migration"""
|
||||
|
||||
Part = self.old_state.apps.get_model('part', 'part')
|
||||
StockItem = self.old_state.apps.get_model('stock', 'stockitem')
|
||||
|
||||
@ -53,7 +52,6 @@ class TestSerialNumberMigration(MigratorTestCase):
|
||||
|
||||
def test_migrations(self):
|
||||
"""Test that the migrations have been applied correctly"""
|
||||
|
||||
StockItem = self.new_state.apps.get_model('stock', 'stockitem')
|
||||
|
||||
# Check that the serial number integer conversion has been applied correctly
|
||||
@ -77,7 +75,6 @@ class TestScheduledForDeletionMigration(MigratorTestCase):
|
||||
|
||||
def prepare(self):
|
||||
"""Create some initial stock items"""
|
||||
|
||||
Part = self.old_state.apps.get_model('part', 'part')
|
||||
StockItem = self.old_state.apps.get_model('stock', 'stockitem')
|
||||
|
||||
@ -124,7 +121,6 @@ class TestScheduledForDeletionMigration(MigratorTestCase):
|
||||
|
||||
def test_migration(self):
|
||||
"""Test that all stock items were actually removed"""
|
||||
|
||||
StockItem = self.new_state.apps.get_model('stock', 'stockitem')
|
||||
|
||||
# All the "scheduled for deletion" items have been removed
|
||||
|
@ -39,7 +39,6 @@ class StockDetailTest(StockViewTestCase):
|
||||
|
||||
def test_basic_info(self):
|
||||
"""Test that basic stock item info is rendered"""
|
||||
|
||||
url = reverse('stock-item-detail', kwargs={'pk': 1})
|
||||
|
||||
response = self.client.get(url)
|
||||
|
@ -55,7 +55,6 @@ class StockTest(StockTestBase):
|
||||
|
||||
def test_pathstring(self):
|
||||
"""Check that pathstring updates occur as expected"""
|
||||
|
||||
a = StockLocation.objects.create(name="A")
|
||||
b = StockLocation.objects.create(name="B", parent=a)
|
||||
c = StockLocation.objects.create(name="C", parent=b)
|
||||
@ -131,7 +130,6 @@ class StockTest(StockTestBase):
|
||||
|
||||
def test_link(self):
|
||||
"""Test the link URL field validation"""
|
||||
|
||||
item = StockItem.objects.get(pk=1)
|
||||
|
||||
# Check that invalid URLs fail
|
||||
@ -178,7 +176,6 @@ class StockTest(StockTestBase):
|
||||
|
||||
def test_serial_numbers(self):
|
||||
"""Test serial number uniqueness"""
|
||||
|
||||
# Ensure that 'global uniqueness' setting is enabled
|
||||
InvenTreeSetting.set_setting('SERIAL_NUMBER_GLOBALLY_UNIQUE', True, self.user)
|
||||
|
||||
@ -284,7 +281,6 @@ class StockTest(StockTestBase):
|
||||
|
||||
def test_parent_locations(self):
|
||||
"""Test parent."""
|
||||
|
||||
# Ensure pathstring gets updated
|
||||
self.drawer3.save()
|
||||
|
||||
@ -318,7 +314,6 @@ class StockTest(StockTestBase):
|
||||
|
||||
def test_items(self):
|
||||
"""Test has_items."""
|
||||
|
||||
# Drawer 3 should have three stock items
|
||||
self.assertEqual(self.drawer3.stock_items.count(), 18)
|
||||
self.assertEqual(self.drawer3.item_count, 18)
|
||||
@ -495,7 +490,6 @@ class StockTest(StockTestBase):
|
||||
|
||||
def test_return_from_customer(self):
|
||||
"""Test removing previous allocated stock from customer"""
|
||||
|
||||
it = StockItem.objects.get(pk=2)
|
||||
|
||||
# First establish total stock for this part
|
||||
@ -940,7 +934,6 @@ class StockBarcodeTest(StockTestBase):
|
||||
|
||||
def test_stock_item_barcode_basics(self):
|
||||
"""Simple tests for the StockItem barcode integration"""
|
||||
|
||||
item = StockItem.objects.get(pk=1)
|
||||
|
||||
self.assertEqual(StockItem.barcode_model_type(), 'stockitem')
|
||||
@ -957,7 +950,6 @@ class StockBarcodeTest(StockTestBase):
|
||||
|
||||
def test_location_barcode_basics(self):
|
||||
"""Simple tests for the StockLocation barcode integration"""
|
||||
|
||||
self.assertEqual(StockLocation.barcode_model_type(), 'stocklocation')
|
||||
|
||||
loc = StockLocation.objects.get(pk=1)
|
||||
@ -985,7 +977,6 @@ class VariantTest(StockTestBase):
|
||||
|
||||
def test_serial_numbers(self):
|
||||
"""Test serial number functionality for variant / template parts."""
|
||||
|
||||
InvenTreeSetting.set_setting('SERIAL_NUMBER_GLOBALLY_UNIQUE', False, self.user)
|
||||
|
||||
chair = Part.objects.get(pk=10000)
|
||||
|
Reference in New Issue
Block a user