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 sales_order_allocation_count(self, **kwargs):
"""Return the total quantity of this part allocated to sales orders."""
query = self.sales_order_allocations(**kwargs).aggregate(
total=Coalesce(
Sum('quantity', output_field=models.DecimalField()),
0,
... | Return the total quantity of this part allocated to sales orders. | sales_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 allocation_count(self, **kwargs):
"""Return the total quantity of stock allocated for this part, against both build orders and sales orders."""
if self.id is None:
# If this instance has not been saved, foreign-key lookups will fail
return 0
return sum([
... | Return the total quantity of stock allocated for this part, against both build orders and sales orders. | 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 stock_entries(self, include_variants=True, in_stock=None, location=None):
"""Return all stock entries for this Part.
Arguments:
include_variants: If True, include stock entries for all part variants
in_stock: If True, filter by stock entries which are 'in stock'
... | Return all stock entries for this Part.
Arguments:
include_variants: If True, include stock entries for all part variants
in_stock: If True, filter by stock entries which are 'in stock'
location: If set, filter by stock entries in the specified location
| stock_entries | 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_stock_count(self, include_variants=True):
"""Return the total "in stock" count for this part."""
entries = self.stock_entries(in_stock=True, include_variants=include_variants)
query = entries.aggregate(t=Coalesce(Sum('quantity'), Decimal(0)))
return query['t'] | Return the total "in stock" count for this part. | get_stock_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 get_bom_item_filter(self, include_inherited=True):
"""Returns a query filter for all BOM items associated with this Part.
There are some considerations:
a) BOM items can be defined against *this* part
b) BOM items can be inherited from a *parent* part
We will construct a f... | Returns a query filter for all BOM items associated with this Part.
There are some considerations:
a) BOM items can be defined against *this* part
b) BOM items can be inherited from a *parent* part
We will construct a filter to grab *all* the BOM items!
Note: This does *not* ... | get_bom_item_filter | 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_bom_items(self, include_inherited=True) -> QuerySet[BomItem]:
"""Return a queryset containing all BOM items for this part.
By default, will include inherited BOM items
"""
queryset = BomItem.objects.filter(
self.get_bom_item_filter(include_inherited=include_inherited... | Return a queryset containing all BOM items for this part.
By default, will include inherited BOM items
| get_bom_items | 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_used_in(self, include_inherited=True, include_substitutes=True):
"""Return a list containing all parts this part is used in.
Includes consideration of inherited BOMs
"""
# Grab a queryset of all BomItem objects which "require" this part
bom_items = BomItem.objects.filter... | Return a list containing all parts this part is used in.
Includes consideration of inherited BOMs
| get_used_in | 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_trackable_parts(self):
"""Return a queryset of all trackable parts in the BOM for this part."""
queryset = self.get_bom_items()
queryset = queryset.filter(sub_part__trackable=True)
return queryset | Return a queryset of all trackable parts in the BOM for this part. | get_trackable_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 get_bom_hash(self):
"""Return a checksum hash for the BOM for this part.
Used to determine if the BOM has changed (and needs to be signed off!)
The hash is calculated by hashing each line item in the BOM. Returns a string representation of a hash object which can be compared with a stored v... | Return a checksum hash for the BOM for this part.
Used to determine if the BOM has changed (and needs to be signed off!)
The hash is calculated by hashing each line item in the BOM. Returns a string representation of a hash object which can be compared with a stored value
| get_bom_hash | 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_bom(self, user):
"""Validate the BOM (mark the BOM as validated by the given User.
- Calculates and stores the hash for the BOM
- Saves the current date and the checking user
"""
# Validate each line item, ignoring inherited ones
bom_items = self.get_bom_ite... | Validate the BOM (mark the BOM as validated by the given User.
- Calculates and stores the hash for the BOM
- Saves the current date and the checking user
| validate_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 getRequiredParts(self, recursive=False, parts=None):
"""Return a list of parts required to make this part (i.e. BOM items).
Args:
recursive: If True iterate down through sub-assemblies
parts: Set of parts already found (to prevent recursion issues)
"""
if par... | Return a list of parts required to make this part (i.e. BOM items).
Args:
recursive: If True iterate down through sub-assemblies
parts: Set of parts already found (to prevent recursion issues)
| getRequiredParts | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def pricing(self):
"""Return the PartPricing information for this Part instance.
If there is no PartPricing database entry defined for this Part,
it will first be created, and then returned.
"""
try:
pricing = PartPricing.objects.get(part=self)
except PartPri... | Return the PartPricing information for this Part instance.
If there is no PartPricing database entry defined for this Part,
it will first be created, and then returned.
| pricing | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def schedule_pricing_update(self, create: bool = False):
"""Helper function to schedule a pricing update.
Importantly, catches any errors which may occur during deletion of related objects,
in particular due to post_delete signals.
Ref: https://github.com/inventree/InvenTree/pull/3986
... | Helper function to schedule a pricing update.
Importantly, catches any errors which may occur during deletion of related objects,
in particular due to post_delete signals.
Ref: https://github.com/inventree/InvenTree/pull/3986
Arguments:
create: Whether or not a new PartPri... | schedule_pricing_update | 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_price_info(self, quantity=1, buy=True, bom=True, internal=False):
"""Return a simplified pricing string for this part.
Args:
quantity: Number of units to calculate price for
buy: Include supplier pricing (default = True)
bom: Include BOM pricing (default = Tr... | Return a simplified pricing string for this part.
Args:
quantity: Number of units to calculate price for
buy: Include supplier pricing (default = True)
bom: Include BOM pricing (default = True)
internal: Include internal pricing (default = False)
| get_price_info | 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_supplier_price_range(self, quantity=1):
"""Return the supplier price range of this part.
Actions:
- Checks if there is any supplier pricing information associated with this Part
- Iterate through available supplier pricing and select (min, max)
- Returns tuple of (min, m... | Return the supplier price range of this part.
Actions:
- Checks if there is any supplier pricing information associated with this Part
- Iterate through available supplier pricing and select (min, max)
- Returns tuple of (min, max)
Arguments:
quantity: Quantity at w... | get_supplier_price_range | 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_bom_price_range(self, quantity=1, internal=False, purchase=False):
"""Return the price range of the BOM for this part.
Adds the minimum price for all components in the BOM.
Note: If the BOM contains items without pricing information,
these items cannot be included in the BOM!
... | Return the price range of the BOM for this part.
Adds the minimum price for all components in the BOM.
Note: If the BOM contains items without pricing information,
these items cannot be included in the BOM!
| get_bom_price_range | 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_price_range(
self, quantity=1, buy=True, bom=True, internal=False, purchase=False
):
"""Return the price range for this part.
This price can be either:
- Supplier price (if purchased from suppliers)
- BOM price (if built from other parts)
- Internal price (if... | Return the price range for this part.
This price can be either:
- Supplier price (if purchased from suppliers)
- BOM price (if built from other parts)
- Internal price (if set for the part)
- Purchase price (if set for the part)
Returns:
Minimum of the suppl... | get_price_range | 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_internal_price(self, quantity, moq=True, multiples=True, currency=None):
"""Return the internal price of this Part at the specified quantity."""
return common.currency.get_price(
self, quantity, moq, multiples, currency, break_name='internal_price_breaks'
) | Return the internal price of this Part at the specified quantity. | get_internal_price | 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_purchase_price(self, quantity):
"""Calculate the purchase price for this part at the specified quantity.
- Looks at available supplier pricing data
- Calculates the price base on the closest price point
"""
currency = currency_code_default()
try:
pric... | Calculate the purchase price for this part at the specified quantity.
- Looks at available supplier pricing data
- Calculates the price base on the closest price point
| get_purchase_price | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def copy_bom_from(self, other, clear=True, **kwargs):
"""Copy the BOM from another part.
Args:
other: The part to copy the BOM from
clear (bool, optional): Remove existing BOM items first. Defaults to True.
"""
# Ignore if the other part is actually this part?
... | Copy the BOM from another part.
Args:
other: The part to copy the BOM from
clear (bool, optional): Remove existing BOM items first. Defaults to True.
| copy_bom_from | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def copy_parameters_from(self, other, **kwargs):
"""Copy all parameter values from another Part instance."""
clear = kwargs.get('clear', True)
if clear:
self.get_parameters().delete()
for parameter in other.get_parameters():
# If this part already has a paramete... | Copy all parameter values from another Part instance. | copy_parameters_from | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def getTestTemplates(
self, required=None, include_parent: bool = True, enabled=None
) -> QuerySet[PartTestTemplate]:
"""Return a list of all test templates associated with this Part.
These are used for validation of a StockItem.
Args:
required (bool, optional): Filter... | Return a list of all test templates associated with this Part.
These are used for validation of a StockItem.
Args:
required (bool, optional): Filter templates by whether they are required. Defaults to None.
include_parent (bool, optional): Include templates from parent parts. ... | getTestTemplates | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def getTestTemplateMap(self, **kwargs):
"""Return a map of all test templates associated with this Part."""
templates = {}
for template in self.getTestTemplates(**kwargs):
templates[template.key] = template
return templates | Return a map of all test templates associated with this Part. | getTestTemplateMap | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def getRequiredTests(self, include_parent=True, enabled=True):
"""Return the tests which are required by this part.
Arguments:
include_parent: If True, include tests which are defined for parent parts
enabled: If set (either True or False), filter by template "enabled" status
... | Return the tests which are required by this part.
Arguments:
include_parent: If True, include tests which are defined for parent parts
enabled: If set (either True or False), filter by template "enabled" status
| getRequiredTests | 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_orders(self):
"""Return a list of sales orders which reference this part."""
orders = []
for line in self.sales_order_line_items.all().prefetch_related('order'):
if line.order not in orders:
orders.append(line.order)
return orders | Return a list of sales orders which reference this part. | 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 purchase_orders(self):
"""Return a list of purchase orders which reference this part."""
orders = []
for part in self.supplier_parts.all().prefetch_related(
'purchase_order_line_items'
):
for order in part.purchase_orders():
if order not in or... | Return a list of purchase orders which reference this part. | purchase_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 on_order(self):
"""Return the total number of items on order for this part.
Note that some supplier parts may have a different pack_quantity attribute,
and this needs to be taken into account!
"""
quantity = 0
# Iterate through all supplier parts
for sp in s... | Return the total number of items on order for this part.
Note that some supplier parts may have a different pack_quantity attribute,
and this needs to be taken into account!
| on_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_parameter(self, name):
"""Return the parameter with the given name.
If no matching parameter is found, return None.
"""
try:
return self.parameters.get(template__name=name)
except PartParameter.DoesNotExist:
return None | Return the parameter with the given name.
If no matching parameter is found, return None.
| get_parameter | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def parameters_map(self):
"""Return a map (dict) of parameter values associated with this Part instance, of the form.
Example:
{
"name_1": "value_1",
"name_2": "value_2",
}
"""
params = {}
for parameter in self.parameters.all():
... | Return a map (dict) of parameter values associated with this Part instance, of the form.
Example:
{
"name_1": "value_1",
"name_2": "value_2",
}
| parameters_map | 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_conversion_options(self):
"""Return options for converting this part to a "variant" within the same tree.
a) Variants underneath this one
b) Immediate parent
c) Siblings
"""
parts = []
# Child parts
children = self.get_descendants(include_self=Fa... | Return options for converting this part to a "variant" within the same tree.
a) Variants underneath this one
b) Immediate parent
c) Siblings
| get_conversion_options | 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_related_parts(self):
"""Return a set of all related parts for this part."""
related_parts = set()
related_parts_1 = self.related_parts_1.filter(part_1__id=self.pk)
related_parts_2 = self.related_parts_2.filter(part_2__id=self.pk)
for related_part in related_parts_1:
... | Return a set of all related parts for this part. | get_related_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 after_save_part(sender, instance: Part, created, **kwargs):
"""Function to be executed after a Part is saved."""
from django.conf import settings
from part import tasks as part_tasks
if instance and not created and not InvenTree.ready.isImportingData():
# Check part stock only if we are *u... | Function to be executed after a Part is saved. | after_save_part | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def convert(self, money):
"""Attempt to convert money value to default currency.
If a MissingRate error is raised, ignore it and return None
"""
if money is None:
return None
target_currency = currency_code_default()
try:
result = convert_money(... | Attempt to convert money value to default currency.
If a MissingRate error is raised, ignore it and return None
| convert | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def schedule_for_update(self, counter: int = 0):
"""Schedule this pricing to be updated."""
import InvenTree.ready
# If importing data, skip pricing update
if InvenTree.ready.isImportingData():
return
# If running data migrations, skip pricing update
if Inve... | Schedule this pricing to be updated. | schedule_for_update | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def update_pricing(
self,
counter: int = 0,
cascade: bool = True,
previous_min=None,
previous_max=None,
):
"""Recalculate all cost data for the referenced Part instance.
Arguments:
counter: Recursion counter (used to prevent infinite recursion)
... | Recalculate all cost data for the referenced Part instance.
Arguments:
counter: Recursion counter (used to prevent infinite recursion)
cascade: If True, update pricing for all assemblies and templates which use this part
previous_min: Previous minimum price (used to prevent ... | update_pricing | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def update_assemblies(self, counter: int = 0):
"""Schedule updates for any assemblies which use this part."""
# If the linked Part is used in any assemblies, schedule a pricing update for those assemblies
used_in_parts = self.part.get_used_in()
for p in used_in_parts:
p.pri... | Schedule updates for any assemblies which use this part. | update_assemblies | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def update_templates(self, counter: int = 0):
"""Schedule updates for any template parts above this part."""
templates = self.part.get_ancestors(include_self=False)
for p in templates:
p.pricing.schedule_for_update(counter + 1) | Schedule updates for any template parts above this part. | update_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 save(self, *args, **kwargs):
"""Whenever pricing model is saved, automatically update overall prices."""
# Update the currency which was used to perform the calculation
self.currency = currency_code_default()
try:
self.update_overall_cost()
except Exception:
... | Whenever pricing model is saved, automatically update overall prices. | 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 update_bom_cost(self, save=True):
"""Recalculate BOM cost for the referenced Part instance.
Iterate through the Bill of Materials, and calculate cumulative pricing:
cumulative_min: The sum of minimum costs for each line in the BOM
cumulative_max: The sum of maximum costs for each l... | Recalculate BOM cost for the referenced Part instance.
Iterate through the Bill of Materials, and calculate cumulative pricing:
cumulative_min: The sum of minimum costs for each line in the BOM
cumulative_max: The sum of maximum costs for each line in the BOM
Note: The cumulative cost... | update_bom_cost | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def update_purchase_cost(self, save=True):
"""Recalculate historical purchase cost for the referenced Part instance.
Purchase history only takes into account "completed" purchase orders.
"""
# Find all line items for completed orders which reference this part
line_items = OrderM... | Recalculate historical purchase cost for the referenced Part instance.
Purchase history only takes into account "completed" purchase orders.
| update_purchase_cost | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def update_internal_cost(self, save=True):
"""Recalculate internal cost for the referenced Part instance."""
min_int_cost = None
max_int_cost = None
if get_global_setting('PART_INTERNAL_PRICE', False):
# Only calculate internal pricing if internal pricing is enabled
... | Recalculate internal cost for the referenced Part instance. | update_internal_cost | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def update_variant_cost(self, save=True):
"""Update variant cost values.
Here we track the min/max costs of any variant parts.
"""
variant_min = None
variant_max = None
active_only = get_global_setting('PRICING_ACTIVE_VARIANTS', False)
if self.part.is_template:... | Update variant cost values.
Here we track the min/max costs of any variant parts.
| update_variant_cost | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def update_overall_cost(self):
"""Update overall cost values.
Here we simply take the minimum / maximum values of the other calculated fields.
"""
overall_min = None
overall_max = None
min_costs = [self.bom_cost_min, self.purchase_cost_min, self.internal_cost_min]
... | Update overall cost values.
Here we simply take the minimum / maximum values of the other calculated fields.
| update_overall_cost | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def update_last_stocktake(sender, instance, created, **kwargs):
"""Callback function when a PartStocktake instance is created / edited."""
# When a new PartStocktake instance is create, update the last_stocktake date for the Part
if created:
try:
part = instance.part
part.las... | Callback function when a PartStocktake instance is created / edited. | update_last_stocktake | 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_stocktake_report(instance, filename):
"""Save stocktake reports to the correct subdirectory."""
filename = os.path.basename(filename)
return os.path.join('stocktake', 'report', filename) | Save stocktake reports to the correct subdirectory. | save_stocktake_report | 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_absolute_url(self):
"""Return the URL for the associated report file for download."""
if self.report:
return self.report.url
return None | Return the URL for the associated report file for download. | get_absolute_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 clean(self):
"""Clean fields for the PartTestTemplate model."""
self.test_name = self.test_name.strip()
self.key = helpers.generateTestKey(self.test_name)
if len(self.key) == 0:
raise ValidationError({
'test_name': _(
'Invalid templat... | Clean fields for the PartTestTemplate model. | 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 validate_unique(self, exclude=None):
"""Test that this test template is 'unique' within this part tree."""
if not self.part.testable:
raise ValidationError({
'part': _('Test templates can only be created for testable parts')
})
# Check that this test ... | Test that this test template is 'unique' within this part tree. | 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 get_choices(self):
"""Return a list of valid choices for this test template."""
if not self.choices:
return []
return [x.strip() for x in self.choices.split(',') if x.strip()] | Return a list of valid choices for this test template. | get_choices | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def __str__(self):
"""Return a string representation of a PartParameterTemplate instance."""
s = str(self.name)
if self.units:
s += f' ({self.units})'
return s | Return a string representation of a PartParameterTemplate instance. | __str__ | 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 cleaning step for this model.
Checks:
- A 'checkbox' field cannot have 'choices' set
- A 'checkbox' field cannot have 'units' set
"""
super().clean()
# Check that checkbox parameters do not have units or choices
if self.checkbo... | Custom cleaning step for this model.
Checks:
- A 'checkbox' field cannot have 'choices' set
- A 'checkbox' field cannot have 'units' set
| 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 validate_unique(self, exclude=None):
"""Ensure that PartParameterTemplates cannot be created with the same name.
This test should be case-insensitive (which the unique caveat does not cover).
"""
super().validate_unique(exclude)
try:
others = PartParameterTempla... | Ensure that PartParameterTemplates cannot be created with the same name.
This test should be case-insensitive (which the unique caveat does not cover).
| 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 get_choices(self):
"""Return a list of choices for this parameter template."""
if self.selectionlist:
return self.selectionlist.get_choices()
if not self.choices:
return []
return [x.strip() for x in self.choices.split(',') if x.strip()] | Return a list of choices for this parameter template. | get_choices | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def post_save_part_parameter_template(sender, instance, created, **kwargs):
"""Callback function when a PartParameterTemplate is created or saved."""
import part.tasks as part_tasks
if InvenTree.ready.canAppAccessDatabase() and not InvenTree.ready.isImportingData():
if not created:
# Sc... | Callback function when a PartParameterTemplate is created or saved. | post_save_part_parameter_template | 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_part_lock(self):
"""Check if the referenced part is locked."""
# TODO: Potentially control this behaviour via a global setting
if self.part.locked:
raise ValidationError(_('Parameter cannot be modified - part is locked')) | Check if the referenced part is locked. | check_part_lock | 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):
"""Custom save method for the PartParameter model."""
# Validate the PartParameter before saving
self.calculate_numeric_value()
# Check if the part is locked
self.check_part_lock()
# Convert 'boolean' values to 'True' / 'False'
i... | Custom save method for the PartParameter model. | 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 clean(self):
"""Validate the PartParameter before saving to the database."""
super().clean()
# Validate the parameter data against the template units
if (
get_global_setting(
'PART_PARAMETER_ENFORCE_UNITS', True, cache=False, create=False
)
... | Validate the PartParameter before saving to the database. | 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 calculate_numeric_value(self):
"""Calculate a numeric value for the parameter data.
- If a 'units' field is provided, then the data will be converted to the base SI unit.
- Otherwise, we'll try to do a simple float cast
"""
if self.template.units:
try:
... | Calculate a numeric value for the parameter data.
- If a 'units' field is provided, then the data will be converted to the base SI unit.
- Otherwise, we'll try to do a simple float cast
| calculate_numeric_value | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def create(cls, part, template, data, save=False):
"""Custom save method for the PartParameter class."""
part_parameter = cls(part=part, template=template, data=data)
if save:
part_parameter.save()
return part_parameter | Custom save method for the PartParameter class. | create | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def __str__(self):
"""String representation of a PartCategoryParameterTemplate (admin interface)."""
if self.default_value:
return f'{self.category.name} | {self.parameter_template.name} | {self.default_value}'
return f'{self.category.name} | {self.parameter_template.name}' | String representation of a PartCategoryParameterTemplate (admin interface). | __str__ | 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):
"""Validate this PartCategoryParameterTemplate instance.
Checks the provided 'default_value', and (if not blank), ensure it is valid.
"""
super().clean()
self.default_value = (
'' if self.default_value is None else str(self.default_value.strip())
... | Validate this PartCategoryParameterTemplate instance.
Checks the provided 'default_value', and (if not blank), ensure it is valid.
| 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 check_part_lock(self, assembly):
"""When editing or deleting a BOM item, check if the assembly is locked.
If locked, raise an exception.
Arguments:
assembly: The assembly part
Raises:
ValidationError: If the assembly is locked
"""
# TODO: Pe... | When editing or deleting a BOM item, check if the assembly is locked.
If locked, raise an exception.
Arguments:
assembly: The assembly part
Raises:
ValidationError: If the assembly is locked
| check_part_lock | 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_item_hash(self):
"""Calculate the checksum hash of this BOM line item.
The hash is calculated from the following fields:
- part.pk
- sub_part.pk
- quantity
- reference
- optional
- inherited
- consumable
- allow_variants
""... | Calculate the checksum hash of this BOM line item.
The hash is calculated from the following fields:
- part.pk
- sub_part.pk
- quantity
- reference
- optional
- inherited
- consumable
- allow_variants
| get_item_hash | 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_hash(self, valid=True):
"""Mark this item as 'valid' (store the checksum hash).
Args:
valid: If true, validate the hash, otherwise invalidate it (default = True)
"""
if valid:
self.checksum = self.get_item_hash()
else:
self.checks... | Mark this item as 'valid' (store the checksum hash).
Args:
valid: If true, validate the hash, otherwise invalidate it (default = True)
| validate_hash | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def is_line_valid(self):
"""Check if this line item has been validated by the user."""
# Ensure an empty checksum returns False
if len(self.checksum) == 0:
return False
return self.get_item_hash() == self.checksum | Check if this line item has been validated by the user. | is_line_valid | 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_required_quantity(self, build_quantity):
"""Calculate the required part quantity, based on the supplier build_quantity. Includes overage estimate in the returned value.
Args:
build_quantity: Number of parts to build
Returns:
Quantity required for this build (inc... | Calculate the required part quantity, based on the supplier build_quantity. Includes overage estimate in the returned value.
Args:
build_quantity: Number of parts to build
Returns:
Quantity required for this build (including overage)
| get_required_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 price_range(self, internal=False):
"""Return the price-range for this BOM item."""
# get internal price setting
use_internal = get_global_setting('PART_BOM_USE_INTERNAL_PRICE', False)
prange = self.sub_part.get_price_range(
self.quantity, internal=use_internal and interna... | Return the price-range for this BOM item. | price_range | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def update_pricing_after_edit(sender, instance, created, **kwargs):
"""Callback function when a part price break is created or updated."""
# Update part pricing *unless* we are importing data
if (
InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING)
and not InvenTree.rea... | Callback function when a part price break is created or updated. | update_pricing_after_edit | python | inventree/InvenTree | src/backend/InvenTree/part/models.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/models.py | MIT |
def update_pricing_after_delete(sender, instance, **kwargs):
"""Callback function when a part price break is deleted."""
# Update part pricing *unless* we are importing data
if (
InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING)
and not InvenTree.ready.isImportingData... | Callback function when a part price break is deleted. | update_pricing_after_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):
"""Enforce a 'clean' operation when saving a PartRelated instance."""
self.clean()
self.validate_unique()
super().save(*args, **kwargs) | Enforce a 'clean' operation when saving a PartRelated instance. | 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 clean(self):
"""Overwrite clean method to check that relation is unique."""
super().clean()
if self.part_1 == self.part_2:
raise ValidationError(
_('Part relationship cannot be created between a part and itself')
)
# Check for inverse relatio... | Overwrite clean method to check that relation is unique. | 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 __init__(self, *args, **kwargs):
"""Optionally add or remove extra fields."""
path_detail = kwargs.pop('path_detail', False)
super().__init__(*args, **kwargs)
if not path_detail and not isGeneratingSchema():
self.fields.pop('path', None) | Optionally add or remove extra fields. | __init__ | python | inventree/InvenTree | src/backend/InvenTree/part/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/serializers.py | MIT |
def annotate_queryset(queryset):
"""Annotate extra information to the queryset."""
# Annotate the number of 'parts' which exist in each category (including subcategories!)
queryset = queryset.annotate(
part_count=part_filters.annotate_category_parts(),
subcategories=part_... | Annotate extra information to the queryset. | annotate_queryset | python | inventree/InvenTree | src/backend/InvenTree/part/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/serializers.py | MIT |
def validate_image(self, value):
"""Check that file is an image."""
validate = InvenTree.helpers.TestIfImage(value)
if not validate:
raise serializers.ValidationError(_('File is not an image'))
return value | Check that file is an image. | validate_image | python | inventree/InvenTree | src/backend/InvenTree/part/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/serializers.py | MIT |
def __init__(self, *args, **kwargs):
"""Custom initialization routine for the PartBrief serializer."""
pricing = kwargs.pop('pricing', True)
super().__init__(*args, **kwargs)
if not pricing and not isGeneratingSchema():
self.fields.pop('pricing_min', None)
self.... | Custom initialization routine for the PartBrief serializer. | __init__ | python | inventree/InvenTree | src/backend/InvenTree/part/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/serializers.py | MIT |
def __init__(self, *args, **kwargs):
"""Custom initialization method for the serializer.
Allows us to optionally include or exclude particular information
"""
template_detail = kwargs.pop('template_detail', True)
part_detail = kwargs.pop('part_detail', False)
super().__... | Custom initialization method for the serializer.
Allows us to optionally include or exclude particular information
| __init__ | python | inventree/InvenTree | src/backend/InvenTree/part/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/serializers.py | MIT |
def __init__(self, *args, **kwargs):
"""Custom initialization method for PartSerializer.
- Allows us to optionally pass extra fields based on the query.
"""
self.starred_parts = kwargs.pop('starred_parts', [])
category_detail = kwargs.pop('category_detail', False)
locati... | Custom initialization method for PartSerializer.
- Allows us to optionally pass extra fields based on the query.
| __init__ | python | inventree/InvenTree | src/backend/InvenTree/part/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/serializers.py | MIT |
def skip_create_fields(self):
"""Skip these fields when instantiating a new Part instance."""
fields = super().skip_create_fields()
fields += [
'duplicate',
'initial_stock',
'initial_supplier',
'copy_category_parameters',
'existing_ima... | Skip these fields when instantiating a new Part instance. | skip_create_fields | python | inventree/InvenTree | src/backend/InvenTree/part/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/serializers.py | MIT |
def annotate_queryset(queryset):
"""Add some extra annotations to the queryset.
Performing database queries as efficiently as possible, to reduce database trips.
"""
queryset = queryset.prefetch_related('category', 'default_location')
# Annotate with the total number of revisio... | Add some extra annotations to the queryset.
Performing database queries as efficiently as possible, to reduce database trips.
| annotate_queryset | python | inventree/InvenTree | src/backend/InvenTree/part/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/serializers.py | MIT |
def create(self, validated_data):
"""Custom method for creating a new Part instance using this serializer."""
duplicate = validated_data.pop('duplicate', None)
initial_stock = validated_data.pop('initial_stock', None)
initial_supplier = validated_data.pop('initial_supplier', None)
... | Custom method for creating a new Part instance using this serializer. | create | python | inventree/InvenTree | src/backend/InvenTree/part/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/serializers.py | MIT |
def save(self):
"""Called when this serializer is saved."""
data = self.validated_data
# Add in user information automatically
request = self.context.get('request')
data['user'] = request.user if request else None
super().save() | Called when this serializer is saved. | save | python | inventree/InvenTree | src/backend/InvenTree/part/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/serializers.py | MIT |
def save(self):
"""Saving this serializer instance requests generation of a new stocktake report."""
data = self.validated_data
user = self.context['request'].user
# Generate a new report
offload_task(
part.stocktake.generate_stocktake_report,
force_async... | Saving this serializer instance requests generation of a new stocktake report. | save | python | inventree/InvenTree | src/backend/InvenTree/part/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/serializers.py | MIT |
def save(self):
"""Called when the serializer is saved."""
super().save()
# Update part pricing
pricing = self.instance
pricing.update_pricing() | Called when the serializer is saved. | save | python | inventree/InvenTree | src/backend/InvenTree/part/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/serializers.py | MIT |
def __init__(self, *args, **kwargs):
"""Determine if extra detail fields are to be annotated on this serializer.
- part_detail and sub_part_detail serializers are only included if requested.
- This saves a bunch of database requests
"""
part_detail = kwargs.pop('part_detail', Fa... | Determine if extra detail fields are to be annotated on this serializer.
- part_detail and sub_part_detail serializers are only included if requested.
- This saves a bunch of database requests
| __init__ | python | inventree/InvenTree | src/backend/InvenTree/part/serializers.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/serializers.py | MIT |
def generate_stocktake_report(**kwargs):
"""Generated a new stocktake report.
Note that this method should be called only by the background worker process!
Unless otherwise specified, the stocktake report is generated for *all* Part instances.
Optional filters can by supplied via the kwargs
kwarg... | Generated a new stocktake report.
Note that this method should be called only by the background worker process!
Unless otherwise specified, the stocktake report is generated for *all* Part instances.
Optional filters can by supplied via the kwargs
kwargs:
user: The user who requested this sto... | generate_stocktake_report | python | inventree/InvenTree | src/backend/InvenTree/part/stocktake.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/stocktake.py | MIT |
def notify_low_stock(part: part_models.Part):
"""Notify interested users that a part is 'low stock'.
Rules:
- Triggered when the available stock for a given part falls be low the configured threhsold
- A notification is delivered to any users who are 'subscribed' to this part
"""
name = _('Low ... | Notify interested users that a part is 'low stock'.
Rules:
- Triggered when the available stock for a given part falls be low the configured threhsold
- A notification is delivered to any users who are 'subscribed' to this part
| notify_low_stock | python | inventree/InvenTree | src/backend/InvenTree/part/tasks.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/tasks.py | MIT |
def notify_low_stock_if_required(part_id: int):
"""Check if the stock quantity has fallen below the minimum threshold of part.
If true, notify the users who have subscribed to the part
"""
try:
part = part_models.Part.objects.get(pk=part_id)
except part_models.Part.DoesNotExist:
log... | Check if the stock quantity has fallen below the minimum threshold of part.
If true, notify the users who have subscribed to the part
| notify_low_stock_if_required | python | inventree/InvenTree | src/backend/InvenTree/part/tasks.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/tasks.py | MIT |
def update_part_pricing(pricing: part_models.PartPricing, counter: int = 0):
"""Update cached pricing data for the specified PartPricing instance.
Arguments:
pricing: The target PartPricing instance to be updated
counter: How many times this function has been called in sequence
"""
logg... | Update cached pricing data for the specified PartPricing instance.
Arguments:
pricing: The target PartPricing instance to be updated
counter: How many times this function has been called in sequence
| update_part_pricing | python | inventree/InvenTree | src/backend/InvenTree/part/tasks.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/tasks.py | MIT |
def scheduled_stocktake_reports():
"""Scheduled tasks for creating automated stocktake reports.
This task runs daily, and performs the following functions:
- Delete 'old' stocktake report files after the specified period
- Generate new reports at the specified period
"""
# Sleep a random numbe... | Scheduled tasks for creating automated stocktake reports.
This task runs daily, and performs the following functions:
- Delete 'old' stocktake report files after the specified period
- Generate new reports at the specified period
| scheduled_stocktake_reports | python | inventree/InvenTree | src/backend/InvenTree/part/tasks.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/tasks.py | MIT |
def rebuild_parameters(template_id):
"""Rebuild all parameters for a given template.
This function is called when a base template is changed,
which may cause the base unit to be adjusted.
"""
try:
template = part_models.PartParameterTemplate.objects.get(pk=template_id)
except part_model... | Rebuild all parameters for a given template.
This function is called when a base template is changed,
which may cause the base unit to be adjusted.
| rebuild_parameters | python | inventree/InvenTree | src/backend/InvenTree/part/tasks.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/tasks.py | MIT |
def rebuild_supplier_parts(part_id):
"""Rebuild all SupplierPart objects for a given part.
This function is called when a bart part is changed,
which may cause the native units of any supplier parts to be updated
"""
try:
prt = part_models.Part.objects.get(pk=part_id)
except part_models... | Rebuild all SupplierPart objects for a given part.
This function is called when a bart part is changed,
which may cause the native units of any supplier parts to be updated
| rebuild_supplier_parts | python | inventree/InvenTree | src/backend/InvenTree/part/tasks.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/tasks.py | MIT |
def setUpTestData(cls):
"""Custom setup routine for this class."""
super().setUpTestData()
# Create a custom APIClient for file uploads
# Ref: https://stackoverflow.com/questions/40453947/how-to-generate-a-file-upload-test-request-with-django-rest-frameworks-apireq
cls.upload_cl... | Custom setup routine for this class. | setUpTestData | python | inventree/InvenTree | src/backend/InvenTree/part/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/test_api.py | MIT |
def test_part_count(self):
"""Test that the 'part_count' field is annotated correctly."""
url = reverse('api-part-category-list')
# Create a parent category
cat = PartCategory.objects.create(
name='Parent Cat', description='Some name', parent=None
)
# Create... | Test that the 'part_count' field is annotated correctly. | test_part_count | python | inventree/InvenTree | src/backend/InvenTree/part/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/test_api.py | MIT |
def test_category_parameters(self):
"""Test that the PartCategoryParameterTemplate API function work."""
url = reverse('api-part-category-parameter-list')
response = self.get(url, {}, expected_code=200)
self.assertEqual(len(response.data), 2)
# Add some more category templates... | Test that the PartCategoryParameterTemplate API function work. | test_category_parameters | python | inventree/InvenTree | src/backend/InvenTree/part/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/test_api.py | MIT |
def test_bleach(self):
"""Test that the data cleaning functionality is working.
This helps to protect against XSS injection
"""
url = reverse('api-part-category-detail', kwargs={'pk': 1})
# Invalid values containing tags
invalid_values = [
'<img src="test"/>... | Test that the data cleaning functionality is working.
This helps to protect against XSS injection
| test_bleach | python | inventree/InvenTree | src/backend/InvenTree/part/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/test_api.py | MIT |
def test_invisible_chars(self):
"""Test that invisible characters are removed from the input data."""
url = reverse('api-part-category-detail', kwargs={'pk': 1})
values = [
'A part\n category\n\t',
'A\t part\t category\t',
'A pa\rrt cat\r\r\regory',
... | Test that invisible characters are removed from the input data. | test_invisible_chars | python | inventree/InvenTree | src/backend/InvenTree/part/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/test_api.py | MIT |
def test_category_delete(self):
"""Test category deletion with different parameters."""
class Target(IntEnum):
move_subcategories_to_parent_move_parts_to_parent = (0,)
move_subcategories_to_parent_delete_parts = (1,)
delete_subcategories_move_parts_to_parent = (2,)
... | Test category deletion with different parameters. | test_category_delete | python | inventree/InvenTree | src/backend/InvenTree/part/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/test_api.py | MIT |
def test_structural(self):
"""Test the effectiveness of structural categories.
Make sure:
- Parts cannot be created in structural categories
- Parts cannot be assigned to structural categories
"""
# Create our structural part category
structural_category = PartCa... | Test the effectiveness of structural categories.
Make sure:
- Parts cannot be created in structural categories
- Parts cannot be assigned to structural categories
| test_structural | python | inventree/InvenTree | src/backend/InvenTree/part/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/test_api.py | MIT |
def test_part_category_default_location(self):
"""Test default location propagation through location trees."""
"""Making a tree structure like this:
main
loc 2
sub1
sub2
loc 3
sub3
loc 4
... | Test default location propagation through location trees. | test_part_category_default_location | python | inventree/InvenTree | src/backend/InvenTree/part/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/test_api.py | MIT |
def test_part_label_translation(self):
"""Test that 'label' values are correctly translated."""
response = self.options(reverse('api-part-list'))
labels = {
'IPN': 'IPN',
'category': 'Category',
'assembly': 'Assembly',
'ordering': 'On Order',
... | Test that 'label' values are correctly translated. | test_part_label_translation | python | inventree/InvenTree | src/backend/InvenTree/part/test_api.py | https://github.com/inventree/InvenTree/blob/master/src/backend/InvenTree/part/test_api.py | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.