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 filter_serialized(self, queryset, name, value): """Filter by whether the StockItem has a serial number (or not).""" q = Q(serial=None) | Q(serial='') if str2bool(value): return queryset.exclude(q) return queryset.filter(q).distinct()
Filter by whether the StockItem has a serial number (or not).
filter_serialized
python
inventree/InvenTree
src/backend/InvenTree/stock/api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/api.py
MIT
def filter_has_batch(self, queryset, name, value): """Filter by whether the StockItem has a batch code (or not).""" q = Q(batch=None) | Q(batch='') if str2bool(value): return queryset.exclude(q) return queryset.filter(q).distinct()
Filter by whether the StockItem has a batch code (or not).
filter_has_batch
python
inventree/InvenTree
src/backend/InvenTree/stock/api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/api.py
MIT
def filter_tracked(self, queryset, name, value): """Filter by whether this stock item is *tracked*. Meaning either: - It has a serial number - It has a batch code """ q_batch = Q(batch=None) | Q(batch='') q_serial = Q(serial=None) | Q(serial='') if str2b...
Filter by whether this stock item is *tracked*. Meaning either: - It has a serial number - It has a batch code
filter_tracked
python
inventree/InvenTree
src/backend/InvenTree/stock/api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/api.py
MIT
def filter_consumed(self, queryset, name, value): """Filter by whether the stock item has been consumed by a build order.""" if str2bool(value): return queryset.filter(consumed_by__isnull=False) return queryset.filter(consumed_by__isnull=True)
Filter by whether the stock item has been consumed by a build order.
filter_consumed
python
inventree/InvenTree
src/backend/InvenTree/stock/api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/api.py
MIT
def filter_installed(self, queryset, name, value): """Filter stock items by "belongs_to" field being empty.""" if str2bool(value): return queryset.exclude(belongs_to=None) return queryset.filter(belongs_to=None)
Filter stock items by "belongs_to" field being empty.
filter_installed
python
inventree/InvenTree
src/backend/InvenTree/stock/api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/api.py
MIT
def filter_company(self, queryset, name, company): """Filter by company (either manufacturer or supplier).""" return queryset.filter( Q(supplier_part__supplier=company) | Q(supplier_part__manufacturer_part__manufacturer=company) ).distinct()
Filter by company (either manufacturer or supplier).
filter_company
python
inventree/InvenTree
src/backend/InvenTree/stock/api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/api.py
MIT
def get_serializer(self, *args, **kwargs): """Set context before returning serializer. Extra detail may be provided to the serializer via query parameters: - part_detail: Include detail about the StockItem's part - location_detail: Include detail about the StockItem's location ...
Set context before returning serializer. Extra detail may be provided to the serializer via query parameters: - part_detail: Include detail about the StockItem's part - location_detail: Include detail about the StockItem's location - supplier_part_detail: Include detail about the Stock...
get_serializer
python
inventree/InvenTree
src/backend/InvenTree/stock/api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/api.py
MIT
def create(self, request, *args, **kwargs): """Create a new StockItem object via the API. We override the default 'create' implementation. If a location is *not* specified, but the linked *part* has a default location, we can pre-fill the location automatically. """ use...
Create a new StockItem object via the API. We override the default 'create' implementation. If a location is *not* specified, but the linked *part* has a default location, we can pre-fill the location automatically.
create
python
inventree/InvenTree
src/backend/InvenTree/stock/api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/api.py
MIT
def filter_queryset(self, queryset): """Custom filtering for the StockItem queryset.""" params = self.request.query_params queryset = super().filter_queryset(queryset) # Exclude stock item tree exclude_tree = params.get('exclude_tree', None) if exclude_tree is not None...
Custom filtering for the StockItem queryset.
filter_queryset
python
inventree/InvenTree
src/backend/InvenTree/stock/api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/api.py
MIT
def perform_create(self, serializer): """Create a new test result object. Also, check if an attachment was uploaded alongside the test result, and save it to the database if it were. """ # Capture the user information test_result = serializer.save() test_result.u...
Create a new test result object. Also, check if an attachment was uploaded alongside the test result, and save it to the database if it were.
perform_create
python
inventree/InvenTree
src/backend/InvenTree/stock/api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/api.py
MIT
def get_delta_model_map(self) -> dict: """Return a mapping of delta models to their respective models and serializers. This is used to generate additional context information for the historical data, with some attempt at caching so that we can reduce the number of database hits. """ ...
Return a mapping of delta models to their respective models and serializers. This is used to generate additional context information for the historical data, with some attempt at caching so that we can reduce the number of database hits.
get_delta_model_map
python
inventree/InvenTree
src/backend/InvenTree/stock/api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/api.py
MIT
def create(self, request, *args, **kwargs): """Create a new StockItemTracking object. Here we override the default 'create' implementation, to save the user information associated with the request object. """ # Clean up input data data = self.clean_data(request.data) ...
Create a new StockItemTracking object. Here we override the default 'create' implementation, to save the user information associated with the request object.
create
python
inventree/InvenTree
src/backend/InvenTree/stock/api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/api.py
MIT
def annotate_location_items(filter: Q = None): """Construct a queryset annotation which returns the number of stock items in a particular location. - Includes items in subcategories also - Requires subquery to perform annotation """ # Construct a subquery to provide all items in this location and a...
Construct a queryset annotation which returns the number of stock items in a particular location. - Includes items in subcategories also - Requires subquery to perform annotation
annotate_location_items
python
inventree/InvenTree
src/backend/InvenTree/stock/filters.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/filters.py
MIT
def annotate_child_items(): """Construct a queryset annotation which returns the number of children below a certain StockItem node in a StockItem tree.""" child_stock_query = stock.models.StockItem.objects.filter( tree_id=OuterRef('tree_id'), lft__gt=OuterRef('lft'), rght__lt=OuterRef('r...
Construct a queryset annotation which returns the number of children below a certain StockItem node in a StockItem tree.
annotate_child_items
python
inventree/InvenTree
src/backend/InvenTree/stock/filters.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/filters.py
MIT
def annotate_sub_locations(): """Construct a queryset annotation which returns the number of sub-locations below a certain StockLocation node in a StockLocation tree.""" subquery = stock.models.StockLocation.objects.filter( tree_id=OuterRef('tree_id'), lft__gt=OuterRef('lft'), rght__lt=O...
Construct a queryset annotation which returns the number of sub-locations below a certain StockLocation node in a StockLocation tree.
annotate_sub_locations
python
inventree/InvenTree
src/backend/InvenTree/stock/filters.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/filters.py
MIT
def generate_batch_code(**kwargs): """Generate a default 'batch code' for a new StockItem. By default, this uses the value of the 'STOCK_BATCH_CODE_TEMPLATE' setting (if configured), which can be passed through a simple template. Also, this function is exposed to the ValidationMixin plugin class, ...
Generate a default 'batch code' for a new StockItem. By default, this uses the value of the 'STOCK_BATCH_CODE_TEMPLATE' setting (if configured), which can be passed through a simple template. Also, this function is exposed to the ValidationMixin plugin class, allowing custom plugins to be used to gene...
generate_batch_code
python
inventree/InvenTree
src/backend/InvenTree/stock/generators.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/generators.py
MIT
def generate_serial_number(part=None, quantity=1, **kwargs) -> str: """Generate a default 'serial number' for a new StockItem.""" quantity = quantity or 1 if part is None: # Cannot generate a serial number without a part return None try: quantity = int(quantity) except Exce...
Generate a default 'serial number' for a new StockItem.
generate_serial_number
python
inventree/InvenTree
src/backend/InvenTree/stock/generators.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/generators.py
MIT
def delete(self, *args, **kwargs): """Custom model deletion routine, which updates any child locations or items. This must be handled within a transaction.atomic(), otherwise the tree structure is damaged """ super().delete( delete_children=kwargs.get('delete_sub_locations',...
Custom model deletion routine, which updates any child locations or items. This must be handled within a transaction.atomic(), otherwise the tree structure is damaged
delete
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def report_context(self) -> StockLocationReportContext: """Return report context data for this StockLocation.""" return { 'location': self, 'qr_data': self.barcode, 'parent': self.parent, 'stock_location': self, 'stock_items': self.get_stock_it...
Return report context data for this StockLocation.
report_context
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def icon(self) -> str: """Get the current icon used for this location. The icon field on this model takes precedences over the possibly assigned stock location type """ if self.custom_icon: return self.custom_icon if self.location_type: return self.locat...
Get the current icon used for this location. The icon field on this model takes precedences over the possibly assigned stock location type
icon
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def get_location_owner(self): """Get the closest "owner" for this location. Start at this location, and traverse "up" the location tree until we find an owner """ for loc in self.get_ancestors(include_self=True, ascending=True): if loc.owner is not None: retu...
Get the closest "owner" for this location. Start at this location, and traverse "up" the location tree until we find an owner
get_location_owner
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def check_ownership(self, user): """Check if the user "owns" (is one of the owners of) the location.""" # Superuser accounts automatically "own" everything if user.is_superuser: return True ownership_enabled = get_global_setting('STOCK_OWNERSHIP_CONTROL') if not own...
Check if the user "owns" (is one of the owners of) the location.
check_ownership
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def clean(self): """Custom clean action for the StockLocation model. Ensure stock location can't be made structural if stock items already located to them """ if self.pk and self.structural and self.stock_item_count(False) > 0: raise ValidationError( _( ...
Custom clean action for the StockLocation model. Ensure stock location can't be made structural if stock items already located to them
clean
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def get_stock_items(self, cascade=True): """Return a queryset for all stock items under this category. Args: cascade: If True, also look under sublocations (default = True) """ if cascade: query = StockItem.objects.filter( location__in=self.getUni...
Return a queryset for all stock items under this category. Args: cascade: If True, also look under sublocations (default = True)
get_stock_items
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def default_delete_on_deplete(): """Return a default value for the 'delete_on_deplete' field. Prior to 2022-12-24, this field was set to True by default. Now, there is a user-configurable setting to govern default behavior. """ try: return get_global_setting('STOCK_DELETE_DEPLETED_DEFAULT',...
Return a default value for the 'delete_on_deplete' field. Prior to 2022-12-24, this field was set to True by default. Now, there is a user-configurable setting to govern default behavior.
default_delete_on_deplete
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def get_test_keys(self, include_installed=True): """Construct a flattened list of test 'keys' for this StockItem.""" keys = [] for test in self.part.getTestTemplates(required=True): if test.key not in keys: keys.append(test.key) for test in self.part.getTest...
Construct a flattened list of test 'keys' for this StockItem.
get_test_keys
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def report_context(self) -> StockItemReportContext: """Generate custom report context data for this StockItem.""" return { 'barcode_data': self.barcode_data, 'barcode_hash': self.barcode_hash, 'batch': self.batch, 'child_items': self.get_children(), ...
Generate custom report context data for this StockItem.
report_context
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def _create_serial_numbers(cls, serials: list, **kwargs) -> QuerySet: """Create multiple stock items with the provided serial numbers. Arguments: serials: List of serial numbers to create **kwargs: Additional keyword arguments to pass to the StockItem creation function ...
Create multiple stock items with the provided serial numbers. Arguments: serials: List of serial numbers to create **kwargs: Additional keyword arguments to pass to the StockItem creation function Returns: QuerySet: The created StockItem objects Raises: ...
_create_serial_numbers
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def convert_serial_to_int(serial: str) -> int: """Convert the provided serial number to an integer value. This function hooks into the plugin system to allow for custom serial number conversion. """ from plugin import PluginMixinEnum, registry # First, let any plugins convert t...
Convert the provided serial number to an integer value. This function hooks into the plugin system to allow for custom serial number conversion.
convert_serial_to_int
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def update_serial_number(self): """Update the 'serial_int' field, to be an integer representation of the serial number. This is used for efficient numerical sorting """ serial = str(getattr(self, 'serial', '')).strip() serial_int = self.convert_serial_to_int(serial) tr...
Update the 'serial_int' field, to be an integer representation of the serial number. This is used for efficient numerical sorting
update_serial_number
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def get_next_serialized_item(self, include_variants=True, reverse=False): """Get the "next" serial number for the part this stock item references. e.g. if this stock item has a serial number 100, we may return the stock item with serial number 101 Note that this only works for "serialized" sto...
Get the "next" serial number for the part this stock item references. e.g. if this stock item has a serial number 100, we may return the stock item with serial number 101 Note that this only works for "serialized" stock items with integer values Args: include_variants: True if we ...
get_next_serialized_item
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def save(self, *args, **kwargs): """Save this StockItem to the database. Performs a number of checks: - Unique serial number requirement - Adds a transaction note when the item is first created. """ self.validate_unique() self.clean() self.update_serial_...
Save this StockItem to the database. Performs a number of checks: - Unique serial number requirement - Adds a transaction note when the item is first created.
save
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def serialized(self): """Return True if this StockItem is serialized.""" return ( self.serial is not None and len(str(self.serial).strip()) > 0 and self.quantity == 1 )
Return True if this StockItem is serialized.
serialized
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def validate_unique(self, exclude=None): """Test that this StockItem is "unique". If the StockItem is serialized, the same serial number. cannot exist for the same part (or part tree). """ super().validate_unique(exclude) # If the serial number is set, make sure it is n...
Test that this StockItem is "unique". If the StockItem is serialized, the same serial number. cannot exist for the same part (or part tree).
validate_unique
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def validate_batch_code(self): """Ensure that the batch code is valid for this StockItem. - Validation is performed by custom plugins. - By default, no validation checks are performed """ from plugin import PluginMixinEnum, registry for plugin in registry.with_mixin(Plu...
Ensure that the batch code is valid for this StockItem. - Validation is performed by custom plugins. - By default, no validation checks are performed
validate_batch_code
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def clean(self): """Validate the StockItem object (separate to field validation). The following validation checks are performed: - The 'part' and 'supplier_part.part' fields cannot point to the same Part object - The 'part' is not virtual - The 'part' does not belong to itself ...
Validate the StockItem object (separate to field validation). The following validation checks are performed: - The 'part' and 'supplier_part.part' fields cannot point to the same Part object - The 'part' is not virtual - The 'part' does not belong to itself - The location is not...
clean
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def convert_to_variant(self, variant, user, notes=None): """Convert this StockItem instance to a "variant", i.e. change the "part" reference field.""" if not variant: # Ignore null values return if variant == self.part: # Variant is the same as the current pa...
Convert this StockItem instance to a "variant", i.e. change the "part" reference field.
convert_to_variant
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def get_item_owner(self): """Return the closest "owner" for this StockItem. - If the item has an owner set, return that - If the item is "in stock", check the StockLocation - Otherwise, return None """ if self.owner is not None: return self.owner if ...
Return the closest "owner" for this StockItem. - If the item has an owner set, return that - If the item is "in stock", check the StockLocation - Otherwise, return None
get_item_owner
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def check_ownership(self, user): """Check if the user "owns" (or is one of the owners of) the item.""" # Superuser accounts automatically "own" everything if user.is_superuser: return True ownership_enabled = get_global_setting('STOCK_OWNERSHIP_CONTROL') if not owne...
Check if the user "owns" (or is one of the owners of) the item.
check_ownership
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def is_stale(self): """Returns True if this Stock item is "stale". To be "stale", the following conditions must be met: - Expiry date is not None - Expiry date will "expire" within the configured stale date - The StockItem is otherwise "in stock" """ if self.expi...
Returns True if this Stock item is "stale". To be "stale", the following conditions must be met: - Expiry date is not None - Expiry date will "expire" within the configured stale date - The StockItem is otherwise "in stock"
is_stale
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def is_expired(self): """Returns True if this StockItem is "expired". To be "expired", the following conditions must be met: - Expiry date is not None - Expiry date is "in the past" - The StockItem is otherwise "in stock" """ if self.expiry_date is None: ...
Returns True if this StockItem is "expired". To be "expired", the following conditions must be met: - Expiry date is not None - Expiry date is "in the past" - The StockItem is otherwise "in stock"
is_expired
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def clearAllocations(self): """Clear all order allocations for this StockItem. Clears: - SalesOrder allocations - Build allocations """ # Delete outstanding SalesOrder allocations self.sales_order_allocations.all().delete() # Delete outstanding BuildOrde...
Clear all order allocations for this StockItem. Clears: - SalesOrder allocations - Build allocations
clearAllocations
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def allocateToCustomer( self, customer, quantity=None, order=None, user=None, notes=None ): """Allocate a StockItem to a customer. This action can be called by the following processes: - Completion of a SalesOrder - User manually assigns a StockItem to the customer ...
Allocate a StockItem to a customer. This action can be called by the following processes: - Completion of a SalesOrder - User manually assigns a StockItem to the customer Args: customer: The customer (Company) to assign the stock to quantity: Quantity to assign ...
allocateToCustomer
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def return_from_customer(self, location, user=None, **kwargs): """Return stock item from customer, back into the specified location. Arguments: location: The location to return the stock item to user: The user performing the action Keyword Arguments: notes: ...
Return stock item from customer, back into the specified location. Arguments: location: The location to return the stock item to user: The user performing the action Keyword Arguments: notes: Additional notes to add to the tracking entry status: Optional...
return_from_customer
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def build_allocation_count(self, **kwargs): """Return the total quantity allocated to builds, with optional filters.""" query = self.allocations.all() if filter_allocations := kwargs.get('filter_allocations'): query = query.filter(**filter_allocations) if exclude_allocation...
Return the total quantity allocated to builds, with optional filters.
build_allocation_count
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def get_sales_order_allocations(self, active=True, **kwargs): """Return a queryset for SalesOrderAllocations against this StockItem, with optional filters. Arguments: active: Filter by 'active' status of the allocation """ query = self.sales_order_allocations.all() ...
Return a queryset for SalesOrderAllocations against this StockItem, with optional filters. Arguments: active: Filter by 'active' status of the allocation
get_sales_order_allocations
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def sales_order_allocation_count(self, active=True, **kwargs): """Return the total quantity allocated to SalesOrders.""" query = self.get_sales_order_allocations(active=active, **kwargs) query = query.aggregate(q=Coalesce(Sum('quantity'), Decimal(0))) total = query['q'] if tota...
Return the total quantity allocated to SalesOrders.
sales_order_allocation_count
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def allocation_count(self): """Return the total quantity allocated to builds or orders.""" bo = self.build_allocation_count() so = self.sales_order_allocation_count() return bo + so
Return the total quantity allocated to builds or orders.
allocation_count
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def can_delete(self): """Can this stock item be deleted? It can NOT be deleted under the following circumstances: - Has installed stock items - Is installed inside another StockItem - It has been assigned to a SalesOrder - It has been assigned to a BuildOrder """...
Can this stock item be deleted? It can NOT be deleted under the following circumstances: - Has installed stock items - Is installed inside another StockItem - It has been assigned to a SalesOrder - It has been assigned to a BuildOrder
can_delete
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def get_installed_items(self, cascade: bool = False) -> set[StockItem]: """Return all stock items which are *installed* in this one! Note: This function is recursive, and may result in a number of database hits! Args: cascade (bool, optional): Include items which are installed in i...
Return all stock items which are *installed* in this one! Note: This function is recursive, and may result in a number of database hits! Args: cascade (bool, optional): Include items which are installed in items which are installed in items. Defaults to False. Returns: ...
get_installed_items
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def installStockItem(self, other_item, quantity, user, notes, build=None): """Install another stock item into this stock item. Args: other_item: The stock item to install into this stock item quantity: The quantity of stock to install user: The user performing the op...
Install another stock item into this stock item. Args: other_item: The stock item to install into this stock item quantity: The quantity of stock to install user: The user performing the operation notes: Any notes associated with the operation build: ...
installStockItem
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def uninstall_into_location(self, location, user, notes): """Uninstall this stock item from another item, into a location. Args: location: The stock location where the item will be moved user: The user performing the operation notes: Any notes associated with the ope...
Uninstall this stock item from another item, into a location. Args: location: The stock location where the item will be moved user: The user performing the operation notes: Any notes associated with the operation
uninstall_into_location
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def is_in_stock( self, check_status: bool = True, check_quantity: bool = True ) -> bool: """Return True if this StockItem is "in stock". Args: check_status: If True, check the status of the StockItem. Defaults to True. check_quantity: If True, check the quantity of t...
Return True if this StockItem is "in stock". Args: check_status: If True, check the status of the StockItem. Defaults to True. check_quantity: If True, check the quantity of the StockItem. Defaults to True.
is_in_stock
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def can_adjust_location(self): """Returns True if the stock location can be "adjusted" for this part. Cannot be adjusted if: - Has been delivered to a customer - Has been installed inside another StockItem """ if self.customer is not None: return False ...
Returns True if the stock location can be "adjusted" for this part. Cannot be adjusted if: - Has been delivered to a customer - Has been installed inside another StockItem
can_adjust_location
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def serializeStock(self, quantity, serials, user, notes='', location=None): """Split this stock item into unique serial numbers. - Quantity can be less than or equal to the quantity of the stock item - Number of serial numbers must match the quantity - Provided serial numbers must not a...
Split this stock item into unique serial numbers. - Quantity can be less than or equal to the quantity of the stock item - Number of serial numbers must match the quantity - Provided serial numbers must not already be in use Args: quantity: Number of items to serialize (int...
serializeStock
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def copyHistoryFrom(self, other): """Copy stock history from another StockItem.""" for item in other.tracking_info.all(): item.item = self item.pk = None item.save()
Copy stock history from another StockItem.
copyHistoryFrom
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def copyTestResultsFrom(self, other, filters=None): """Copy all test results from another StockItem.""" # Set default - see B006 if filters is None: filters = {} for result in other.test_results.all().filter(**filters): # Create a copy of the test result by nulli...
Copy all test results from another StockItem.
copyTestResultsFrom
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def add_test_result(self, create_template=True, **kwargs): """Helper function to add a new StockItemTestResult. The main purpose of this function is to allow lookup of the template, based on the provided test name. If no template is found, a new one is created (if create_template=True)...
Helper function to add a new StockItemTestResult. The main purpose of this function is to allow lookup of the template, based on the provided test name. If no template is found, a new one is created (if create_template=True). Args: create_template: If True, create a new te...
add_test_result
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def can_merge(self, other=None, raise_error=False, **kwargs): """Check if this stock item can be merged into another stock item.""" allow_mismatched_suppliers = kwargs.get('allow_mismatched_suppliers', False) allow_mismatched_status = kwargs.get('allow_mismatched_status', False) try: ...
Check if this stock item can be merged into another stock item.
can_merge
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def merge_stock_items(self, other_items, raise_error=False, **kwargs): """Merge another stock item into this one; the two become one! *This* stock item subsumes the other, which is essentially deleted: - The quantity of this StockItem is increased - Tracking history for the *other* ite...
Merge another stock item into this one; the two become one! *This* stock item subsumes the other, which is essentially deleted: - The quantity of this StockItem is increased - Tracking history for the *other* item is deleted - Any allocations (build order, sales order) are moved to thi...
merge_stock_items
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def splitStock(self, quantity, location=None, user=None, **kwargs): """Split this stock item into two items, in the same location. Stock tracking notes for this StockItem will be duplicated, and added to the new StockItem. Args: quantity: Number of stock items to remove fro...
Split this stock item into two items, in the same location. Stock tracking notes for this StockItem will be duplicated, and added to the new StockItem. Args: quantity: Number of stock items to remove from this entity, and pass to the next location: Where to move the new...
splitStock
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def move(self, location, notes, user, **kwargs): """Move part to a new location. If less than the available quantity is to be moved, a new StockItem is created, with the defined quantity, and that new StockItem is moved. The quantity is also subtracted from the existing StockIte...
Move part to a new location. If less than the available quantity is to be moved, a new StockItem is created, with the defined quantity, and that new StockItem is moved. The quantity is also subtracted from the existing StockItem. Args: location: Destination location...
move
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def updateQuantity(self, quantity): """Update stock quantity for this item. If the quantity has reached zero, this StockItem will be deleted. Returns: - True if the quantity was saved - False if the StockItem was deleted """ # Do not adjust quantity of a...
Update stock quantity for this item. If the quantity has reached zero, this StockItem will be deleted. Returns: - True if the quantity was saved - False if the StockItem was deleted
updateQuantity
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def stocktake(self, count, user, **kwargs): """Perform item stocktake. Arguments: count: The new quantity of the item user: The user performing the stocktake Keyword Arguments: notes: Optional notes for the stocktake status: Optionally adjust the...
Perform item stocktake. Arguments: count: The new quantity of the item user: The user performing the stocktake Keyword Arguments: notes: Optional notes for the stocktake status: Optionally adjust the stock status
stocktake
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def add_stock(self, quantity, user, **kwargs): """Add a specified quantity of stock to this item. Arguments: quantity: The quantity to add user: The user performing the action Keyword Arguments: notes: Optional notes for the stock addition status...
Add a specified quantity of stock to this item. Arguments: quantity: The quantity to add user: The user performing the action Keyword Arguments: notes: Optional notes for the stock addition status: Optionally adjust the stock status
add_stock
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def take_stock(self, quantity, user, code=StockHistoryCode.STOCK_REMOVE, **kwargs): """Remove the specified quantity from this StockItem. Arguments: quantity: The quantity to remove user: The user performing the action Keyword Arguments: code: The stock hist...
Remove the specified quantity from this StockItem. Arguments: quantity: The quantity to remove user: The user performing the action Keyword Arguments: code: The stock history code to use notes: Optional notes for the stock removal status: Opt...
take_stock
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def getTestResults(self, template=None, test=None, result=None, user=None): """Return all test results associated with this StockItem. Optionally can filter results by: - Test template ID - Test name - Test result - User """ results = self.test_results ...
Return all test results associated with this StockItem. Optionally can filter results by: - Test template ID - Test name - Test result - User
getTestResults
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def testResultMap(self, **kwargs): """Return a map of test-results using the test name as the key. Where multiple test results exist for a given name, the *most recent* test is used. This map is useful for rendering to a template (e.g. a test report), as all named tests are acc...
Return a map of test-results using the test name as the key. Where multiple test results exist for a given name, the *most recent* test is used. This map is useful for rendering to a template (e.g. a test report), as all named tests are accessible.
testResultMap
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def requiredTestStatus(self, required_tests=None): """Return the status of the tests required for this StockItem. Return: A dict containing the following items: - total: Number of required tests - passed: Number of tests that have passed - failed: Number ...
Return the status of the tests required for this StockItem. Return: A dict containing the following items: - total: Number of required tests - passed: Number of tests that have passed - failed: Number of tests that have failed
requiredTestStatus
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def passedAllRequiredTests(self, required_tests=None): """Returns True if this StockItem has passed all required tests.""" status = self.requiredTestStatus(required_tests=required_tests) return status['passed'] >= status['total']
Returns True if this StockItem has passed all required tests.
passedAllRequiredTests
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def before_delete_stock_item(sender, instance, using, **kwargs): """Receives pre_delete signal from StockItem object. Before a StockItem is deleted, ensure that each child object is updated, to point to the new parent item. """ # Update each StockItem parent field for child in instance.children...
Receives pre_delete signal from StockItem object. Before a StockItem is deleted, ensure that each child object is updated, to point to the new parent item.
before_delete_stock_item
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def after_delete_stock_item(sender, instance: StockItem, **kwargs): """Function to be executed after a StockItem object is deleted.""" from part import tasks as part_tasks if InvenTree.ready.isImportingData(): return if InvenTree.ready.canAppAccessDatabase(allow_test=True): # Run this ...
Function to be executed after a StockItem object is deleted.
after_delete_stock_item
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def after_save_stock_item(sender, instance: StockItem, created, **kwargs): """Hook function to be executed after StockItem object is saved/updated.""" from part import tasks as part_tasks if not InvenTree.ready.isImportingData(): if InvenTree.ready.canAppAccessDatabase(allow_test=True): ...
Hook function to be executed after StockItem object is saved/updated.
after_save_stock_item
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def save(self, *args, **kwargs): """Validate result is unique before saving.""" super().clean() super().validate_unique() super().save(*args, **kwargs)
Validate result is unique before saving.
save
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def clean(self): """Make sure all values - including for templates - are provided.""" super().clean() # If this test result corresponds to a template, check the requirements of the template try: template = self.template except PartModels.PartTestTemplate.DoesNotExist...
Make sure all values - including for templates - are provided.
clean
python
inventree/InvenTree
src/backend/InvenTree/stock/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/models.py
MIT
def validate_serial(self, value): """Make sure serial is not to big.""" if abs(InvenTree.helpers.extract_int(value)) > 0x7FFFFFFF: raise serializers.ValidationError(_('Serial number is too large')) return value
Make sure serial is not to big.
validate_serial
python
inventree/InvenTree
src/backend/InvenTree/stock/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/serializers.py
MIT
def validate_part(self, part): """Ensure the provided Part instance is valid.""" if part.virtual: raise ValidationError(_('Stock item cannot be created for virtual parts')) return part
Ensure the provided Part instance is valid.
validate_part
python
inventree/InvenTree
src/backend/InvenTree/stock/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/serializers.py
MIT
def update(self, instance, validated_data): """Custom update method to pass the user information through to the instance.""" instance._user = self.context['user'] return super().update(instance, validated_data)
Custom update method to pass the user information through to the instance.
update
python
inventree/InvenTree
src/backend/InvenTree/stock/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/serializers.py
MIT
def annotate_queryset(queryset): """Add some extra annotations to the queryset, performing database queries as efficiently as possible.""" queryset = queryset.prefetch_related( 'location', 'allocations', 'sales_order', 'sales_order_allocations', ...
Add some extra annotations to the queryset, performing database queries as efficiently as possible.
annotate_queryset
python
inventree/InvenTree
src/backend/InvenTree/stock/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/serializers.py
MIT
def validate_quantity(self, quantity): """Validate that the quantity value is correct.""" item = self.context['item'] if quantity < 0: raise ValidationError(_('Quantity must be greater than zero')) if quantity > item.quantity: q = item.quantity raise...
Validate that the quantity value is correct.
validate_quantity
python
inventree/InvenTree
src/backend/InvenTree/stock/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/serializers.py
MIT
def validate(self, data): """Check that the supplied serial numbers are valid.""" data = super().validate(data) item = self.context['item'] if not item.part.trackable: raise ValidationError(_('Serial numbers cannot be assigned to this part')) # Ensure the serial nu...
Check that the supplied serial numbers are valid.
validate
python
inventree/InvenTree
src/backend/InvenTree/stock/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/serializers.py
MIT
def validate(self, data): """Ensure that the provided dataset is valid.""" stock_item = data['stock_item'] quantity = data.get('quantity', stock_item.quantity) if quantity > stock_item.quantity: raise ValidationError({ 'quantity': _('Quantity to install must...
Ensure that the provided dataset is valid.
validate
python
inventree/InvenTree
src/backend/InvenTree/stock/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/serializers.py
MIT
def save(self): """Install the selected stock item into this one.""" data = self.validated_data stock_item = data['stock_item'] quantity_to_install = data.get('quantity', stock_item.quantity) note = data.get('note', '') parent_item = self.context['item'] request...
Install the selected stock item into this one.
save
python
inventree/InvenTree
src/backend/InvenTree/stock/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/serializers.py
MIT
def validate_part(self, part): """Ensure that the provided part is a valid option for the stock item.""" stock_item = self.context['item'] valid_options = stock_item.part.get_conversion_options() if part not in valid_options: raise ValidationError( _('Selecte...
Ensure that the provided part is a valid option for the stock item.
validate_part
python
inventree/InvenTree
src/backend/InvenTree/stock/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/serializers.py
MIT
def validate(self, data): """Ensure that the stock item is valid for conversion. Rules: - If a SupplierPart is assigned, we cannot convert! """ data = super().validate(data) stock_item = self.context['item'] if stock_item.supplier_part is not None: ...
Ensure that the stock item is valid for conversion. Rules: - If a SupplierPart is assigned, we cannot convert!
validate
python
inventree/InvenTree
src/backend/InvenTree/stock/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/serializers.py
MIT
def save(self): """Save the serializer to convert the StockItem to the selected Part.""" data = self.validated_data part = data['part'] stock_item = self.context['item'] request = self.context['request'] stock_item.convert_to_variant(part, request.user)
Save the serializer to convert the StockItem to the selected Part.
save
python
inventree/InvenTree
src/backend/InvenTree/stock/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/serializers.py
MIT
def save(self): """Save the serializer to return the item into stock.""" item = self.context['item'] request = self.context['request'] data = self.validated_data location = data['location'] item.return_from_customer( location, user=request.user,...
Save the serializer to return the item into stock.
save
python
inventree/InvenTree
src/backend/InvenTree/stock/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/serializers.py
MIT
def save(self): """Save the serializer to change the status of the selected stock items.""" data = self.validated_data items = data['items'] status = data['status'] request = self.context['request'] user = getattr(request, 'user', None) note = data.get('note', ...
Save the serializer to change the status of the selected stock items.
save
python
inventree/InvenTree
src/backend/InvenTree/stock/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/serializers.py
MIT
def validate_item(self, item): """Validate item. Ensures: - is in stock - Is salable - Is not allocated """ # The item must currently be "in stock" if not item.in_stock: raise ValidationError(_('Item must be in stock')) # The base par...
Validate item. Ensures: - is in stock - Is salable - Is not allocated
validate_item
python
inventree/InvenTree
src/backend/InvenTree/stock/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/serializers.py
MIT
def validate_customer(self, customer): """Make sure provided company is customer.""" if customer and not customer.is_customer: raise ValidationError(_('Selected company is not a customer')) return customer
Make sure provided company is customer.
validate_customer
python
inventree/InvenTree
src/backend/InvenTree/stock/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/serializers.py
MIT
def validate_item(self, item): """Make sure item can be merged.""" # Check that the stock item is able to be merged item.can_merge(raise_error=True) return item
Make sure item can be merged.
validate_item
python
inventree/InvenTree
src/backend/InvenTree/stock/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/serializers.py
MIT
def validate(self, data): """Make sure all needed values are provided and that the items can be merged.""" data = super().validate(data) items = data['items'] if len(items) < 2: raise ValidationError(_('At least two stock items must be provided')) unique_items = se...
Make sure all needed values are provided and that the items can be merged.
validate
python
inventree/InvenTree
src/backend/InvenTree/stock/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/serializers.py
MIT
def save(self): """Actually perform the stock merging action. At this point we are confident that the merge can take place """ data = self.validated_data base_item = data['base_item'] items = data['items'][1:] request = self.context['request'] user = ge...
Actually perform the stock merging action. At this point we are confident that the merge can take place
save
python
inventree/InvenTree
src/backend/InvenTree/stock/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/serializers.py
MIT
def validate_pk(self, stock_item: StockItem) -> StockItem: """Ensure the stock item is valid.""" allow_out_of_stock_transfer = get_global_setting( 'STOCK_ALLOW_OUT_OF_STOCK_TRANSFER', backup_value=False, cache=False ) if not allow_out_of_stock_transfer and not stock_item.is_...
Ensure the stock item is valid.
validate_pk
python
inventree/InvenTree
src/backend/InvenTree/stock/serializers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/serializers.py
MIT
def rebuild_stock_item_tree(tree_id=None): """Rebuild the stock tree structure. The StockItem tree uses the MPTT library to manage the tree structure. """ from stock.models import StockItem if tree_id: try: StockItem.objects.partial_rebuild(tree_id) except Exception: ...
Rebuild the stock tree structure. The StockItem tree uses the MPTT library to manage the tree structure.
rebuild_stock_item_tree
python
inventree/InvenTree
src/backend/InvenTree/stock/tasks.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/tasks.py
MIT
def test_pathstring(self): """Check that pathstring updates occur as expected.""" a = StockLocation.objects.create(name='A') b = StockLocation.objects.create(name='B', parent=a) c = StockLocation.objects.create(name='C', parent=b) d = StockLocation.objects.create(name='D', parent...
Check that pathstring updates occur as expected.
test_pathstring
python
inventree/InvenTree
src/backend/InvenTree/stock/tests.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/tests.py
MIT
def test_link(self): """Test the link URL field validation.""" item = StockItem.objects.get(pk=1) # Check that invalid URLs fail for bad_url in ['test.com', 'httpx://abc.xyz', 'https:google.com']: with self.assertRaises(ValidationError): item.link = bad_url ...
Test the link URL field validation.
test_link
python
inventree/InvenTree
src/backend/InvenTree/stock/tests.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/tests.py
MIT
def test_exteneded_schema(self): """Test that extended URL schemes are allowed.""" item = StockItem.objects.get(pk=1) item.link = 'ssh://user:pwd@deb.org:223' item.save() item.full_clean()
Test that extended URL schemes are allowed.
test_exteneded_schema
python
inventree/InvenTree
src/backend/InvenTree/stock/tests.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/tests.py
MIT
def test_expiry(self): """Test expiry date functionality for StockItem model.""" today = datetime.datetime.now().date() item = StockItem.objects.create( location=self.office, part=Part.objects.get(pk=1), quantity=10 ) # Without an expiry_date set, item should not be...
Test expiry date functionality for StockItem model.
test_expiry
python
inventree/InvenTree
src/backend/InvenTree/stock/tests.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/tests.py
MIT
def test_is_building(self): """Test that the is_building flag does not count towards stock.""" part = Part.objects.get(pk=1) # Record the total stock count n = part.total_stock StockItem.objects.create(part=part, quantity=5) # And there should be *no* items being build...
Test that the is_building flag does not count towards stock.
test_is_building
python
inventree/InvenTree
src/backend/InvenTree/stock/tests.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/stock/tests.py
MIT