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 complete_sales_order_shipment(shipment_id: int, user_id: int) -> None:
"""Complete allocations for a pending shipment against a SalesOrder.
At this stage, the shipment is assumed to be complete,
and we need to perform the required "processing" tasks.
"""
try:
shipment = order.models.Sal... | Complete allocations for a pending shipment against a SalesOrder.
At this stage, the shipment is assumed to be complete,
and we need to perform the required "processing" tasks.
| complete_sales_order_shipment | python | inventree/InvenTree | src/backend/InvenTree/order/tasks.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/tasks.py | MIT |
def test_rebuild_reference(self):
"""Test that the reference_int field is correctly updated when the model is saved."""
order = PurchaseOrder.objects.get(pk=1)
order.save()
self.assertEqual(order.reference_int, 1)
order.reference = '12345XYZ'
order.save()
self.as... | Test that the reference_int field is correctly updated when the model is saved. | test_rebuild_reference | python | inventree/InvenTree | src/backend/InvenTree/order/tests.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/tests.py | MIT |
def test_locking(self):
"""Test the (auto)locking functionality of the (Purchase)Order model."""
order = PurchaseOrder.objects.get(pk=1)
order.status = PurchaseOrderStatus.PENDING
order.save()
self.assertFalse(order.check_locked())
order.status = PurchaseOrderStatus.COM... | Test the (auto)locking functionality of the (Purchase)Order model. | test_locking | python | inventree/InvenTree | src/backend/InvenTree/order/tests.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/tests.py | MIT |
def test_on_order(self):
"""There should be 3 separate items on order for the M2x4 LPHS part."""
part = Part.objects.get(name='M2x4 LPHS')
open_orders = []
for supplier in part.supplier_parts.all():
open_orders += supplier.open_orders()
self.assertEqual(len(open_or... | There should be 3 separate items on order for the M2x4 LPHS part. | test_on_order | python | inventree/InvenTree | src/backend/InvenTree/order/tests.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/tests.py | MIT |
def test_add_items(self):
"""Test functions for adding line items to an order."""
order = PurchaseOrder.objects.get(pk=1)
self.assertEqual(order.status, PurchaseOrderStatus.PENDING)
self.assertEqual(order.lines.count(), 4)
sku = SupplierPart.objects.get(SKU='ACME-WIDGET')
... | Test functions for adding line items to an order. | test_add_items | python | inventree/InvenTree | src/backend/InvenTree/order/tests.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/tests.py | MIT |
def test_pricing(self):
"""Test functions for adding line items to an order including price-breaks."""
order = PurchaseOrder.objects.get(pk=7)
self.assertEqual(order.status, PurchaseOrderStatus.PENDING)
self.assertEqual(order.lines.count(), 0)
sku = SupplierPart.objects.get(SKU... | Test functions for adding line items to an order including price-breaks. | test_pricing | python | inventree/InvenTree | src/backend/InvenTree/order/tests.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/tests.py | MIT |
def test_receive_pack_size(self):
"""Test receiving orders from suppliers with different pack_size values."""
prt = Part.objects.get(pk=1)
sup = Company.objects.get(pk=1)
# Create a new supplier part with larger pack size
sp_1 = SupplierPart.objects.create(
part=prt,... | Test receiving orders from suppliers with different pack_size values. | test_receive_pack_size | python | inventree/InvenTree | src/backend/InvenTree/order/tests.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/tests.py | MIT |
def test_receive_convert_currency(self):
"""Test receiving orders with different currencies."""
# Setup some dummy exchange rates
self.generate_exchange_rates()
set_global_setting('INVENTREE_DEFAULT_CURRENCY', 'USD')
self.assertEqual(get_global_setting('INVENTREE_DEFAULT_CURRENC... | Test receiving orders with different currencies. | test_receive_convert_currency | python | inventree/InvenTree | src/backend/InvenTree/order/tests.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/tests.py | MIT |
def test_overdue_notification(self):
"""Test overdue purchase order notification.
Ensure that a notification is sent when a PurchaseOrder becomes overdue
"""
po = PurchaseOrder.objects.get(pk=1)
# Ensure that the right users have the right permissions
for user_id in [2,... | Test overdue purchase order notification.
Ensure that a notification is sent when a PurchaseOrder becomes overdue
| test_overdue_notification | python | inventree/InvenTree | src/backend/InvenTree/order/tests.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/tests.py | MIT |
def test_new_po_notification(self):
"""Test that a notification is sent when a new PurchaseOrder is created.
- The responsible user(s) should receive a notification
- The creating user should *not* receive a notification
"""
po = PurchaseOrder.objects.create(
supplie... | Test that a notification is sent when a new PurchaseOrder is created.
- The responsible user(s) should receive a notification
- The creating user should *not* receive a notification
| test_new_po_notification | python | inventree/InvenTree | src/backend/InvenTree/order/tests.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/tests.py | MIT |
def check_options(data, field_name, spec):
"""Helper function to check that the options are configured correctly."""
field_data = data[field_name]
for k, v in spec.items():
self.assertIn(k, field_data)
self.assertEqual(field_data[k], v) | Helper function to check that the options are configured correctly. | check_options | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_po_list(self):
"""Test the PurchaseOrder list API endpoint."""
# List *ALL* PurchaseOrder items
self.filter({}, 7)
# Filter by assigned-to-me
self.filter({'assigned_to_me': 1}, 0)
self.filter({'assigned_to_me': 0}, 7)
# Filter by supplier
self.f... | Test the PurchaseOrder list API endpoint. | test_po_list | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_po_detail(self):
"""Test the PurchaseOrder detail API endpoint."""
url = '/api/order/po/1/'
response = self.get(url)
self.assertEqual(response.status_code, 200)
data = response.data
self.assertEqual(data['pk'], 1)
self.assertEqual(data['description'],... | Test the PurchaseOrder detail API endpoint. | test_po_detail | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_po_reference(self):
"""Test that a reference with a too big / small reference is handled correctly."""
# get permissions
self.assignRole('purchase_order.add')
url = reverse('api-po-list')
huge_number = 'PO-92233720368547758089999999999999999'
response = self.po... | Test that a reference with a too big / small reference is handled correctly. | test_po_reference | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_po_reference_wildcard_default(self):
"""Test that a reference with a wildcard default."""
# get permissions
self.assignRole('purchase_order.add')
# set PO reference setting
set_global_setting('PURCHASEORDER_REFERENCE_PATTERN', '{?:PO}-{ref:04d}')
url = reverse(... | Test that a reference with a wildcard default. | test_po_reference_wildcard_default | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_po_attachments(self):
"""Test the list endpoint for the PurchaseOrderAttachment model."""
url = reverse('api-attachment-list')
response = self.get(url, {'model_type': 'purchaseorder'})
self.assertEqual(response.status_code, status.HTTP_200_OK) | Test the list endpoint for the PurchaseOrderAttachment model. | test_po_attachments | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_po_operations(self):
"""Test that we can create / edit and delete a PurchaseOrder via the API."""
n = models.PurchaseOrder.objects.count()
url = reverse('api-po-list')
# Initially we do not have "add" permission for the PurchaseOrder model,
# so this POST request shoul... | Test that we can create / edit and delete a PurchaseOrder via the API. | test_po_operations | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_po_create(self):
"""Test that we can create a new PurchaseOrder via the API."""
self.assignRole('purchase_order.add')
setting = 'PURCHASEORDER_REQUIRE_RESPONSIBLE'
url = reverse('api-po-list')
InvenTreeSetting.set_setting(setting, False)
data = {
'... | Test that we can create a new PurchaseOrder via the API. | test_po_create | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_po_creation_date(self):
"""Test that we can create set the creation_date field of PurchaseOrder via the API."""
self.assignRole('purchase_order.add')
response = self.post(
reverse('api-po-list'),
{
'reference': 'PO-19881110',
'sup... | Test that we can create set the creation_date field of PurchaseOrder via the API. | test_po_creation_date | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_po_duplicate(self):
"""Test that we can duplicate a PurchaseOrder via the API."""
self.assignRole('purchase_order.add')
po = models.PurchaseOrder.objects.get(pk=1)
self.assertGreater(po.lines.count(), 0)
lines = []
# Add some extra line items to this order
... | Test that we can duplicate a PurchaseOrder via the API. | test_po_duplicate | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_po_calendar_auth(self):
"""Test accessing calendar with header authorization."""
self.client.logout()
base64_token = base64.b64encode(
f'{self.username}:{self.password}'.encode('ascii')
).decode('ascii')
response = self.client.get(
reverse('api-po... | Test accessing calendar with header authorization. | test_po_calendar_auth | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_po_line_list(self):
"""Test the PurchaseOrderLine list API endpoint."""
# List *ALL* PurchaseOrderLine items
self.filter({}, 5)
# Filter by pending status
self.filter({'pending': 1}, 5)
self.filter({'pending': 0}, 0)
# Filter by received status
... | Test the PurchaseOrderLine list API endpoint. | test_po_line_list | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_po_line_bulk_delete(self):
"""Test that we can bulk delete multiple PurchaseOrderLineItems via the API."""
n = models.PurchaseOrderLineItem.objects.count()
self.assignRole('purchase_order.delete')
url = reverse('api-po-line-list')
# Try to delete a set of line items v... | Test that we can bulk delete multiple PurchaseOrderLineItems via the API. | test_po_line_bulk_delete | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_po_line_merge_pricing(self):
"""Test that we can create a new PurchaseOrderLineItem via the API."""
self.assignRole('purchase_order.add')
self.generate_exchange_rates()
su = Company.objects.get(pk=1)
sp = SupplierPart.objects.get(pk=1)
po = models.PurchaseOrder.... | Test that we can create a new PurchaseOrderLineItem via the API. | test_po_line_merge_pricing | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_download_wrong_format(self):
"""Incorrect format should default raise an error."""
url = reverse('api-po-list')
response = self.export_data(url, export_format='xyz', expected_code=400)
self.assertIn('is not a valid choice', str(response['export_format'])) | Incorrect format should default raise an error. | test_download_wrong_format | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_download_line_items(self):
"""Test that the PurchaseOrderLineItems can be downloaded to a file."""
with self.export_data(
reverse('api-po-line-list'),
export_format='xlsx',
expected_code=200,
expected_fn=r'InvenTree_PurchaseOrderLineItem.+\.xlsx',... | Test that the PurchaseOrderLineItems can be downloaded to a file. | test_download_line_items | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_no_items(self):
"""Test with an empty list of items."""
data = self.post(
self.url, {'items': [], 'location': None}, expected_code=400
).data
self.assertIn('Line items must be provided', str(data))
# No new stock items have been created
self.assertE... | Test with an empty list of items. | test_no_items | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_invalid_items(self):
"""Test than errors are returned as expected for invalid data."""
data = self.post(
self.url,
{'items': [{'line_item': 12345, 'location': 12345}]},
expected_code=400,
).data
items = data['items'][0]
self.assertIn... | Test than errors are returned as expected for invalid data. | test_invalid_items | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_invalid_status(self):
"""Test with an invalid StockStatus value."""
data = self.post(
self.url,
{
'items': [
{'line_item': 22, 'location': 1, 'status': 99999, 'quantity': 5}
]
},
expected_code=40... | Test with an invalid StockStatus value. | test_invalid_status | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_mismatched_items(self):
"""Test for supplier parts which *do* exist but do not match the order supplier."""
data = self.post(
self.url,
{
'items': [{'line_item': 22, 'quantity': 123, 'location': 1}],
'location': None,
},
... | Test for supplier parts which *do* exist but do not match the order supplier. | test_mismatched_items | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_null_barcode(self):
"""Test than a "null" barcode field can be provided."""
# Set stock item barcode
item = StockItem.objects.get(pk=1)
item.save()
# Test with "null" value
self.post(
self.url,
{
'items': [{'line_item': 1,... | Test than a "null" barcode field can be provided. | test_null_barcode | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_invalid_barcodes(self):
"""Tests for checking in items with invalid barcodes.
- Cannot check in "duplicate" barcodes
- Barcodes cannot match 'barcode_hash' field for existing StockItem
"""
# Set stock item barcode
item = StockItem.objects.get(pk=1)
item.... | Tests for checking in items with invalid barcodes.
- Cannot check in "duplicate" barcodes
- Barcodes cannot match 'barcode_hash' field for existing StockItem
| test_invalid_barcodes | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_batch_code(self):
"""Test that we can supply a 'batch code' when receiving items."""
line_1 = models.PurchaseOrderLineItem.objects.get(pk=1)
line_2 = models.PurchaseOrderLineItem.objects.get(pk=2)
self.assertEqual(StockItem.objects.filter(supplier_part=line_1.part).count(), 0)
... | Test that we can supply a 'batch code' when receiving items. | test_batch_code | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_serial_numbers(self):
"""Test that we can supply a 'serial number' when receiving items."""
line_1 = models.PurchaseOrderLineItem.objects.get(pk=1)
line_2 = models.PurchaseOrderLineItem.objects.get(pk=2)
self.assertEqual(StockItem.objects.filter(supplier_part=line_1.part).count... | Test that we can supply a 'serial number' when receiving items. | test_serial_numbers | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_packaging(self):
"""Test that we can supply a 'packaging' value when receiving items."""
line_1 = models.PurchaseOrderLineItem.objects.get(pk=1)
line_2 = models.PurchaseOrderLineItem.objects.get(pk=2)
line_1.part.packaging = 'Reel'
line_1.part.save()
line_2.par... | Test that we can supply a 'packaging' value when receiving items. | test_packaging | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_so_list(self):
"""Test the SalesOrder list API endpoint."""
# All orders
self.filter({}, 5)
# Filter by customer
self.filter({'customer': 4}, 3)
self.filter({'customer': 5}, 2)
# Filter by outstanding
self.filter({'outstanding': True}, 3)
... | Test the SalesOrder list API endpoint. | test_so_list | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_so_attachments(self):
"""Test the list endpoint for the SalesOrderAttachment model."""
url = reverse('api-attachment-list')
# Filter by 'salesorder'
self.get(
url, data={'model_type': 'salesorder', 'model_id': 1}, expected_code=200
) | Test the list endpoint for the SalesOrderAttachment model. | test_so_attachments | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_so_operations(self):
"""Test that we can create / edit and delete a SalesOrder via the API."""
n = models.SalesOrder.objects.count()
url = reverse('api-so-list')
# Initially we do not have "add" permission for the SalesOrder model,
# so this POST request should return ... | Test that we can create / edit and delete a SalesOrder via the API. | test_so_operations | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_so_create(self):
"""Test that we can create a new SalesOrder via the API."""
self.assignRole('sales_order.add')
url = reverse('api-so-list')
# Will fail due to invalid reference field
response = self.post(
url,
{
'reference': '12... | Test that we can create a new SalesOrder via the API. | test_so_create | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_so_cancel(self):
"""Test API endpoint for cancelling a SalesOrder."""
so = models.SalesOrder.objects.get(pk=1)
self.assertEqual(so.status, SalesOrderStatus.PENDING)
url = reverse('api-so-cancel', kwargs={'pk': so.pk})
# Try to cancel, without permission
self.p... | Test API endpoint for cancelling a SalesOrder. | test_so_cancel | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_export(self):
"""Test we can export the SalesOrder list."""
n = models.SalesOrder.objects.count()
# Check there are some sales orders
self.assertGreater(n, 0)
for order in models.SalesOrder.objects.all():
# Reconstruct the total price
order.save... | Test we can export the SalesOrder list. | test_export | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_sales_order_complete(self):
"""Tests for marking a SalesOrder as complete."""
self.assignRole('sales_order.add')
# Let's create a SalesOrder
customer = Company.objects.filter(is_customer=True).first()
so = models.SalesOrder.objects.create(
customer=customer,... | Tests for marking a SalesOrder as complete. | test_sales_order_complete | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def setUpTestData(cls):
"""Init routine for this unit test class."""
super().setUpTestData()
# List of salable parts
parts = Part.objects.filter(salable=True)
lines = []
# Create a bunch of SalesOrderLineItems for each order
for idx, so in enumerate(models.Sale... | Init routine for this unit test class. | setUpTestData | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_so_line_allocated_filters(self):
"""Test filtering by allocation status for a SalesOrderLineItem."""
self.assignRole('sales_order.add')
# Crete a new SalesOrder via the API
response = self.post(
reverse('api-so-list'),
{
'customer': Compa... | Test filtering by allocation status for a SalesOrderLineItem. | test_so_line_allocated_filters | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_download_fail(self):
"""Test that downloading without the 'export' option fails."""
url = reverse('api-so-list')
response = self.export_data(url, export_plugin='no-plugin', expected_code=400)
self.assertIn('is not a valid choice', str(response['export_plugin'])) | Test that downloading without the 'export' option fails. | test_download_fail | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_download_csv(self):
"""Test that the list of sales orders can be downloaded as a .csv file."""
url = reverse('api-so-list')
required_cols = [
'Line Items',
'ID',
'Reference',
'Customer',
'Order Status',
'Shipment D... | Test that the list of sales orders can be downloaded as a .csv file. | test_download_csv | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def setUp(self):
"""Init routines for this unit testing class."""
super().setUp()
self.assignRole('sales_order.add')
self.url = reverse('api-so-allocate', kwargs={'pk': 1})
self.order = models.SalesOrder.objects.get(pk=1)
# Create some line items for this purchase ord... | Init routines for this unit testing class. | setUp | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_allocate(self):
"""Test that the allocation endpoint acts as expected, when provided with valid data!"""
# First, check that there are no line items allocated against this SalesOrder
self.assertEqual(self.order.stock_allocations.count(), 0)
data = {'items': [], 'shipment': self... | Test that the allocation endpoint acts as expected, when provided with valid data! | test_allocate | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_allocate_variant(self):
"""Test that the allocation endpoint acts as expected, when provided with variant."""
# First, check that there are no line items allocated against this SalesOrder
self.assertEqual(self.order.stock_allocations.count(), 0)
data = {'items': [], 'shipment':... | Test that the allocation endpoint acts as expected, when provided with variant. | test_allocate_variant | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_shipment_complete(self):
"""Test that we can complete a shipment via the API."""
url = reverse('api-so-shipment-ship', kwargs={'pk': self.shipment.pk})
self.assertFalse(self.shipment.is_complete())
self.assertFalse(self.shipment.check_can_complete(raise_error=False))
w... | Test that we can complete a shipment via the API. | test_shipment_complete | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_shipment_delivery_date(self):
"""Test delivery date functions via API."""
url = reverse('api-so-shipment-detail', kwargs={'pk': self.shipment.pk})
# Attempt remove delivery_date from shipment
response = self.patch(url, {'delivery_date': None}, expected_code=200)
# Ship... | Test delivery date functions via API. | test_shipment_delivery_date | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_sales_order_shipment_list(self):
"""Test the SalesOrderShipment list API endpoint."""
url = reverse('api-so-shipment-list')
# Count before creation
count_before = models.SalesOrderShipment.objects.count()
# Create some new shipments via the API
for order in mod... | Test the SalesOrderShipment list API endpoint. | test_sales_order_shipment_list | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_create(self):
"""Test creation of ReturnOrder via the API."""
url = reverse('api-return-order-list')
# Do not have required permissions yet
self.post(
url, {'customer': 1, 'description': 'a return order'}, expected_code=403
)
self.assignRole('return... | Test creation of ReturnOrder via the API. | test_create | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_update(self):
"""Test that we can update a ReturnOrder via the API."""
url = reverse('api-return-order-detail', kwargs={'pk': 1})
# Test detail endpoint
data = self.get(url, expected_code=200).data
self.assertEqual(data['reference'], 'RMA-001')
# Attempt to up... | Test that we can update a ReturnOrder via the API. | test_update | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_ro_issue(self):
"""Test the 'issue' order for a ReturnOrder."""
order = models.ReturnOrder.objects.get(pk=1)
self.assertEqual(order.status, ReturnOrderStatus.PENDING)
self.assertIsNone(order.issue_date)
url = reverse('api-return-order-issue', kwargs={'pk': 1})
... | Test the 'issue' order for a ReturnOrder. | test_ro_issue | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_receive(self):
"""Test that we can receive items against a ReturnOrder."""
customer = Company.objects.get(pk=4)
# Create an order
rma = models.ReturnOrder.objects.create(
customer=customer, description='A return order'
)
self.assertEqual(rma.referen... | Test that we can receive items against a ReturnOrder. | test_receive | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def receive(items, location=None, expected_code=400):
"""Helper function to receive items against this ReturnOrder."""
url = reverse('api-return-order-receive', kwargs={'pk': rma.pk})
response = self.post(
url, {'items': items, 'location': location}, expected_code=ex... | Helper function to receive items against this ReturnOrder. | receive | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_receive_untracked(self):
"""Test that we can receive untracked items against a ReturnOrder.
Ref: https://github.com/inventree/InvenTree/pull/8590
"""
self.assignRole('return_order.add')
company = Company.objects.get(pk=4)
# Create a new ReturnOrder
rma ... | Test that we can receive untracked items against a ReturnOrder.
Ref: https://github.com/inventree/InvenTree/pull/8590
| test_receive_untracked | python | inventree/InvenTree | src/backend/InvenTree/order/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_api.py | MIT |
def test_ref_field(self):
"""Test that the 'reference_int' field has been created and is filled out correctly."""
PurchaseOrder = self.new_state.apps.get_model('order', 'purchaseorder')
SalesOrder = self.new_state.apps.get_model('order', 'salesorder')
for ii in range(10):
po... | Test that the 'reference_int' field has been created and is filled out correctly. | test_ref_field | python | inventree/InvenTree | src/backend/InvenTree/order/test_migrations.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_migrations.py | MIT |
def test_shipment_creation(self):
"""Check that a SalesOrderShipment has been created."""
SalesOrder = self.new_state.apps.get_model('order', 'salesorder')
Shipment = self.new_state.apps.get_model('order', 'salesordershipment')
# Check that the correct number of Shipments have been crea... | Check that a SalesOrderShipment has been created. | test_shipment_creation | python | inventree/InvenTree | src/backend/InvenTree/order/test_migrations.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_migrations.py | MIT |
def test_po_migration(self):
"""Test that the the PO lines where converted correctly."""
PurchaseOrder = self.new_state.apps.get_model('order', 'purchaseorder')
for ii in range(10):
po = PurchaseOrder.objects.get(reference=f'{ii}-abcde')
self.assertEqual(po.extra_lines.co... | Test that the the PO lines where converted correctly. | test_po_migration | python | inventree/InvenTree | src/backend/InvenTree/order/test_migrations.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_migrations.py | MIT |
def test_migration(self):
"""Test that the migration has correctly updated the SalesOrder objects."""
SalesOrder = self.new_state.apps.get_model('order', 'salesorder')
order = SalesOrder.objects.get(reference='SO-999')
self.assertIsNotNone(order.shipment_date)
self.assertEqual(o... | Test that the migration has correctly updated the SalesOrder objects. | test_migration | python | inventree/InvenTree | src/backend/InvenTree/order/test_migrations.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_migrations.py | MIT |
def setUpTestData(cls):
"""Initial setup for this set of unit tests."""
# Create a Company to ship the goods to
cls.customer = Company.objects.create(
name='ABC Co', description='My customer', is_customer=True
)
# Create a Part to ship
cls.part = Part.objects... | Initial setup for this set of unit tests. | setUpTestData | python | inventree/InvenTree | src/backend/InvenTree/order/test_sales_order.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_sales_order.py | MIT |
def test_so_reference(self):
"""Unit tests for sales order generation."""
# Test that a good reference is created when we have no existing orders
SalesOrder.objects.all().delete()
self.assertEqual(SalesOrder.generate_reference(), 'SO-0001') | Unit tests for sales order generation. | test_so_reference | python | inventree/InvenTree | src/backend/InvenTree/order/test_sales_order.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_sales_order.py | MIT |
def test_rebuild_reference(self):
"""Test that the 'reference_int' field gets rebuilt when the model is saved."""
self.assertEqual(self.order.reference_int, 1234)
self.order.reference = '999'
self.order.save()
self.assertEqual(self.order.reference_int, 999)
self.order.r... | Test that the 'reference_int' field gets rebuilt when the model is saved. | test_rebuild_reference | python | inventree/InvenTree | src/backend/InvenTree/order/test_sales_order.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_sales_order.py | MIT |
def test_add_duplicate_line_item(self):
"""Adding a duplicate line item to a SalesOrder is accepted."""
for ii in range(1, 5):
SalesOrderLineItem.objects.create(
order=self.order, part=self.part, quantity=ii
) | Adding a duplicate line item to a SalesOrder is accepted. | test_add_duplicate_line_item | python | inventree/InvenTree | src/backend/InvenTree/order/test_sales_order.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_sales_order.py | MIT |
def test_over_allocate(self):
"""Test that over allocation logic works."""
SA = StockItem.objects.create(part=self.part, quantity=9)
# First three allocations should succeed
for _i in range(3):
allocation = SalesOrderAllocation.objects.create(
line=self.line,... | Test that over allocation logic works. | test_over_allocate | python | inventree/InvenTree | src/backend/InvenTree/order/test_sales_order.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_sales_order.py | MIT |
def test_allocate_variant(self):
"""Allocate a variant of the designated item."""
SalesOrderAllocation.objects.create(
line=self.line,
shipment=self.shipment,
item=StockItem.objects.get(pk=self.Sc.pk),
quantity=50,
)
self.assertEqual(self.l... | Allocate a variant of the designated item. | test_allocate_variant | python | inventree/InvenTree | src/backend/InvenTree/order/test_sales_order.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_sales_order.py | MIT |
def test_order_cancel(self):
"""Allocate line items then cancel the order."""
self.allocate_stock(True)
self.assertEqual(SalesOrderAllocation.objects.count(), 2)
self.assertEqual(self.order.status, status.SalesOrderStatus.PENDING)
self.order.cancel_order()
self.assertEq... | Allocate line items then cancel the order. | test_order_cancel | python | inventree/InvenTree | src/backend/InvenTree/order/test_sales_order.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_sales_order.py | MIT |
def test_complete_order(self):
"""Allocate line items, then ship the order."""
# Assert some stuff before we run the test
# Initially there are three stock items
self.assertEqual(StockItem.objects.count(), 3)
# Take 25 units from each StockItem
self.allocate_stock(True)
... | Allocate line items, then ship the order. | test_complete_order | python | inventree/InvenTree | src/backend/InvenTree/order/test_sales_order.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_sales_order.py | MIT |
def test_default_shipment(self):
"""Test sales order default shipment creation."""
# Default setting value should be False
self.assertEqual(
False, InvenTreeSetting.get_setting('SALESORDER_DEFAULT_SHIPMENT')
)
# Create an order
order_1 = SalesOrder.objects.cr... | Test sales order default shipment creation. | test_default_shipment | python | inventree/InvenTree | src/backend/InvenTree/order/test_sales_order.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_sales_order.py | MIT |
def test_new_so_notification(self):
"""Test that a notification is sent when a new SalesOrder is issued.
- The responsible user should receive a notification
- The creating user should *not* receive a notification
"""
so = SalesOrder.objects.create(
customer=self.cus... | Test that a notification is sent when a new SalesOrder is issued.
- The responsible user should receive a notification
- The creating user should *not* receive a notification
| test_new_so_notification | python | inventree/InvenTree | src/backend/InvenTree/order/test_sales_order.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/test_sales_order.py | MIT |
def add_shipment(apps, schema_editor):
"""
Create a SalesOrderShipment for each existing SalesOrder instance.
Any "allocations" are marked against that shipment.
For each existing SalesOrder instance, we create a default SalesOrderShipment,
and associate each SalesOrderAllocation with this shipmen... |
Create a SalesOrderShipment for each existing SalesOrder instance.
Any "allocations" are marked against that shipment.
For each existing SalesOrder instance, we create a default SalesOrderShipment,
and associate each SalesOrderAllocation with this shipment
| add_shipment | python | inventree/InvenTree | src/backend/InvenTree/order/migrations/0055_auto_20211025_0645.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/migrations/0055_auto_20211025_0645.py | MIT |
def reverse_add_shipment(apps, schema_editor): # pragma: no cover
"""
Reverse the migration, delete and SalesOrderShipment instances
"""
Allocation = apps.get_model('order', 'salesorderallocation')
# First, ensure that all SalesOrderAllocation objects point to a null shipment
for allocation i... |
Reverse the migration, delete and SalesOrderShipment instances
| reverse_add_shipment | python | inventree/InvenTree | src/backend/InvenTree/order/migrations/0055_auto_20211025_0645.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/migrations/0055_auto_20211025_0645.py | MIT |
def calculate_shipped_quantity(apps, schema_editor):
"""
In migration 0057 we added a new field 'shipped' to the SalesOrderLineItem model.
This field is used to record the number of items shipped,
even if the actual stock items get deleted from the database.
For existing orders in the database, we... |
In migration 0057 we added a new field 'shipped' to the SalesOrderLineItem model.
This field is used to record the number of items shipped,
even if the actual stock items get deleted from the database.
For existing orders in the database, we calculate this as follows:
- If the order is "shipped"... | calculate_shipped_quantity | python | inventree/InvenTree | src/backend/InvenTree/order/migrations/0058_auto_20211126_1210.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/migrations/0058_auto_20211126_1210.py | MIT |
def _convert_model(apps, line_item_ref, extra_line_ref, price_ref):
"""Convert the OrderLineItem instances if applicable to new ExtraLine instances"""
OrderLineItem = apps.get_model('order', line_item_ref)
OrderExtraLine = apps.get_model('order', extra_line_ref)
items_to_change = OrderLineItem.objects.... | Convert the OrderLineItem instances if applicable to new ExtraLine instances | _convert_model | python | inventree/InvenTree | src/backend/InvenTree/order/migrations/0064_purchaseorderextraline_salesorderextraline.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/migrations/0064_purchaseorderextraline_salesorderextraline.py | MIT |
def _reconvert_model(apps, line_item_ref, extra_line_ref): # pragma: no cover
"""Convert ExtraLine instances back to OrderLineItem instances"""
OrderLineItem = apps.get_model('order', line_item_ref)
OrderExtraLine = apps.get_model('order', extra_line_ref)
print(f'\nStarting to convert - currently at {... | Convert ExtraLine instances back to OrderLineItem instances | _reconvert_model | python | inventree/InvenTree | src/backend/InvenTree/order/migrations/0064_purchaseorderextraline_salesorderextraline.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/migrations/0064_purchaseorderextraline_salesorderextraline.py | MIT |
def update_order_references(order_model, prefix):
"""Update all references of the given model, with the specified prefix"""
n = 0
for order in order_model.objects.all():
if not order.reference.startswith(prefix):
order.reference = prefix + order.reference
order.save()
... | Update all references of the given model, with the specified prefix | update_order_references | python | inventree/InvenTree | src/backend/InvenTree/order/migrations/0074_auto_20220709_0108.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/migrations/0074_auto_20220709_0108.py | MIT |
def update_salesorder_reference(apps, schema_editor):
"""Migrate the reference pattern for the SalesOrder model"""
# Extract the existing "prefix" value
InvenTreeSetting = apps.get_model('common', 'inventreesetting')
try:
prefix = InvenTreeSetting.objects.get(key='SALESORDER_REFERENCE_PREFIX')... | Migrate the reference pattern for the SalesOrder model | update_salesorder_reference | python | inventree/InvenTree | src/backend/InvenTree/order/migrations/0074_auto_20220709_0108.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/migrations/0074_auto_20220709_0108.py | MIT |
def update_purchaseorder_reference(apps, schema_editor):
"""Migrate the reference pattern for the PurchaseOrder model"""
# Extract the existing "prefix" value
InvenTreeSetting = apps.get_model('common', 'inventreesetting')
try:
prefix = InvenTreeSetting.objects.get(key='PURCHASEORDER_REFERENCE... | Migrate the reference pattern for the PurchaseOrder model | update_purchaseorder_reference | python | inventree/InvenTree | src/backend/InvenTree/order/migrations/0074_auto_20220709_0108.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/migrations/0074_auto_20220709_0108.py | MIT |
def update_shipment_date(apps, schema_editor):
"""
Update the shipment date for existing SalesOrderAllocation objects
"""
from order.status_codes import SalesOrderStatusGroups
SalesOrder = apps.get_model('order', 'SalesOrder')
# Find any orders which are "complete" but missing a shipment date... |
Update the shipment date for existing SalesOrderAllocation objects
| update_shipment_date | python | inventree/InvenTree | src/backend/InvenTree/order/migrations/0105_auto_20241128_0431.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/order/migrations/0105_auto_20241128_0431.py | MIT |
def get_serializer(self, *args, **kwargs):
"""Add additional context based on query parameters."""
try:
params = self.request.query_params
kwargs['path_detail'] = str2bool(params.get('path_detail', False))
except AttributeError:
pass
return super().g... | Add additional context based on query parameters. | get_serializer | python | inventree/InvenTree | src/backend/InvenTree/part/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py | MIT |
def get_queryset(self, *args, **kwargs):
"""Return an annotated queryset for the CategoryDetail endpoint."""
queryset = super().get_queryset(*args, **kwargs)
queryset = part_serializers.CategorySerializer.annotate_queryset(queryset)
return queryset | Return an annotated queryset for the CategoryDetail endpoint. | get_queryset | python | inventree/InvenTree | src/backend/InvenTree/part/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py | MIT |
def get_serializer_context(self):
"""Add extra context to the serializer for the CategoryDetail endpoint."""
ctx = super().get_serializer_context()
try:
ctx['starred_categories'] = [
star.category for star in self.request.user.starred_categories.all()
]
... | Add extra context to the serializer for the CategoryDetail endpoint. | get_serializer_context | python | inventree/InvenTree | src/backend/InvenTree/part/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py | MIT |
def filter_starred(self, queryset, name, value):
"""Filter by whether the PartCategory is starred by the current user."""
user = self.request.user
starred_categories = [
star.category.pk for star in user.starred_categories.all()
]
if str2bool(value):
ret... | Filter by whether the PartCategory is starred by the current user. | filter_starred | python | inventree/InvenTree | src/backend/InvenTree/part/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py | MIT |
def filter_cascade(self, queryset, name, value):
"""Filter by whether to include sub-categories in the filtered results.
Note: If the "parent" filter is provided, we offload the logic to that method.
"""
parent = str2bool(self.data.get('parent', None))
top_level = str2bool(self.... | Filter by whether to include sub-categories in the filtered results.
Note: If the "parent" filter is provided, we offload the logic to that method.
| filter_cascade | python | inventree/InvenTree | src/backend/InvenTree/part/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py | MIT |
def filter_parent(self, queryset, name, value):
"""Filter by parent category.
Note that the filtering behaviour here varies,
depending on whether the 'cascade' value is set.
So, we have to check the "cascade" value here.
"""
parent = value
depth = self.data.get(... | Filter by parent category.
Note that the filtering behaviour here varies,
depending on whether the 'cascade' value is set.
So, we have to check the "cascade" value here.
| filter_parent | python | inventree/InvenTree | src/backend/InvenTree/part/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py | MIT |
def filter_exclude_tree(self, queryset, name, value):
"""Exclude all sub-categories under the specified category."""
# Exclude the specified category
queryset = queryset.exclude(pk=value.pk)
# Exclude any sub-categories also
queryset = queryset.exclude(parent__in=value.get_desce... | Exclude all sub-categories under the specified category. | filter_exclude_tree | python | inventree/InvenTree | src/backend/InvenTree/part/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py | MIT |
def update(self, request, *args, **kwargs):
"""Perform 'update' function and mark this part as 'starred' (or not)."""
# Clean up input data
data = self.clean_data(request.data)
if 'starred' in data:
starred = str2bool(data.get('starred', False))
self.get_object(... | Perform 'update' function and mark this part as 'starred' (or not). | update | python | inventree/InvenTree | src/backend/InvenTree/part/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py | MIT |
def destroy(self, request, *args, **kwargs):
"""Delete a Part category instance via the API."""
delete_parts = (
'delete_parts' in request.data and request.data['delete_parts'] == '1'
)
delete_child_categories = (
'delete_child_categories' in request.data
... | Delete a Part category instance via the API. | destroy | python | inventree/InvenTree | src/backend/InvenTree/part/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py | MIT |
def get_queryset(self, *args, **kwargs):
"""Return an annotated queryset for the CategoryTree endpoint."""
queryset = super().get_queryset(*args, **kwargs)
queryset = part_serializers.CategoryTree.annotate_queryset(queryset)
return queryset | Return an annotated queryset for the CategoryTree endpoint. | get_queryset | python | inventree/InvenTree | src/backend/InvenTree/part/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py | MIT |
def get_queryset(self):
"""Custom filtering.
Rules:
- Allow filtering by "null" parent to retrieve all categories parameter templates
- Allow filtering by category
- Allow traversing all parent categories
"""
queryset = super().get_queryset()
params = se... | Custom filtering.
Rules:
- Allow filtering by "null" parent to retrieve all categories parameter templates
- Allow filtering by category
- Allow traversing all parent categories
| get_queryset | python | inventree/InvenTree | src/backend/InvenTree/part/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py | MIT |
def filter_part(self, queryset, name, part):
"""Filter by the 'part' field.
Note: If the 'include_inherited' query parameter is set,
we also include any parts "above" the specified part.
"""
include_inherited = str2bool(
self.request.query_params.get('include_inherit... | Filter by the 'part' field.
Note: If the 'include_inherited' query parameter is set,
we also include any parts "above" the specified part.
| filter_part | python | inventree/InvenTree | src/backend/InvenTree/part/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py | MIT |
def filter_has_results(self, queryset, name, value):
"""Filter by whether the PartTestTemplate has any associated test results."""
if str2bool(value):
return queryset.exclude(results=0)
return queryset.filter(results=0) | Filter by whether the PartTestTemplate has any associated test results. | filter_has_results | python | inventree/InvenTree | src/backend/InvenTree/part/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py | MIT |
def get_queryset(self, *args, **kwargs):
"""Return an annotated queryset for the PartTestTemplateDetail endpoints."""
queryset = super().get_queryset(*args, **kwargs)
queryset = part_serializers.PartTestTemplateSerializer.annotate_queryset(
queryset
)
return queryset | Return an annotated queryset for the PartTestTemplateDetail endpoints. | get_queryset | python | inventree/InvenTree | src/backend/InvenTree/part/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py | MIT |
def get_queryset(self):
"""Return a queryset which excludes any parts without images."""
queryset = super().get_queryset()
# Get all Parts which have an associated image
queryset = queryset.exclude(image='')
return queryset | Return a queryset which excludes any parts without images. | get_queryset | python | inventree/InvenTree | src/backend/InvenTree/part/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py | MIT |
def list(self, request, *args, **kwargs):
"""Serialize the available Part images.
- Images may be used for multiple parts!
"""
queryset = self.filter_queryset(self.get_queryset())
# Return the most popular parts first
data = (
queryset.values('image').annota... | Serialize the available Part images.
- Images may be used for multiple parts!
| list | python | inventree/InvenTree | src/backend/InvenTree/part/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py | MIT |
def retrieve(self, request, *args, **kwargs):
"""Return scheduling information for the referenced Part instance."""
part = self.get_object()
schedule = []
def add_schedule_entry(
date: datetime,
quantity: float,
title: str,
instance,
... | Return scheduling information for the referenced Part instance. | retrieve | python | inventree/InvenTree | src/backend/InvenTree/part/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py | MIT |
def add_schedule_entry(
date: datetime,
quantity: float,
title: str,
instance,
speculative_quantity: float = 0,
):
"""Add a new entry to the schedule list.
Args:
date (datetime): The date of the scheduled event.... | Add a new entry to the schedule list.
Args:
date (datetime): The date of the scheduled event.
quantity (float): The quantity of stock to be added or removed.
title (str): The title of the scheduled event.
instance (Model): The associated model... | add_schedule_entry | python | inventree/InvenTree | src/backend/InvenTree/part/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py | MIT |
def compare(entry_1, entry_2):
"""Comparison function for sorting entries by date.
Account for the fact that either date might be None
"""
date_1 = entry_1['date']
date_2 = entry_2['date']
if date_1 is None:
return -1
... | Comparison function for sorting entries by date.
Account for the fact that either date might be None
| compare | python | inventree/InvenTree | src/backend/InvenTree/part/api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.