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 retrieve(self, request, *args, **kwargs): """Return serial number information for the referenced Part instance.""" part = self.get_object() # Calculate the "latest" serial number latest_serial = part.get_latest_serial_number() next_serial = part.get_next_serial_number() ...
Return serial number 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 get_serializer_context(self): """Add custom information to the serializer context for this endpoint.""" ctx = super().get_serializer_context() try: ctx['part'] = Part.objects.get(pk=self.kwargs.get('pk', None)) except Exception: pass return ctx
Add custom information to the serializer context for this 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 validate_valid(self, valid): """Check that the 'valid' input was flagged.""" if not valid: raise ValidationError(_('This option must be selected'))
Check that the 'valid' input was flagged.
validate_valid
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_is_revision(self, queryset, name, value): """Filter by whether the Part is a revision or not.""" if str2bool(value): return queryset.exclude(revision_of=None) return queryset.filter(revision_of=None)
Filter by whether the Part is a revision or not.
filter_is_revision
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_revisions(self, queryset, name, value): """Filter by whether the Part has any revisions or not.""" if str2bool(value): return queryset.exclude(revision_count=0) return queryset.filter(revision_count=0)
Filter by whether the Part has any revisions or not.
filter_has_revisions
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_units(self, queryset, name, value): """Filter by whether the Part has units or not.""" if str2bool(value): return queryset.exclude(Q(units=None) | Q(units='')) return queryset.filter(Q(units=None) | Q(units='')).distinct()
Filter by whether the Part has units or not.
filter_has_units
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_ipn(self, queryset, name, value): """Filter by whether the Part has an IPN (internal part number) or not.""" if str2bool(value): return queryset.exclude(IPN='') return queryset.filter(IPN='')
Filter by whether the Part has an IPN (internal part number) or not.
filter_has_ipn
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_stock(self, queryset, name, value): """Filter by whether the Part has any stock.""" if str2bool(value): return queryset.filter(Q(in_stock__gt=0)) return queryset.filter(Q(in_stock__lte=0))
Filter by whether the Part has any stock.
filter_has_stock
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_unallocated_stock(self, queryset, name, value): """Filter by whether the Part has unallocated stock.""" if str2bool(value): return queryset.filter(Q(unallocated_stock__gt=0)) return queryset.filter(Q(unallocated_stock__lte=0))
Filter by whether the Part has unallocated stock.
filter_unallocated_stock
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_pricing(self, queryset, name, value): """Filter the queryset based on whether pricing information is available for the sub_part.""" q_a = Q(pricing_data=None) q_b = Q(pricing_data__overall_min=None, pricing_data__overall_max=None) if str2bool(value): return qu...
Filter the queryset based on whether pricing information is available for the sub_part.
filter_has_pricing
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_stocktake(self, queryset, name, value): """Filter the queryset based on whether stocktake data is available.""" if str2bool(value): return queryset.exclude(last_stocktake=None) return queryset.filter(last_stocktake=None)
Filter the queryset based on whether stocktake data is available.
filter_has_stocktake
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_stock_to_build(self, queryset, name, value): """Filter the queryset based on whether part stock is required for a pending BuildOrder.""" if str2bool(value): # Return parts which are required for a build order, but have not yet been allocated return queryset.filter( ...
Filter the queryset based on whether part stock is required for a pending BuildOrder.
filter_stock_to_build
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_depleted_stock(self, queryset, name, value): """Filter the queryset based on whether the part is fully depleted of stock.""" if str2bool(value): return queryset.filter(Q(in_stock=0) & ~Q(stock_item_count=0)) return queryset.exclude(Q(in_stock=0) & ~Q(stock_item_count=0))
Filter the queryset based on whether the part is fully depleted of stock.
filter_depleted_stock
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_bom_valid(self, queryset, name, value): """Filter by whether the BOM for the part is valid or not.""" # Limit queryset to active assemblies queryset = queryset.filter(active=True, assembly=True).distinct() # Iterate through the queryset # TODO: We should cache BOM che...
Filter by whether the BOM for the part is valid or not.
filter_bom_valid
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 Part is 'starred' by the current user.""" if self.request.user.is_anonymous: return queryset starred_parts = [ star.part.pk for star in self.request.user.starred_parts.all().prefetch_re...
Filter by whether the Part 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 get_queryset(self, *args, **kwargs): """Return an annotated queryset object for the PartDetail endpoint.""" queryset = super().get_queryset(*args, **kwargs) queryset = part_serializers.PartSerializer.annotate_queryset(queryset) # Annotate with parameter template data? if st...
Return an annotated queryset object for the PartDetail 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(self, *args, **kwargs): """Return a serializer instance for this endpoint.""" # Ensure the request context is passed through kwargs['context'] = self.get_serializer_context() # Indicate that we can create a new Part via this endpoint kwargs['create'] = self.is...
Return a serializer instance for this endpoint.
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 filter_queryset(self, queryset): """Perform custom filtering of the queryset.""" params = self.request.query_params queryset = super().filter_queryset(queryset) # Exclude specific part ID values? exclude_id = [] for key in ['exclude_id', 'exclude_id[]']: ...
Perform custom filtering of the queryset.
filter_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_parametric_data(self, queryset): """Filter queryset against part parameters. Used to filter returned parts based on their parameter values. To filter based on parameter value, supply query parameters like: - parameter_<x>=<value> - parameter_<x>_gt=<value> - ...
Filter queryset against part parameters. Used to filter returned parts based on their parameter values. To filter based on parameter value, supply query parameters like: - parameter_<x>=<value> - parameter_<x>_gt=<value> - parameter_<x>_lte=<value> where: -...
filter_parametric_data
python
inventree/InvenTree
src/backend/InvenTree/part/api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py
MIT
def order_by_parameter(self, queryset): """Perform queryset ordering based on parameter value. - Used if the 'ordering' query param points to a parameter - e.g. '&ordering=param_<id>' where <id> specifies the PartParameterTemplate - Only parts which have a matching parameter are returne...
Perform queryset ordering based on parameter value. - Used if the 'ordering' query param points to a parameter - e.g. '&ordering=param_<id>' where <id> specifies the PartParameterTemplate - Only parts which have a matching parameter are returned - Queryset is ordered based on parameter ...
order_by_parameter
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): """Custom update functionality for Part instance. - If the 'starred' field is provided, update the 'starred' status against current user """ # Clean input data data = self.clean_data(request.data) if 'starred' in data: ...
Custom update functionality for Part instance. - If the 'starred' field is provided, update the 'starred' status against current user
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 get_queryset(self, *args, **kwargs): """Return an annotated queryset for the PartRelatedDetail endpoint.""" queryset = super().get_queryset(*args, **kwargs) queryset = queryset.prefetch_related('part_1', 'part_2') return queryset
Return an annotated queryset for the PartRelatedDetail 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 filter_has_choices(self, queryset, name, value): """Filter queryset to include only PartParameterTemplates with choices.""" if str2bool(value): return queryset.exclude(Q(choices=None) | Q(choices='')) return queryset.filter(Q(choices=None) | Q(choices='')).distinct()
Filter queryset to include only PartParameterTemplates with choices.
filter_has_choices
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_units(self, queryset, name, value): """Filter queryset to include only PartParameterTemplates with units.""" if str2bool(value): return queryset.exclude(Q(units=None) | Q(units='')) return queryset.filter(Q(units=None) | Q(units='')).distinct()
Filter queryset to include only PartParameterTemplates with units.
filter_has_units
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 queryset to include only PartParameterTemplates which are referenced by a part.""" parameters = PartParameter.objects.filter(part=part) template_ids = parameters.values_list('template').distinct() return queryset.filter(pk__in=[el[0]...
Filter queryset to include only PartParameterTemplates which are referenced by a 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_category(self, queryset, name, category): """Filter queryset to include only PartParameterTemplates which are referenced by parts in this category.""" cats = category.get_descendants(include_self=True) parameters = PartParameter.objects.filter(part__category__in=cats) template...
Filter queryset to include only PartParameterTemplates which are referenced by parts in this category.
filter_category
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 PartParameterTemplateDetail endpoint.""" queryset = super().get_queryset(*args, **kwargs) queryset = part_serializers.PartParameterTemplateSerializer.annotate_queryset( queryset ) retur...
Return an annotated queryset for the PartParameterTemplateDetail 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, *args, **kwargs): """Override get_queryset method to prefetch related fields.""" queryset = super().get_queryset(*args, **kwargs) queryset = queryset.prefetch_related('part', 'template') return queryset
Override get_queryset method to prefetch related fields.
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(self, *args, **kwargs): """Return the serializer instance for this API endpoint. If requested, extra detail fields are annotated to the queryset: - part_detail - template_detail """ try: kwargs['part_detail'] = str2bool(self.request.GET.get...
Return the serializer instance for this API endpoint. If requested, extra detail fields are annotated to the queryset: - part_detail - template_detail
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 filter_part(self, queryset, name, part): """Filter against the provided part. If 'include_variants' query parameter is provided, filter against variant parts also """ try: include_variants = str2bool(self.request.GET.get('include_variants', False)) except Attribu...
Filter against the provided part. If 'include_variants' query parameter is provided, filter against variant parts also
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_available_stock(self, queryset, name, value): """Filter the queryset based on whether each line item has any available stock.""" if str2bool(value): return queryset.filter(available_stock__gt=0) return queryset.filter(available_stock=0)
Filter the queryset based on whether each line item has any available stock.
filter_available_stock
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_on_order(self, queryset, name, value): """Filter the queryset based on whether each line item has any stock on order.""" if str2bool(value): return queryset.filter(on_order__gt=0) return queryset.filter(on_order=0)
Filter the queryset based on whether each line item has any stock on order.
filter_on_order
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(self, *args, **kwargs): """Return the serializer instance for this API endpoint. If requested, extra detail fields are annotated to the queryset: - part_detail - sub_part_detail """ # Do we wish to include extra detail? try: kwargs[...
Return the serializer instance for this API endpoint. If requested, extra detail fields are annotated to the queryset: - part_detail - sub_part_detail
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 the queryset object for this endpoint.""" queryset = super().get_queryset(*args, **kwargs) queryset = self.get_serializer_class().annotate_queryset(queryset) return queryset
Return the queryset object for this 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 validate_delete(self, queryset, request) -> None: """Ensure that there are no 'locked' items.""" for bom_item in queryset: # Note: Calling check_part_lock may raise a ValidationError bom_item.check_part_lock(bom_item.part)
Ensure that there are no 'locked' items.
validate_delete
python
inventree/InvenTree
src/backend/InvenTree/part/api.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/api.py
MIT
def ready(self): """This function is called whenever the Part app is loaded.""" # skip loading if plugin registry is not loaded or we run in a background thread if ( not InvenTree.ready.isPluginRegistryLoaded() or not InvenTree.ready.isInMainThread() ): ...
This function is called whenever the Part app is loaded.
ready
python
inventree/InvenTree
src/backend/InvenTree/part/apps.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/apps.py
MIT
def update_trackable_status(self): """Check for any instances where a trackable part is used in the BOM for a non-trackable part. In such a case, force the top-level part to be trackable too. """ from .models import BomItem try: items = BomItem.objects.filter( ...
Check for any instances where a trackable part is used in the BOM for a non-trackable part. In such a case, force the top-level part to be trackable too.
update_trackable_status
python
inventree/InvenTree
src/backend/InvenTree/part/apps.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/apps.py
MIT
def reset_part_pricing_flags(self): """Performed on startup, to ensure that all pricing objects are in a "good" state. Prevents issues with state machine if the server is restarted mid-update """ from .models import PartPricing if InvenTree.ready.isImportingData(): ...
Performed on startup, to ensure that all pricing objects are in a "good" state. Prevents issues with state machine if the server is restarted mid-update
reset_part_pricing_flags
python
inventree/InvenTree
src/backend/InvenTree/part/apps.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/apps.py
MIT
def annotate_in_production_quantity(reference=''): """Annotate the 'in production' quantity for each part in a queryset. Sum the 'quantity' field for all stock items which are 'in production' for each part. Arguments: reference: Reference to the part from the current queryset (default = '') ""...
Annotate the 'in production' quantity for each part in a queryset. Sum the 'quantity' field for all stock items which are 'in production' for each part. Arguments: reference: Reference to the part from the current queryset (default = '')
annotate_in_production_quantity
python
inventree/InvenTree
src/backend/InvenTree/part/filters.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/filters.py
MIT
def annotate_on_order_quantity(reference: str = ''): """Annotate the 'on order' quantity for each part in a queryset. Sum the 'remaining quantity' of each line item for any open purchase orders for each part: - Purchase order must be 'active' or 'pending' - Received quantity must be less than line ite...
Annotate the 'on order' quantity for each part in a queryset. Sum the 'remaining quantity' of each line item for any open purchase orders for each part: - Purchase order must be 'active' or 'pending' - Received quantity must be less than line item quantity Note that in addition to the 'quantity' on o...
annotate_on_order_quantity
python
inventree/InvenTree
src/backend/InvenTree/part/filters.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/filters.py
MIT
def annotate_total_stock(reference: str = '', filter: Q = None): """Annotate 'total stock' quantity against a queryset. - This function calculates the 'total stock' for a given part - Finds all stock items associated with each part (using the provided filter) - Aggregates the 'quantity' of each relevan...
Annotate 'total stock' quantity against a queryset. - This function calculates the 'total stock' for a given part - Finds all stock items associated with each part (using the provided filter) - Aggregates the 'quantity' of each relevant stock item Args: reference (str): The relationship refere...
annotate_total_stock
python
inventree/InvenTree
src/backend/InvenTree/part/filters.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/filters.py
MIT
def annotate_build_order_requirements(reference: str = ''): """Annotate the total quantity of each part required for build orders. - Only interested in 'active' build orders - We are looking for any BuildLine items which required this part (bom_item.sub_part) - We are interested in the 'quantity' of ea...
Annotate the total quantity of each part required for build orders. - Only interested in 'active' build orders - We are looking for any BuildLine items which required this part (bom_item.sub_part) - We are interested in the 'quantity' of each BuildLine item
annotate_build_order_requirements
python
inventree/InvenTree
src/backend/InvenTree/part/filters.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/filters.py
MIT
def annotate_build_order_allocations(reference: str = ''): """Annotate the total quantity of each part allocated to build orders. - This function calculates the total part quantity allocated to open build orders - Finds all build order allocations for each part (using the provided filter) - Aggregates ...
Annotate the total quantity of each part allocated to build orders. - This function calculates the total part quantity allocated to open build orders - Finds all build order allocations for each part (using the provided filter) - Aggregates the 'allocated quantity' for each relevant build order allocation ...
annotate_build_order_allocations
python
inventree/InvenTree
src/backend/InvenTree/part/filters.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/filters.py
MIT
def annotate_sales_order_requirements(reference: str = ''): """Annotate the total quantity of each part required for sales orders. - Only interested in 'active' sales orders - We are looking for any order lines which requires this part - We are interested in 'quantity'-'shipped' """ # Order fi...
Annotate the total quantity of each part required for sales orders. - Only interested in 'active' sales orders - We are looking for any order lines which requires this part - We are interested in 'quantity'-'shipped'
annotate_sales_order_requirements
python
inventree/InvenTree
src/backend/InvenTree/part/filters.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/filters.py
MIT
def annotate_sales_order_allocations(reference: str = ''): """Annotate the total quantity of each part allocated to sales orders. - This function calculates the total part quantity allocated to open sales orders" - Finds all sales order allocations for each part (using the provided filter) - Aggregates...
Annotate the total quantity of each part allocated to sales orders. - This function calculates the total part quantity allocated to open sales orders" - Finds all sales order allocations for each part (using the provided filter) - Aggregates the 'allocated quantity' for each relevant sales order allocation...
annotate_sales_order_allocations
python
inventree/InvenTree
src/backend/InvenTree/part/filters.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/filters.py
MIT
def variant_stock_query(reference: str = '', filter: Q = None): """Create a queryset to retrieve all stock items for variant parts under the specified part. - Useful for annotating a queryset with aggregated information about variant parts Args: reference: The relationship reference of the part fr...
Create a queryset to retrieve all stock items for variant parts under the specified part. - Useful for annotating a queryset with aggregated information about variant parts Args: reference: The relationship reference of the part from the current model filter: Q object which defines how to filt...
variant_stock_query
python
inventree/InvenTree
src/backend/InvenTree/part/filters.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/filters.py
MIT
def annotate_variant_quantity(subquery: Q, reference: str = 'quantity'): """Create a subquery annotation for all variant part stock items on the given parent query. Args: subquery: A 'variant_stock_query' Q object reference: The relationship reference of the variant stock items from the current...
Create a subquery annotation for all variant part stock items on the given parent query. Args: subquery: A 'variant_stock_query' Q object reference: The relationship reference of the variant stock items from the current queryset
annotate_variant_quantity
python
inventree/InvenTree
src/backend/InvenTree/part/filters.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/filters.py
MIT
def annotate_category_parts(): """Construct a queryset annotation which returns the number of parts in a particular category. - Includes parts in subcategories also - Requires subquery to perform annotation """ # Construct a subquery to provide all parts in this category and any subcategories: ...
Construct a queryset annotation which returns the number of parts in a particular category. - Includes parts in subcategories also - Requires subquery to perform annotation
annotate_category_parts
python
inventree/InvenTree
src/backend/InvenTree/part/filters.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/filters.py
MIT
def annotate_default_location(reference=''): """Construct a queryset that finds the closest default location in the part's category tree. If the part's category has its own default_location, this is returned. If not, the category tree is traversed until a value is found. """ subquery = part.models....
Construct a queryset that finds the closest default location in the part's category tree. If the part's category has its own default_location, this is returned. If not, the category tree is traversed until a value is found.
annotate_default_location
python
inventree/InvenTree
src/backend/InvenTree/part/filters.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/filters.py
MIT
def annotate_sub_categories(): """Construct a queryset annotation which returns the number of subcategories for each provided category.""" subquery = part.models.PartCategory.objects.filter( tree_id=OuterRef('tree_id'), lft__gt=OuterRef('lft'), rght__lt=OuterRef('rght'), level__g...
Construct a queryset annotation which returns the number of subcategories for each provided category.
annotate_sub_categories
python
inventree/InvenTree
src/backend/InvenTree/part/filters.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/filters.py
MIT
def filter_by_parameter(queryset, template_id: int, value: str, func: str = ''): """Filter the given queryset by a given template parameter. Parts which do not have a value for the given parameter are excluded. Arguments: queryset: A queryset of Part objects template_id (int): The ID of th...
Filter the given queryset by a given template parameter. Parts which do not have a value for the given parameter are excluded. Arguments: queryset: A queryset of Part objects template_id (int): The ID of the template parameter to filter by value (str): The value of the parameter to fil...
filter_by_parameter
python
inventree/InvenTree
src/backend/InvenTree/part/filters.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/filters.py
MIT
def order_by_parameter(queryset, template_id: int, ascending=True): """Order the given queryset by a given template parameter. Parts which do not have a value for the given parameter are ordered last. Arguments: queryset: A queryset of Part objects template_id (int): The ID of the template...
Order the given queryset by a given template parameter. Parts which do not have a value for the given parameter are ordered last. Arguments: queryset: A queryset of Part objects template_id (int): The ID of the template parameter to order by ascending (bool): Order by ascending or desc...
order_by_parameter
python
inventree/InvenTree
src/backend/InvenTree/part/filters.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/filters.py
MIT
def compile_full_name_template(*args, **kwargs): """Recompile the template for rendering the 'full_name' attribute of a Part. This function is called whenever the 'PART_NAME_FORMAT' setting is changed. """ global _part_full_name_template global _part_full_name_template_string template_string =...
Recompile the template for rendering the 'full_name' attribute of a Part. This function is called whenever the 'PART_NAME_FORMAT' setting is changed.
compile_full_name_template
python
inventree/InvenTree
src/backend/InvenTree/part/helpers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/helpers.py
MIT
def render_part_full_name(part) -> str: """Render the 'full_name' attribute of a Part. To improve render efficiency, we re-compile the template whenever the setting is changed Args: part: The Part object to render """ template = compile_full_name_template() if template: try: ...
Render the 'full_name' attribute of a Part. To improve render efficiency, we re-compile the template whenever the setting is changed Args: part: The Part object to render
render_part_full_name
python
inventree/InvenTree
src/backend/InvenTree/part/helpers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/helpers.py
MIT
def get_part_image_directory() -> str: """Return the directory where part images are stored. Returns: str: Directory where part images are stored TODO: Future work may be needed here to support other storage backends, such as S3 """ part_image_directory = os.path.abspath( os.path.j...
Return the directory where part images are stored. Returns: str: Directory where part images are stored TODO: Future work may be needed here to support other storage backends, such as S3
get_part_image_directory
python
inventree/InvenTree
src/backend/InvenTree/part/helpers.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/helpers.py
MIT
def delete(self, *args, **kwargs): """Custom model deletion routine, which updates any child categories or parts. This must be handled within a transaction.atomic(), otherwise the tree structure is damaged """ super().delete( delete_children=kwargs.get('delete_child_categori...
Custom model deletion routine, which updates any child categories or parts. This must be handled within a transaction.atomic(), otherwise the tree structure is damaged
delete
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def icon(self): """Return the icon associated with this PartCategory or the default icon.""" if self._icon: return self._icon if default_icon := get_global_setting('PART_CATEGORY_DEFAULT_ICON', cache=True): return default_icon return ''
Return the icon associated with this PartCategory or the default icon.
icon
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def clean(self): """Custom clean action for the PartCategory model. Ensure that the structural parameter cannot get set if products already assigned to the category """ if self.pk and self.structural and self.partcount(False, False) > 0: raise ValidationError( ...
Custom clean action for the PartCategory model. Ensure that the structural parameter cannot get set if products already assigned to the category
clean
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def get_parts(self, cascade=True) -> set[Part]: """Return a queryset for all parts under this category. Args: cascade (bool, optional): If True, also look under subcategories. Defaults to True. Returns: set[Part]: All matching parts """ if cascade: ...
Return a queryset for all parts under this category. Args: cascade (bool, optional): If True, also look under subcategories. Defaults to True. Returns: set[Part]: All matching parts
get_parts
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def partcount(self, cascade=True, active=False): """Return the total part count under this category (including children of child categories).""" query = self.get_parts(cascade=cascade) if active: query = query.filter(active=True) return query.count()
Return the total part count under this category (including children of child categories).
partcount
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def get_unique_parameters(self, cascade=True, prefetch=None): """Get all unique parameter names for all parts from this category.""" unique_parameters_names = [] parts = prefetch or self.prefetch_parts_parameters(cascade=cascade) for part in parts: for parameter in part.par...
Get all unique parameter names for all parts from this category.
get_unique_parameters
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def get_parts_parameters(self, cascade=True, prefetch=None): """Get all parameter names and values for all parts from this category.""" category_parameters = [] parts = prefetch or self.prefetch_parts_parameters(cascade=cascade) for part in parts: part_parameters = { ...
Get all parameter names and values for all parts from this category.
get_parts_parameters
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def get_parent_categories(cls): """Return tuple list of parent (root) categories.""" # Get root nodes root_categories = cls.objects.filter(level=0) parent_categories = [] for category in root_categories: parent_categories.append((category.id, category.name)) ...
Return tuple list of parent (root) categories.
get_parent_categories
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def get_parameter_templates(self): """Return parameter templates associated to category.""" prefetch = PartCategoryParameterTemplate.objects.prefetch_related( 'category', 'parameter_template' ) return prefetch.filter(category=self.id)
Return parameter templates associated to category.
get_parameter_templates
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def get_subscribers(self, include_parents: bool = True) -> list[User]: """Return a list of users who subscribe to this PartCategory. Arguments: include_parents (bool): If True, include users who subscribe to parent categories. Returns: list[User]: List of users who subs...
Return a list of users who subscribe to this PartCategory. Arguments: include_parents (bool): If True, include users who subscribe to parent categories. Returns: list[User]: List of users who subscribe to this category.
get_subscribers
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def set_starred(self, user, status: bool, **kwargs) -> None: """Set the "subscription" status of this PartCategory against the specified user.""" if not user: return if self.is_starred_by(user, **kwargs) == status: return if status: PartCategoryStar....
Set the "subscription" status of this PartCategory against the specified user.
set_starred
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def rename_part_image(instance, filename): """Function for renaming a part image file. Args: instance: Instance of a Part object filename: Name of original uploaded file Returns: Cleaned filename in format part_<n>_img """ base = part_helpers.PART_IMAGE_DIR fname = os.p...
Function for renaming a part image file. Args: instance: Instance of a Part object filename: Name of original uploaded file Returns: Cleaned filename in format part_<n>_img
rename_part_image
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def get_queryset(self): """Perform default prefetch operations when accessing Part model from the database.""" return ( super() .get_queryset() .prefetch_related( 'category', 'pricing_data', 'category__parent', ...
Perform default prefetch operations when accessing Part model from the database.
get_queryset
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def delete(self, **kwargs): """Custom delete method for the Part model. Prevents deletion of a Part if any of the following conditions are met: - The part is still active - The part is used in a BOM for a different part. """ if self.locked: raise ValidationE...
Custom delete method for the Part model. Prevents deletion of a Part if any of the following conditions are met: - The part is still active - The part is used in a BOM for a different part.
delete
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def save(self, *args, **kwargs): """Overrides the save function for the Part model. If the part image has been updated, then check if the "old" (previous) image is still used by another part. If not, it is considered "orphaned" and will be deleted. """ _new = False if se...
Overrides the save function for the Part model. If the part image has been updated, then check if the "old" (previous) image is still used by another part. If not, it is considered "orphaned" and will be deleted.
save
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def get_parts_in_bom(self, **kwargs): """Return a list of all parts in the BOM for this part. Takes into account substitutes, variant parts, and inherited BOM items """ parts = set() for bom_item in self.get_bom_items(**kwargs): for part in bom_item.get_valid_parts_...
Return a list of all parts in the BOM for this part. Takes into account substitutes, variant parts, and inherited BOM items
get_parts_in_bom
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def check_add_to_bom(self, parent, raise_error=False, recursive=True): """Check if this Part can be added to the BOM of another part. This will fail if: a) The parent part is the same as this one b) The parent part exists in the same variant tree as this one c) The parent part ...
Check if this Part can be added to the BOM of another part. This will fail if: a) The parent part is the same as this one b) The parent part exists in the same variant tree as this one c) The parent part is used in the BOM for *this* part d) The parent part is used in the BOM f...
check_add_to_bom
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def validate_name(self, raise_error=True): """Validate the name field for this Part instance. This function is exposed to any Validation plugins, and thus can be customized. """ from plugin import PluginMixinEnum, registry for plugin in registry.with_mixin(PluginMixinEnum.VALID...
Validate the name field for this Part instance. This function is exposed to any Validation plugins, and thus can be customized.
validate_name
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def validate_ipn(self, raise_error=True): """Ensure that the IPN (internal part number) is valid for this Part". - Validation is handled by custom plugins - By default, no validation checks are performed """ from plugin import PluginMixinEnum, registry for plugin in reg...
Ensure that the IPN (internal part number) is valid for this Part". - Validation is handled by custom plugins - By default, no validation checks are performed
validate_ipn
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def validate_serial_number( self, serial: str, stock_item=None, check_duplicates=True, raise_error=False, **kwargs, ): """Validate a serial number against this Part instance. Note: This function is exposed to any Validation plugins, and thus can be cu...
Validate a serial number against this Part instance. Note: This function is exposed to any Validation plugins, and thus can be customized. Any plugins which implement the 'validate_serial_number' method have three possible outcomes: - Decide the serial is objectionable and raise a django.core...
validate_serial_number
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def find_conflicting_serial_numbers(self, serials: list) -> list: """For a provided list of serials, return a list of those which are conflicting.""" from part.models import Part from stock.models import StockItem conflicts = [] # First, check for raw conflicts based on efficie...
For a provided list of serials, return a list of those which are conflicting.
find_conflicting_serial_numbers
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def get_latest_serial_number(self, allow_plugins=True): """Find the 'latest' serial number for this Part. Here we attempt to find the "highest" serial number which exists for this Part. There are a number of edge cases where this method can fail, but this is accepted to keep database pe...
Find the 'latest' serial number for this Part. Here we attempt to find the "highest" serial number which exists for this Part. There are a number of edge cases where this method can fail, but this is accepted to keep database performance at a reasonable level. Note: Serial numbers must...
get_latest_serial_number
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def get_next_serial_number(self): """Return the 'next' serial number in sequence.""" sn = self.get_latest_serial_number() return InvenTree.helpers.increment_serial_number(sn, self)
Return the 'next' serial number in sequence.
get_next_serial_number
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def get_image_url(self): """Return the URL of the image for this part.""" if self.image: return helpers.getMediaUrl(self.image.url) return helpers.getBlankImage()
Return the URL of the image for this part.
get_image_url
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def get_thumbnail_url(self) -> str: """Return the URL of the image thumbnail for this part.""" if self.image: return helpers.getMediaUrl(self.image.thumbnail.url) return helpers.getBlankThumbnail()
Return the URL of the image thumbnail for this part.
get_thumbnail_url
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def validate_unique(self, exclude=None): """Validate that this Part instance is 'unique'. Uniqueness is checked across the following (case insensitive) fields: - Name - IPN - Revision e.g. there can exist multiple parts with the same name, but only if they have ...
Validate that this Part instance is 'unique'. Uniqueness is checked across the following (case insensitive) fields: - Name - IPN - Revision e.g. there can exist multiple parts with the same name, but only if they have a different revision or internal part number. ...
validate_unique
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def clean(self): """Perform cleaning operations for the Part model. - Check if the PartCategory is not structural - Update trackable status: If this part is trackable, and it is used in the BOM for a parent part which is *not* trackable, then we will force t...
Perform cleaning operations for the Part model. - Check if the PartCategory is not structural - Update trackable status: If this part is trackable, and it is used in the BOM for a parent part which is *not* trackable, then we will force the parent part to be trackab...
clean
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def ensure_trackable(self): """Ensure that trackable is set correctly downline.""" if self.trackable: for part in self.get_used_in(): if not part.trackable: part.trackable = True part.clean() part.save()
Ensure that trackable is set correctly downline.
ensure_trackable
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def get_default_location(self): """Get the default location for a Part (may be None). If the Part does not specify a default location, look at the Category this part is in. The PartCategory object may also specify a default stock location """ if self.default_location: ...
Get the default location for a Part (may be None). If the Part does not specify a default location, look at the Category this part is in. The PartCategory object may also specify a default stock location
get_default_location
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def get_default_supplier(self): """Get the default supplier part for this part (may be None). - If the part specifies a default_supplier, return that - If there is only one supplier part available, return that - Else, return None """ if self.default_supplier: ...
Get the default supplier part for this part (may be None). - If the part specifies a default_supplier, return that - If there is only one supplier part available, return that - Else, return None
get_default_supplier
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def category_path(self): """Return the category path of this Part instance.""" if self.category: return self.category.pathstring return ''
Return the category path of this Part instance.
category_path
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def available_stock(self): """Return the total available stock. - This subtracts stock which is already allocated to builds """ total = self.total_stock total -= self.allocation_count() return max(total, 0)
Return the total available stock. - This subtracts stock which is already allocated to builds
available_stock
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def requiring_build_orders(self): """Return list of outstanding build orders which require this part.""" # List parts that this part is required for # Now, get a list of outstanding build orders which require this part builds = BuildModels.Build.objects.filter( part__in=self...
Return list of outstanding build orders which require this part.
requiring_build_orders
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def required_build_order_quantity(self): """Return the quantity of this part required for active build orders.""" # List active build orders which reference this part builds = self.requiring_build_orders() quantity = 0 for build in builds: bom_item = None ...
Return the quantity of this part required for active build orders.
required_build_order_quantity
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def requiring_sales_orders(self): """Return a list of sales orders which require this part.""" orders = set() # Get a list of line items for open orders which match this part open_lines = OrderModels.SalesOrderLineItem.objects.filter( order__status__in=SalesOrderStatusGroups...
Return a list of sales orders which require this part.
requiring_sales_orders
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def required_sales_order_quantity(self): """Return the quantity of this part required for active sales orders.""" # Get a list of line items for open orders which match this part open_lines = OrderModels.SalesOrderLineItem.objects.filter( order__status__in=SalesOrderStatusGroups.OPEN...
Return the quantity of this part required for active sales orders.
required_sales_order_quantity
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def required_order_quantity(self): """Return total required to fulfil orders.""" return ( self.required_build_order_quantity() + self.required_sales_order_quantity() )
Return total required to fulfil orders.
required_order_quantity
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def quantity_to_order(self): """Return the quantity needing to be ordered for this part. Here, an "order" could be one of: - Build Order - Sales Order To work out how many we need to order: Stock on hand = self.total_stock Required for orders = self.required_or...
Return the quantity needing to be ordered for this part. Here, an "order" could be one of: - Build Order - Sales Order To work out how many we need to order: Stock on hand = self.total_stock Required for orders = self.required_order_quantity() Currently on orde...
quantity_to_order
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def get_subscribers( self, include_variants: bool = True, include_categories: bool = True ) -> list[User]: """Return a list of users who are 'subscribed' to this part. Arguments: include_variants: If True, include users who are subscribed to a variant part include_ca...
Return a list of users who are 'subscribed' to this part. Arguments: include_variants: If True, include users who are subscribed to a variant part include_categories: If True, include users who are subscribed to the category Returns: list[User]: A list of users who ...
get_subscribers
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def set_starred(self, user, status, **kwargs): """Set the "subscription" status of this Part against the specified user.""" if not user: return # Already subscribed? if self.is_starred_by(user, **kwargs) == status: return if status: PartStar....
Set the "subscription" status of this Part against the specified user.
set_starred
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def can_build(self): """Return the number of units that can be build with available stock.""" import part.filters # If this part does NOT have a BOM, result is simply the currently available stock if not self.has_bom: return 0 total = None # Prefetch relate...
Return the number of units that can be build with available stock.
can_build
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def quantity_being_built(self): """Return the current number of parts currently being built. Note: This is the total quantity of Build orders, *not* the number of build outputs. In this fashion, it is the "projected" quantity of builds """ builds = self.active_builds ...
Return the current number of parts currently being built. Note: This is the total quantity of Build orders, *not* the number of build outputs. In this fashion, it is the "projected" quantity of builds
quantity_being_built
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def build_order_allocations(self, **kwargs): """Return all 'BuildItem' objects which allocate this part to Build objects.""" include_variants = kwargs.get('include_variants', True) queryset = BuildModels.BuildItem.objects.all() if include_variants: variants = self.get_desce...
Return all 'BuildItem' objects which allocate this part to Build objects.
build_order_allocations
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def build_order_allocation_count(self, **kwargs): """Return the total amount of this part allocated to build orders.""" query = self.build_order_allocations(**kwargs).aggregate( total=Coalesce( Sum('quantity', output_field=models.DecimalField()), 0, ...
Return the total amount of this part allocated to build orders.
build_order_allocation_count
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT
def sales_order_allocations(self, **kwargs): """Return all sales-order-allocation objects which allocate this part to a SalesOrder.""" include_variants = kwargs.get('include_variants', True) queryset = OrderModels.SalesOrderAllocation.objects.all() if include_variants: # In...
Return all sales-order-allocation objects which allocate this part to a SalesOrder.
sales_order_allocations
python
inventree/InvenTree
src/backend/InvenTree/part/models.py
https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py
MIT