code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def save(self):
"""Save the serializer to complete the build outputs."""
build = self.context['build']
request = self.context.get('request')
data = self.validated_data
location = data.get('location', None)
status = data.get('status_custom_key', StockStatus.OK.value)
... | Save the serializer to complete the build outputs. | save | python | inventree/InvenTree | src/backend/InvenTree/build/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/serializers.py | MIT |
def get_context_data(self):
"""Retrieve extra context data from this serializer."""
build = self.context['build']
return {
'has_allocated_stock': build.is_partially_allocated(),
'incomplete_outputs': build.incomplete_count,
'completed_outputs': build.complete... | Retrieve extra context data from this serializer. | get_context_data | python | inventree/InvenTree | src/backend/InvenTree/build/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/serializers.py | MIT |
def get_context_data(self):
"""Retrieve extra context data for this serializer.
This is so we can determine (at run time) whether the build is ready to be completed.
"""
build = self.context['build']
return {
'overallocated': build.is_overallocated(),
'a... | Retrieve extra context data for this serializer.
This is so we can determine (at run time) whether the build is ready to be completed.
| get_context_data | python | inventree/InvenTree | src/backend/InvenTree/build/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/serializers.py | MIT |
def validate_accept_overallocated(self, value):
"""Check if the 'accept_overallocated' field is required."""
build = self.context['build']
if build.is_overallocated() and value == OverallocationChoice.REJECT:
raise ValidationError(_('Some stock items have been overallocated'))
... | Check if the 'accept_overallocated' field is required. | validate_accept_overallocated | python | inventree/InvenTree | src/backend/InvenTree/build/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/serializers.py | MIT |
def validate_accept_unallocated(self, value):
"""Check if the 'accept_unallocated' field is required."""
build = self.context['build']
if not build.are_untracked_parts_allocated and not value:
raise ValidationError(_('Required stock has not been fully allocated'))
return va... | Check if the 'accept_unallocated' field is required. | validate_accept_unallocated | python | inventree/InvenTree | src/backend/InvenTree/build/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/serializers.py | MIT |
def validate_accept_incomplete(self, value):
"""Check if the 'accept_incomplete' field is required."""
build = self.context['build']
if build.remaining > 0 and not value:
raise ValidationError(_('Required build quantity has not been completed'))
return value | Check if the 'accept_incomplete' field is required. | validate_accept_incomplete | python | inventree/InvenTree | src/backend/InvenTree/build/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/serializers.py | MIT |
def validate(self, data):
"""Perform validation of this serializer prior to saving."""
build = self.context['build']
if (
get_global_setting('BUILDORDER_REQUIRE_CLOSED_CHILDS')
and build.has_open_child_builds
):
raise ValidationError(_('Build order ha... | Perform validation of this serializer prior to saving. | validate | python | inventree/InvenTree | src/backend/InvenTree/build/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/serializers.py | MIT |
def validate_output(self, stock_item):
"""Validation for the output StockItem instance. Stock item must point to the same build order!"""
build = self.context['build']
if stock_item and stock_item.build != build:
raise ValidationError(_('Build output must point to the same build'))
... | Validation for the output StockItem instance. Stock item must point to the same build order! | validate_output | python | inventree/InvenTree | src/backend/InvenTree/build/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/serializers.py | MIT |
def save(self):
"""Save the serializer data.
This performs the actual unallocation against the build order
"""
build = self.context['build']
data = self.validated_data
build.deallocate_stock(
build_line=data.get('build_line', None), output=data.get('output'... | Save the serializer data.
This performs the actual unallocation against the build order
| save | python | inventree/InvenTree | src/backend/InvenTree/build/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/serializers.py | MIT |
def validate_quantity(self, quantity):
"""Perform validation of the 'quantity' field."""
if quantity <= 0:
raise ValidationError(_('Quantity must be greater than zero'))
return quantity | Perform validation of the 'quantity' field. | validate_quantity | python | inventree/InvenTree | src/backend/InvenTree/build/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/serializers.py | MIT |
def validate(self, data):
"""Perform data validation for this item."""
super().validate(data)
build_line = data['build_line']
stock_item = data['stock_item']
quantity = data['quantity']
output = data.get('output', None)
# build = self.context['build']
#... | Perform data validation for this item. | validate | python | inventree/InvenTree | src/backend/InvenTree/build/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/serializers.py | MIT |
def __init__(self, *args, **kwargs):
"""Determine which extra details fields should be included."""
part_detail = kwargs.pop('part_detail', True)
location_detail = kwargs.pop('location_detail', True)
stock_detail = kwargs.pop('stock_detail', True)
build_detail = kwargs.pop('build... | Determine which extra details fields should be included. | __init__ | python | inventree/InvenTree | src/backend/InvenTree/build/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/serializers.py | MIT |
def annotate_queryset(queryset, build=None):
"""Add extra annotations to the queryset.
Annotations:
- allocated: Total stock quantity allocated against this build line
- available: Total stock available for allocation against this build line
- on_order: Total stock on order for ... | Add extra annotations to the queryset.
Annotations:
- allocated: Total stock quantity allocated against this build line
- available: Total stock available for allocation against this build line
- on_order: Total stock on order for this build line
- in_production: Total stock cur... | annotate_queryset | python | inventree/InvenTree | src/backend/InvenTree/build/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/serializers.py | MIT |
def auto_allocate_build(build_id: int, **kwargs):
"""Run auto-allocation for a specified BuildOrder."""
build_order = build_models.Build.objects.filter(pk=build_id).first()
if not build_order:
logger.warning(
'Could not auto-allocate BuildOrder <%s> - BuildOrder does not exist',
... | Run auto-allocation for a specified BuildOrder. | auto_allocate_build | python | inventree/InvenTree | src/backend/InvenTree/build/tasks.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/tasks.py | MIT |
def complete_build_allocations(build_id: int, user_id: int):
"""Complete build allocations for a specified BuildOrder."""
build_order = build_models.Build.objects.filter(pk=build_id).first()
if user_id:
try:
user = User.objects.get(pk=user_id)
except User.DoesNotExist:
... | Complete build allocations for a specified BuildOrder. | complete_build_allocations | python | inventree/InvenTree | src/backend/InvenTree/build/tasks.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/tasks.py | MIT |
def check_build_stock(build: build_models.Build):
"""Check the required stock for a newly created build order.
Send an email out to any subscribed users if stock is low.
"""
# Do not notify if we are importing data
if isImportingData():
return
# Iterate through each of the parts requir... | Check the required stock for a newly created build order.
Send an email out to any subscribed users if stock is low.
| check_build_stock | python | inventree/InvenTree | src/backend/InvenTree/build/tasks.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/tasks.py | MIT |
def create_child_builds(build_id: int) -> None:
"""Create child build orders for a given parent build.
- Will create a build order for each assembly part in the BOM
- Runs recursively, also creating child builds for each sub-assembly part
"""
try:
build_order = build_models.Build.objects.ge... | Create child build orders for a given parent build.
- Will create a build order for each assembly part in the BOM
- Runs recursively, also creating child builds for each sub-assembly part
| create_child_builds | python | inventree/InvenTree | src/backend/InvenTree/build/tasks.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/tasks.py | MIT |
def notify_overdue_build_order(bo: build_models.Build):
"""Notify appropriate users that a Build has just become 'overdue'."""
targets = []
if bo.issued_by:
targets.append(bo.issued_by)
if bo.responsible:
targets.append(bo.responsible)
targets.extend(bo.part.get_subscribers())
... | Notify appropriate users that a Build has just become 'overdue'. | notify_overdue_build_order | python | inventree/InvenTree | src/backend/InvenTree/build/tasks.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/tasks.py | MIT |
def check_overdue_build_orders():
"""Check if any outstanding BuildOrders have just become overdue.
- This check is performed daily
- Look at the 'target_date' of any outstanding BuildOrder objects
- If the 'target_date' expired *yesterday* then the order is just out of date
"""
yesterday = Inv... | Check if any outstanding BuildOrders have just become overdue.
- This check is performed daily
- Look at the 'target_date' of any outstanding BuildOrder objects
- If the 'target_date' expired *yesterday* then the order is just out of date
| check_overdue_build_orders | python | inventree/InvenTree | src/backend/InvenTree/build/tasks.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/tasks.py | MIT |
def test_build_objects(self):
"""Ensure the Build objects were correctly created."""
self.assertEqual(Build.objects.count(), 5)
b = Build.objects.get(pk=2)
self.assertEqual(b.batch, 'B2')
self.assertEqual(b.quantity, 21)
self.assertEqual(str(b), 'BO-0002') | Ensure the Build objects were correctly created. | test_build_objects | python | inventree/InvenTree | src/backend/InvenTree/build/tests.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/tests.py | MIT |
def test_build_create(self):
"""Test creation of build orders via API."""
n = Build.objects.count()
# Find an assembly part
assembly = Part.objects.filter(assembly=True).first()
assembly.active = True
assembly.locked = False
assembly.save()
self.assertE... | Test creation of build orders via API. | test_build_create | python | inventree/InvenTree | src/backend/InvenTree/build/tests.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/tests.py | MIT |
def test_get_build_list(self):
"""Test that we can retrieve list of build objects."""
url = reverse('api-build-list')
response = self.get(url, expected_code=200)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(len(response.data), 5)
# Filter... | Test that we can retrieve list of build objects. | test_get_build_list | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_get_build_item_list(self):
"""Test that we can retrieve list of BuildItem objects."""
url = reverse('api-build-item-list')
response = self.get(url, expected_code=200)
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Test again, filtering by park ID
... | Test that we can retrieve list of BuildItem objects. | test_get_build_item_list | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def setUp(self):
"""Basic setup for this test suite."""
super().setUp()
self.build = Build.objects.get(pk=1)
self.url = reverse('api-build-output-complete', kwargs={'pk': self.build.pk}) | Basic setup for this test suite. | setUp | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_cancel(self):
"""Test that we can cancel a BuildOrder via the API.
- First test that all stock is returned to stock
- Second test that stock is consumed by the build order
"""
def make_new_build(ref):
"""Make a new build order, and allocate stock to it."""
... | Test that we can cancel a BuildOrder via the API.
- First test that all stock is returned to stock
- Second test that stock is consumed by the build order
| test_cancel | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def make_new_build(ref):
"""Make a new build order, and allocate stock to it."""
data = self.post(
reverse('api-build-list'),
{'part': 100, 'quantity': 10, 'title': 'Test build', 'reference': ref},
expected_code=201,
).data
... | Make a new build order, and allocate stock to it. | make_new_build | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_delete(self):
"""Test that we can delete a BuildOrder via the API."""
bo = Build.objects.get(pk=1)
url = reverse('api-build-detail', kwargs={'pk': bo.pk})
# At first we do not have the required permissions
self.delete(url, expected_code=403)
self.assignRole('b... | Test that we can delete a BuildOrder via the API. | test_delete | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_create_delete_output(self):
"""Test that we can create and delete build outputs via the API."""
bo = Build.objects.get(pk=1)
n_outputs = bo.output_count
create_url = reverse('api-build-output-create', kwargs={'pk': 1})
# Attempt to create outputs with invalid data
... | Test that we can create and delete build outputs via the API. | test_create_delete_output | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_download_build_orders(self):
"""Test that we can download a list of build orders via the API."""
required_cols = [
'Reference',
'Build Status',
'Completed items',
'Batch Code',
'Description',
'Part',
'Part Name'... | Test that we can download a list of build orders via the API. | test_download_build_orders | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_create(self):
"""Test creation of new build orders via the API."""
url = reverse('api-build-list')
# First, we'll create a tree of part assemblies
part_a = Part.objects.create(
name='Part A', description='Part A description', assembly=True
)
part_b =... | Test creation of new build orders via the API. | test_create | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def setUp(self):
"""Basic operation as part of test suite setup."""
super().setUp()
self.assignRole('build.add')
self.assignRole('build.change')
self.url = reverse('api-build-allocate', kwargs={'pk': 1})
self.build = Build.objects.get(pk=1)
# Regenerate BuildL... | Basic operation as part of test suite setup. | setUp | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_build_data(self):
"""Check that our assumptions about the particular BuildOrder are correct."""
self.assertEqual(self.build.part.pk, 100)
# There should be 4x BOM items we can use
self.assertEqual(self.build.part.bom_items.count(), 4)
# No items yet allocated to this b... | Check that our assumptions about the particular BuildOrder are correct. | test_build_data | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_options(self):
"""An OPTIONS request to the endpoint should return information about the endpoint."""
response = self.options(self.url, expected_code=200)
self.assertIn(
'API endpoint to allocate stock items to a build order', str(response.data)
) | An OPTIONS request to the endpoint should return information about the endpoint. | test_options | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_invalid_bom_item(self):
"""Test by passing an invalid BOM item."""
# Find the right (in this case, wrong) BuildLine instance
si = StockItem.objects.get(pk=11)
lines = self.build.build_lines.all()
wrong_line = None
for line in lines:
if line.bom_item... | Test by passing an invalid BOM item. | test_invalid_bom_item | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_valid_data(self):
"""Test with valid data.
This should result in creation of a new BuildItem object
"""
# Find the correct BuildLine
si = StockItem.objects.get(pk=2)
right_line = None
for line in self.build.build_lines.all():
if line.bom_it... | Test with valid data.
This should result in creation of a new BuildItem object
| test_valid_data | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_reallocate(self):
"""Test reallocating an existing built item with the same stock item.
This should increment the quantity of the existing BuildItem object
"""
# Find the correct BuildLine
si = StockItem.objects.get(pk=2)
right_line = None
for line in s... | Test reallocating an existing built item with the same stock item.
This should increment the quantity of the existing BuildItem object
| test_reallocate | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_fractional_allocation(self):
"""Test allocation of a fractional quantity of stock items.
Ref: https://github.com/inventree/InvenTree/issues/6508
"""
si = StockItem.objects.get(pk=2)
# Find line item
line = self.build.build_lines.all().filter(bom_item__sub_part=... | Test allocation of a fractional quantity of stock items.
Ref: https://github.com/inventree/InvenTree/issues/6508
| test_fractional_allocation | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_update_overallocated(self):
"""Test update of overallocated stock items."""
si = StockItem.objects.get(pk=2)
# Find line item
line = self.build.build_lines.all().filter(bom_item__sub_part=si.part).first()
# Set initial stock item quantity
si.quantity = 100
... | Test update of overallocated stock items. | test_update_overallocated | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_setup(self):
"""Validate expected state after set-up."""
self.assertEqual(self.build.incomplete_outputs.count(), 0)
self.assertEqual(self.build.complete_outputs.count(), 1)
self.assertEqual(self.build.completed, self.build.quantity) | Validate expected state after set-up. | test_setup | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_overallocated_requires_acceptance(self):
"""Test build order cannot complete with overallocated items."""
# Try to complete the build (it should fail due to overallocation)
response = self.post(self.url, {}, expected_code=400)
self.assertIn('accept_overallocated', response.data)... | Test build order cannot complete with overallocated items. | test_overallocated_requires_acceptance | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_overallocated_can_trim(self):
"""Test build order will trim/de-allocate overallocated stock when requested."""
self.post(
self.url,
{'accept_overallocated': 'trim'},
expected_code=201,
max_query_count=1000, # TODO: Come back and refactor this
... | Test build order will trim/de-allocate overallocated stock when requested. | test_overallocated_can_trim | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_get_all_builds(self):
"""Retrieve *all* builds via the API."""
builds = self.get(self.url)
self.assertEqual(len(builds.data), 5)
builds = self.get(self.url, data={'active': True})
self.assertEqual(len(builds.data), 1)
builds = self.get(self.url, data={'status'... | Retrieve *all* builds via the API. | test_get_all_builds | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_overdue(self):
"""Create a new build, in the past."""
in_the_past = datetime.now().date() - timedelta(days=50)
part = Part.objects.get(pk=50)
Build.objects.create(
part=part,
reference='BO-0006',
quantity=10,
title='Just some thi... | Create a new build, in the past. | test_overdue | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_sub_builds(self):
"""Test the build / sub-build relationship."""
parent = Build.objects.get(pk=5)
part = Part.objects.get(pk=50)
n = Build.objects.count()
# Make some sub builds
for i in range(5):
Build.objects.create(
part=part,
... | Test the build / sub-build relationship. | test_sub_builds | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_create_serialized_output(self):
"""Create a serialized build output via the API."""
build_id = 1
url = reverse('api-build-output-create', kwargs={'pk': build_id})
build = Build.objects.get(pk=build_id)
part = build.part
n_outputs = build.output_count
n... | Create a serialized build output via the API. | test_create_serialized_output | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_create_unserialized_output(self):
"""Create an unserialized build output via the API."""
build_id = 1
url = reverse('api-build-output-create', kwargs={'pk': build_id})
build = Build.objects.get(pk=build_id)
part = build.part
n_outputs = build.output_count
... | Create an unserialized build output via the API. | test_create_unserialized_output | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def scrap(self, build_id, data, expected_code=None):
"""Helper method to POST to the scrap API."""
url = reverse('api-build-output-scrap', kwargs={'pk': build_id})
response = self.post(url, data, expected_code=expected_code)
return response.data | Helper method to POST to the scrap API. | scrap | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_invalid_scraps(self):
"""Test that invalid scrap attempts are rejected."""
# Test with missing required fields
response = self.scrap(1, {}, expected_code=400)
for field in ['outputs', 'location', 'notes']:
self.assertIn('This field is required', str(response[field])... | Test that invalid scrap attempts are rejected. | test_invalid_scraps | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_valid_scraps(self):
"""Test that valid scrap attempts succeed."""
# Create a build output
build = Build.objects.get(pk=1)
for _ in range(3):
build.create_build_output(2)
outputs = build.build_outputs.all()
self.assertEqual(outputs.count(), 3)
... | Test that valid scrap attempts succeed. | test_valid_scraps | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def test_filter_available(self):
"""Filter BuildLine objects by 'available' status."""
url = reverse('api-build-line-list')
# First *all* BuildLine objects
response = self.get(url)
self.assertEqual(len(response.data), BuildLine.objects.count())
# Filter by 'available' s... | Filter BuildLine objects by 'available' status. | test_filter_available | python | inventree/InvenTree | src/backend/InvenTree/build/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_api.py | MIT |
def setUpTestData(cls):
"""Initialize data to use for these tests.
The base Part 'assembly' has a BOM consisting of three parts:
- 5 x sub_part_1
- 3 x sub_part_2
- 2 x sub_part_3 (trackable)
We will build 10x 'assembly' parts, in two build outputs:
- 3 x outp... | Initialize data to use for these tests.
The base Part 'assembly' has a BOM consisting of three parts:
- 5 x sub_part_1
- 3 x sub_part_2
- 2 x sub_part_3 (trackable)
We will build 10x 'assembly' parts, in two build outputs:
- 3 x output_1
- 7 x output_2
... | setUpTestData | python | inventree/InvenTree | src/backend/InvenTree/build/test_build.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_build.py | MIT |
def test_ref_int(self):
"""Test the "integer reference" field used for natural sorting."""
# Set build reference to new value
set_global_setting(
'BUILDORDER_REFERENCE_PATTERN', 'BO-{ref}-???', change_user=None
)
refs = {
'BO-123-456': 123,
'B... | Test the "integer reference" field used for natural sorting. | test_ref_int | python | inventree/InvenTree | src/backend/InvenTree/build/test_build.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_build.py | MIT |
def test_ref_validation(self):
"""Test that the reference field validation works as expected."""
# Default reference pattern = 'BO-{ref:04d}
# These patterns should fail
for ref in ['BO-1234x', 'BO1234', 'OB-1234', 'BO--1234']:
with self.assertRaises(ValidationError):
... | Test that the reference field validation works as expected. | test_ref_validation | python | inventree/InvenTree | src/backend/InvenTree/build/test_build.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_build.py | MIT |
def test_next_ref(self):
"""Test that the next reference is automatically generated."""
set_global_setting(
'BUILDORDER_REFERENCE_PATTERN', 'XYZ-{ref:06d}', change_user=None
)
build = Build.objects.create(
part=self.assembly, quantity=5, reference='XYZ-987', titl... | Test that the next reference is automatically generated. | test_next_ref | python | inventree/InvenTree | src/backend/InvenTree/build/test_build.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_build.py | MIT |
def test_init(self):
"""Perform some basic tests before we start the ball rolling."""
self.assertEqual(StockItem.objects.count(), 12)
# Build is PENDING
self.assertEqual(self.build.status, status.BuildStatus.PENDING)
self.assertTrue(self.build.is_active)
self.assertTrue... | Perform some basic tests before we start the ball rolling. | test_init | python | inventree/InvenTree | src/backend/InvenTree/build/test_build.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_build.py | MIT |
def test_build_item_clean(self):
"""Ensure that dodgy BuildItem objects cannot be created."""
stock = StockItem.objects.create(part=self.assembly, quantity=99)
# Create a BuiltItem which points to an invalid StockItem
b = BuildItem(stock_item=stock, build_line=self.line_2, quantity=10)
... | Ensure that dodgy BuildItem objects cannot be created. | test_build_item_clean | python | inventree/InvenTree | src/backend/InvenTree/build/test_build.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_build.py | MIT |
def test_duplicate_bom_line(self):
"""Try to add a duplicate BOM item - it should be allowed."""
BomItem.objects.create(
part=self.assembly, sub_part=self.sub_part_1, quantity=99
) | Try to add a duplicate BOM item - it should be allowed. | test_duplicate_bom_line | python | inventree/InvenTree | src/backend/InvenTree/build/test_build.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_build.py | MIT |
def allocate_stock(self, output, allocations):
"""Allocate stock to this build, against a particular output.
Args:
output: StockItem object (or None)
allocations: Map of {StockItem: quantity}
"""
items_to_create = []
for item, quantity in allocations.ite... | Allocate stock to this build, against a particular output.
Args:
output: StockItem object (or None)
allocations: Map of {StockItem: quantity}
| allocate_stock | python | inventree/InvenTree | src/backend/InvenTree/build/test_build.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_build.py | MIT |
def test_overallocation_and_trim(self):
"""Test overallocation of stock and trim function."""
self.assertEqual(self.build.status, status.BuildStatus.PENDING)
self.build.issue_build()
self.assertEqual(self.build.status, status.BuildStatus.PRODUCTION)
# Fully allocate tracked stoc... | Test overallocation of stock and trim function. | test_overallocation_and_trim | python | inventree/InvenTree | src/backend/InvenTree/build/test_build.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_build.py | MIT |
def test_change_part(self):
"""Try to change target part after creating a build."""
bo = Build.objects.create(
reference='BO-9999',
title='Some new build',
part=self.assembly,
quantity=5,
issued_by=get_user_model().objects.get(pk=1),
)
... | Try to change target part after creating a build. | test_change_part | python | inventree/InvenTree | src/backend/InvenTree/build/test_build.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_build.py | MIT |
def test_complete_with_required_tests(self):
"""Test the prevention completion when a required test is missing feature."""
# with required tests incompleted the save should fail
set_global_setting(
'PREVENT_BUILD_COMPLETION_HAVING_INCOMPLETED_TESTS', True, change_user=None
)
... | Test the prevention completion when a required test is missing feature. | test_complete_with_required_tests | python | inventree/InvenTree | src/backend/InvenTree/build/test_build.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_build.py | MIT |
def test_overdue_notification(self):
"""Test sending of notifications when a build order is overdue."""
self.build.target_date = datetime.now().date() - timedelta(days=1)
self.build.save()
# Check for overdue orders
build.tasks.check_overdue_build_orders()
message = com... | Test sending of notifications when a build order is overdue. | test_overdue_notification | python | inventree/InvenTree | src/backend/InvenTree/build/test_build.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_build.py | MIT |
def test_new_build_notification(self):
"""Test that a notification is sent when a new build is created."""
Build.objects.create(
reference='BO-9999',
title='Some new build',
part=self.assembly,
quantity=5,
issued_by=get_user_model().objects.get... | Test that a notification is sent when a new build is created. | test_new_build_notification | python | inventree/InvenTree | src/backend/InvenTree/build/test_build.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_build.py | MIT |
def test_events(self):
"""Test that build events are triggered correctly."""
from django_q.models import OrmQ
from build.events import BuildEvents
set_global_setting('ENABLE_PLUGINS_EVENTS', True)
OrmQ.objects.all().delete()
# Create a new build
build = Build.... | Test that build events are triggered correctly. | test_events | python | inventree/InvenTree | src/backend/InvenTree/build/test_build.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_build.py | MIT |
def test_metadata(self):
"""Unit tests for the metadata field."""
# Make sure a BuildItem exists before trying to run this test
b = BuildItem(
stock_item=self.stock_1_2,
build_line=self.line_1,
install_into=self.output_1,
quantity=10,
)
... | Unit tests for the metadata field. | test_metadata | python | inventree/InvenTree | src/backend/InvenTree/build/test_build.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_build.py | MIT |
def setUp(self):
"""Init routines for this unit test class."""
super().setUp()
# Add a "substitute" part for bom_item_2
alt_part = Part.objects.create(
name='alt part', description='An alternative part!', component=True
)
BomItemSubstitute.objects.create(bom... | Init routines for this unit test class. | setUp | python | inventree/InvenTree | src/backend/InvenTree/build/test_build.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_build.py | MIT |
def test_auto_allocate(self):
"""Run the 'auto-allocate' function. What do we expect to happen?
There are two "untracked" parts:
- sub_part_1 (quantity 5 per BOM = 50 required total) / 103 in stock (2 items)
- sub_part_2 (quantity 3 per BOM = 30 required total) / 25 in stock (5 ... | Run the 'auto-allocate' function. What do we expect to happen?
There are two "untracked" parts:
- sub_part_1 (quantity 5 per BOM = 50 required total) / 103 in stock (2 items)
- sub_part_2 (quantity 3 per BOM = 30 required total) / 25 in stock (5 items)
A "fully auto" allocation... | test_auto_allocate | python | inventree/InvenTree | src/backend/InvenTree/build/test_build.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_build.py | MIT |
def test_fully_auto(self):
"""We should be able to auto-allocate against a build in a single go."""
self.build.auto_allocate_stock(
interchangeable=True, substitutes=True, optional_items=True
)
self.assertTrue(self.build.is_fully_allocated(tracked=False))
self.asser... | We should be able to auto-allocate against a build in a single go. | test_fully_auto | python | inventree/InvenTree | src/backend/InvenTree/build/test_build.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_build.py | MIT |
def test_items_exist(self):
"""Test to ensure that the 'assembly' field is correctly configured."""
Part = self.new_state.apps.get_model('part', 'part')
self.assertEqual(Part.objects.count(), 1)
Build = self.new_state.apps.get_model('build', 'build')
self.assertEqual(Build.obj... | Test to ensure that the 'assembly' field is correctly configured. | test_items_exist | python | inventree/InvenTree | src/backend/InvenTree/build/test_migrations.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_migrations.py | MIT |
def test_build_reference(self):
"""Test that the build reference is correctly assigned to the PK of the Build."""
Build = self.new_state.apps.get_model('build', 'build')
self.assertEqual(Build.objects.count(), 3)
# Check that the build reference is properly assigned
for build i... | Test that the build reference is correctly assigned to the PK of the Build. | test_build_reference | python | inventree/InvenTree | src/backend/InvenTree/build/test_migrations.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_migrations.py | MIT |
def prepare(self):
"""Create some initial data prior to migration."""
Setting = self.old_state.apps.get_model('common', 'inventreesetting')
# Create a custom existing prefix so we can confirm the operation is working
Setting.objects.create(key='BUILDORDER_REFERENCE_PREFIX', value='Build... | Create some initial data prior to migration. | prepare | python | inventree/InvenTree | src/backend/InvenTree/build/test_migrations.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_migrations.py | MIT |
def test_reference_migration(self):
"""Test that the reference fields have been correctly updated."""
Build = self.new_state.apps.get_model('build', 'build')
for build in Build.objects.all():
self.assertTrue(build.reference.startswith('BuildOrder-'))
Setting = self.new_stat... | Test that the reference fields have been correctly updated. | test_reference_migration | python | inventree/InvenTree | src/backend/InvenTree/build/test_migrations.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_migrations.py | MIT |
def test_build_line_creation(self):
"""Test that the BuildLine objects have been created correctly."""
Build = self.new_state.apps.get_model('build', 'build')
BomItem = self.new_state.apps.get_model('part', 'bomitem')
BuildLine = self.new_state.apps.get_model('build', 'buildline')
... | Test that the BuildLine objects have been created correctly. | test_build_line_creation | python | inventree/InvenTree | src/backend/InvenTree/build/test_migrations.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/test_migrations.py | MIT |
def validate_build_order_reference(value):
"""Validate that the BuildOrder reference field matches the required pattern."""
from build.models import Build
# If we get to here, run the "default" validation routine
Build.validate_reference_field(value) | Validate that the BuildOrder reference field matches the required pattern. | validate_build_order_reference | python | inventree/InvenTree | src/backend/InvenTree/build/validators.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/validators.py | MIT |
def add_default_reference(apps, schema_editor):
"""
Add a "default" build-order reference for any existing build orders.
Best we can do is use the PK of the build order itself.
"""
Build = apps.get_model('build', 'build')
count = 0
for build in Build.objects.all():
build.referenc... |
Add a "default" build-order reference for any existing build orders.
Best we can do is use the PK of the build order itself.
| add_default_reference | python | inventree/InvenTree | src/backend/InvenTree/build/migrations/0018_build_reference.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/migrations/0018_build_reference.py | MIT |
def build_refs(apps, schema_editor):
"""
Rebuild the integer "reference fields" for existing Build objects
"""
BuildOrder = apps.get_model('build', 'build')
for build in BuildOrder.objects.all():
ref = 0
result = re.match(r"^(\d+)", build.reference)
if result and len(res... |
Rebuild the integer "reference fields" for existing Build objects
| build_refs | python | inventree/InvenTree | src/backend/InvenTree/build/migrations/0032_auto_20211014_0632.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/migrations/0032_auto_20211014_0632.py | MIT |
def update_build_reference(apps, schema_editor):
"""Update the build order reference.
Ref: https://github.com/inventree/InvenTree/pull/3267
Performs the following steps:
- Extract existing 'prefix' value
- Generate a build order pattern based on the prefix value
- Update any existing build ord... | Update the build order reference.
Ref: https://github.com/inventree/InvenTree/pull/3267
Performs the following steps:
- Extract existing 'prefix' value
- Generate a build order pattern based on the prefix value
- Update any existing build order references with the specified prefix
| update_build_reference | python | inventree/InvenTree | src/backend/InvenTree/build/migrations/0036_auto_20220707_1101.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/migrations/0036_auto_20220707_1101.py | MIT |
def get_bom_items_for_part(part, Part, BomItem):
""" Return a list of all BOM items for a given part.
Note that we cannot use the ORM here (as we are inside a data migration),
so we *copy* the logic from the Part class.
This is a snapshot of the Part.get_bom_items() method as of 2023-05-29
"""
... | Return a list of all BOM items for a given part.
Note that we cannot use the ORM here (as we are inside a data migration),
so we *copy* the logic from the Part class.
This is a snapshot of the Part.get_bom_items() method as of 2023-05-29
| get_bom_items_for_part | python | inventree/InvenTree | src/backend/InvenTree/build/migrations/0044_auto_20230528_1410.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/migrations/0044_auto_20230528_1410.py | MIT |
def add_lines_to_builds(apps, schema_editor):
"""Create BuildOrderLine objects for existing build orders"""
# Get database models
Build = apps.get_model("build", "Build")
BuildLine = apps.get_model("build", "BuildLine")
Part = apps.get_model("part", "Part")
BomItem = apps.get_model("part", "Bo... | Create BuildOrderLine objects for existing build orders | add_lines_to_builds | python | inventree/InvenTree | src/backend/InvenTree/build/migrations/0044_auto_20230528_1410.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/migrations/0044_auto_20230528_1410.py | MIT |
def remove_build_lines(apps, schema_editor):
"""Remove BuildOrderLine objects from the database"""
# Get database models
BuildLine = apps.get_model("build", "BuildLine")
n = BuildLine.objects.all().count()
BuildLine.objects.all().delete()
if n > 0:
print(f"Removed {n} BuildOrderLine ... | Remove BuildOrderLine objects from the database | remove_build_lines | python | inventree/InvenTree | src/backend/InvenTree/build/migrations/0044_auto_20230528_1410.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/migrations/0044_auto_20230528_1410.py | MIT |
def reverse_build_links(apps, schema_editor):
"""Reverse data migration from add_build_line_links
Basically, iterate through each BuildItem and update the links based on the BuildLine
"""
BuildItem = apps.get_model("build", "BuildItem")
items = BuildItem.objects.all()
for item in items:
... | Reverse data migration from add_build_line_links
Basically, iterate through each BuildItem and update the links based on the BuildLine
| reverse_build_links | python | inventree/InvenTree | src/backend/InvenTree/build/migrations/0046_auto_20230606_1033.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/migrations/0046_auto_20230606_1033.py | MIT |
def forward(apps, schema_editor):
"""Find and delete any BuildItem instances which have a null BuildLine field."""
BuildItem = apps.get_model('build', 'BuildItem')
items = BuildItem.objects.filter(build_line=None)
if items.count() > 0:
print(f"Deleting {items.count()} BuildItem objects wi... | Find and delete any BuildItem instances which have a null BuildLine field. | forward | python | inventree/InvenTree | src/backend/InvenTree/build/migrations/0050_auto_20240508_0138.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/build/migrations/0050_auto_20240508_0138.py | MIT |
def get_readonly_fields(self, request, obj=None): # pragma: no cover
"""Prevent the 'key' field being edited once the setting is created."""
if obj:
return ['key']
return [] | Prevent the 'key' field being edited once the setting is created. | get_readonly_fields | python | inventree/InvenTree | src/backend/InvenTree/common/admin.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/common/admin.py | MIT |
def get(self, request, fmt=None):
"""Return information on available currency conversions."""
# Extract a list of all available rates
try:
rates = Rate.objects.all()
except Exception:
rates = []
# Information on last update
try:
backen... | Return information on available currency conversions. | get | python | inventree/InvenTree | src/backend/InvenTree/common/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/common/api.py | MIT |
def post(self, request, *args, **kwargs):
"""Performing a POST request will update currency exchange rates."""
from InvenTree.tasks import update_exchange_rates
update_exchange_rates(force=True)
return Response({'success': 'Exchange rates updated'}) | Performing a POST request will update currency exchange rates. | post | python | inventree/InvenTree | src/backend/InvenTree/common/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/common/api.py | MIT |
def list(self, request, *args, **kwargs):
"""Ensure all global settings are created."""
common.models.InvenTreeSetting.build_default_values()
return super().list(request, *args, **kwargs) | Ensure all global settings are created. | list | python | inventree/InvenTree | src/backend/InvenTree/common/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/common/api.py | MIT |
def get_object(self):
"""Attempt to find a global setting object with the provided key."""
key = str(self.kwargs['key']).upper()
if key.startswith('_') or key not in common.models.InvenTreeSetting.SETTINGS:
raise NotFound()
return common.models.InvenTreeSetting.get_setting_... | Attempt to find a global setting object with the provided key. | get_object | python | inventree/InvenTree | src/backend/InvenTree/common/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/common/api.py | MIT |
def list(self, request, *args, **kwargs):
"""Ensure all user settings are created."""
common.models.InvenTreeUserSetting.build_default_values(user=request.user)
return super().list(request, *args, **kwargs) | Ensure all user settings are created. | list | python | inventree/InvenTree | src/backend/InvenTree/common/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/common/api.py | MIT |
def filter_queryset(self, queryset):
"""Only list settings which apply to the current user."""
try:
user = self.request.user
except AttributeError: # pragma: no cover
return common.models.InvenTreeUserSetting.objects.none()
queryset = super().filter_queryset(que... | Only list settings which apply to the current user. | filter_queryset | python | inventree/InvenTree | src/backend/InvenTree/common/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/common/api.py | MIT |
def get_object(self):
"""Attempt to find a user setting object with the provided key."""
key = str(self.kwargs['key']).upper()
if (
key.startswith('_')
or key not in common.models.InvenTreeUserSetting.SETTINGS
):
raise NotFound()
return commo... | Attempt to find a user setting object with the provided key. | get_object | python | inventree/InvenTree | src/backend/InvenTree/common/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/common/api.py | MIT |
def filter_queryset(self, queryset):
"""Only list notifications which apply to the current user."""
try:
user = self.request.user
except AttributeError:
return common.models.NotificationMessage.objects.none()
queryset = super().filter_queryset(queryset)
q... | Only list notifications which apply to the current user. | filter_queryset | python | inventree/InvenTree | src/backend/InvenTree/common/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/common/api.py | MIT |
def get(self, request, *args, **kwargs):
"""Set all messages for the current user as read."""
try:
self.queryset.filter(user=request.user, read=False).update(read=True)
return Response({'status': 'ok'})
except Exception as exc:
raise serializers.ValidationErro... | Set all messages for the current user as read. | get | python | inventree/InvenTree | src/backend/InvenTree/common/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/common/api.py | MIT |
def get_object(self):
"""Attempt to find a config object with the provided key."""
key = self.kwargs['key']
value = CONFIG_LOOKUPS.get(key, None)
if not value:
raise NotFound()
return {key: value} | Attempt to find a config object with the provided key. | get_object | python | inventree/InvenTree | src/backend/InvenTree/common/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/common/api.py | MIT |
def get(self, request, *args, **kwargs):
"""Return a list of all available units."""
reg = InvenTree.conversion.get_unit_registry()
all_units = {k: self.get_unit(reg, k) for k in reg}
data = {
'default_system': reg.default_system,
'available_systems': dir(reg.sys)... | Return a list of all available units. | get | python | inventree/InvenTree | src/backend/InvenTree/common/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/common/api.py | MIT |
def get(self, request, fmt=None):
"""Return information about the current status of the background task queue."""
import django_q.models as q_models
import InvenTree.status
serializer = common.serializers.TaskOverviewSerializer({
'is_running': InvenTree.status.is_worker_run... | Return information about the current status of the background task queue. | get | python | inventree/InvenTree | src/backend/InvenTree/common/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/common/api.py | MIT |
def get_object(self):
"""Attempt to find a ContentType object with the provided key."""
model_ref = self.kwargs.get('model', None)
if model_ref:
qs = self.filter_queryset(self.get_queryset())
try:
return qs.get(model=model_ref)
except ContentTy... | Attempt to find a ContentType object with the provided key. | get_object | python | inventree/InvenTree | src/backend/InvenTree/common/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/common/api.py | MIT |
def filter_is_link(self, queryset, name, value):
"""Filter attachments based on whether they are a link or not."""
if value:
return queryset.exclude(link=None).exclude(link='')
return queryset.filter(Q(link=None) | Q(link='')).distinct() | Filter attachments based on whether they are a link or not. | filter_is_link | python | inventree/InvenTree | src/backend/InvenTree/common/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/common/api.py | MIT |
def filter_is_file(self, queryset, name, value):
"""Filter attachments based on whether they are a file or not."""
if value:
return queryset.exclude(attachment=None).exclude(attachment='')
return queryset.filter(Q(attachment=None) | Q(attachment='')).distinct() | Filter attachments based on whether they are a file or not. | filter_is_file | python | inventree/InvenTree | src/backend/InvenTree/common/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/common/api.py | MIT |
def perform_create(self, serializer):
"""Save the user information when a file is uploaded."""
attachment = serializer.save()
attachment.upload_user = self.request.user
attachment.save() | Save the user information when a file is uploaded. | perform_create | python | inventree/InvenTree | src/backend/InvenTree/common/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/common/api.py | MIT |
def validate_delete(self, queryset, request) -> None:
"""Ensure that the user has correct permissions for a bulk-delete.
- Extract all model types from the provided queryset
- Ensure that the user has correct 'delete' permissions for each model
"""
from common.validators import ... | Ensure that the user has correct permissions for a bulk-delete.
- Extract all model types from the provided queryset
- Ensure that the user has correct 'delete' permissions for each model
| validate_delete | python | inventree/InvenTree | src/backend/InvenTree/common/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/common/api.py | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.